kCCResolutionXXX -> kResolutionXXX and estimate whether touch point is contained in GL viewport rectangle.

This commit is contained in:
James Chen 2012-08-20 16:32:22 +08:00
parent 7eb5d85298
commit 0861877594
4 changed files with 12 additions and 10 deletions

View File

@ -71,12 +71,12 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol
m_fScaleX = (float)m_obScreenSize.width / m_obDesignResolutionSize.width; m_fScaleX = (float)m_obScreenSize.width / m_obDesignResolutionSize.width;
m_fScaleY = (float)m_obScreenSize.height / m_obDesignResolutionSize.height; m_fScaleY = (float)m_obScreenSize.height / m_obDesignResolutionSize.height;
if (resolutionPolicy == kCCResolutionNoBorder) if (resolutionPolicy == kResolutionNoBorder)
{ {
m_fScaleX = m_fScaleY = MAX(m_fScaleX, m_fScaleY); m_fScaleX = m_fScaleY = MAX(m_fScaleX, m_fScaleY);
} }
if (resolutionPolicy == kCCResolutionShowAll) if (resolutionPolicy == kResolutionShowAll)
{ {
m_fScaleX = m_fScaleY = MIN(m_fScaleX, m_fScaleY); m_fScaleX = m_fScaleY = MIN(m_fScaleX, m_fScaleY);
} }
@ -119,7 +119,7 @@ void CCEGLViewProtocol::setFrameSize(float width, float height)
CCSize CCEGLViewProtocol::getVisibleSize() const CCSize CCEGLViewProtocol::getVisibleSize() const
{ {
if (m_eResolutionPolicy == kCCResolutionNoBorder) if (m_eResolutionPolicy == kResolutionNoBorder)
{ {
return CCSizeMake(m_obScreenSize.width/m_fScaleX, m_obScreenSize.height/m_fScaleY); return CCSizeMake(m_obScreenSize.width/m_fScaleX, m_obScreenSize.height/m_fScaleY);
} }
@ -131,7 +131,7 @@ CCSize CCEGLViewProtocol::getVisibleSize() const
CCPoint CCEGLViewProtocol::getVisibleOrigin() const CCPoint CCEGLViewProtocol::getVisibleOrigin() const
{ {
if (m_eResolutionPolicy == kCCResolutionNoBorder) if (m_eResolutionPolicy == kResolutionNoBorder)
{ {
return CCPointMake((m_obDesignResolutionSize.width - m_obScreenSize.width/m_fScaleX)/2, return CCPointMake((m_obDesignResolutionSize.width - m_obScreenSize.width/m_fScaleX)/2,
(m_obDesignResolutionSize.height - m_obScreenSize.height/m_fScaleY)/2); (m_obDesignResolutionSize.height - m_obScreenSize.height/m_fScaleY)/2);

View File

@ -7,13 +7,13 @@ enum ResolutionPolicy
{ {
// The entire application is visible in the specified area without trying to preserve the original aspect ratio. // The entire application is visible in the specified area without trying to preserve the original aspect ratio.
// Distortion can occur, and the application may appear stretched or compressed. // Distortion can occur, and the application may appear stretched or compressed.
kCCResolutionExactFit, kResolutionExactFit,
// The entire application fills the specified area, without distortion but possibly with some cropping, // The entire application fills the specified area, without distortion but possibly with some cropping,
// while maintaining the original aspect ratio of the application. // while maintaining the original aspect ratio of the application.
kCCResolutionNoBorder, kResolutionNoBorder,
// The entire application is visible in the specified area without distortion while maintaining the original // The entire application is visible in the specified area without distortion while maintaining the original
// aspect ratio of the application. Borders can appear on two sides of the application. // aspect ratio of the application. Borders can appear on two sides of the application.
kCCResolutionShowAll, kResolutionShowAll,
kResolutionUnKnown, kResolutionUnKnown,
}; };

View File

@ -30,6 +30,7 @@ THE SOFTWARE.
#include "touch_dispatcher/CCTouchDispatcher.h" #include "touch_dispatcher/CCTouchDispatcher.h"
#include "text_input_node/CCIMEDispatcher.h" #include "text_input_node/CCIMEDispatcher.h"
#include "keypad_dispatcher/CCKeypadDispatcher.h" #include "keypad_dispatcher/CCKeypadDispatcher.h"
#include "support/CCPointExtension.h"
#include "CCApplication.h" #include "CCApplication.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -210,7 +211,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{ {
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
//if (CCRect::CCRectContainsPoint(m_obViewPortRect, pt)) CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
if (m_obViewPortRect.containsPoint(tmp))
{ {
m_bCaptured = true; m_bCaptured = true;
SetCapture(m_hWnd); SetCapture(m_hWnd);

View File

@ -26,7 +26,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd");
// don't enable retina because we don't have ipad hd resource // don't enable retina because we don't have ipad hd resource
CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kCCResolutionNoBorder); CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kResolutionNoBorder);
} }
else if (target == kTargetIphone) else if (target == kTargetIphone)
{ {
@ -47,7 +47,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
// android, windows, blackberry, linux or mac // android, windows, blackberry, linux or mac
// use 960*640 resources as design resolution size // use 960*640 resources as design resolution size
CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd");
CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kCCResolutionNoBorder); CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kResolutionNoBorder);
} }
// turn on display FPS // turn on display FPS