mirror of https://github.com/axmolengine/axmol.git
Merge pull request #1470 from dumganhar/gles20
fixed #1515: Adding a zoom function for debugging large resolution (e.g.new ipad) app on desktop.
This commit is contained in:
commit
1fc2d2ce1f
|
@ -77,6 +77,7 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
CCEGLView::CCEGLView()
|
CCEGLView::CCEGLView()
|
||||||
: bIsInit(false)
|
: bIsInit(false)
|
||||||
|
, m_fFrameZoomFactor(1.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +110,7 @@ void charEventHandle(int iCharID,int iCharState) {
|
||||||
|
|
||||||
void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
||||||
if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) {
|
if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
|
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||||
//get current mouse pos
|
//get current mouse pos
|
||||||
int x,y;
|
int x,y;
|
||||||
glfwGetMousePos(&x, &y);
|
glfwGetMousePos(&x, &y);
|
||||||
|
@ -120,12 +122,14 @@ void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
oPoint.x /= pEGLView->m_fFrameZoomFactor;
|
||||||
|
oPoint.y /= pEGLView->m_fFrameZoomFactor;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
if (iMouseState == GLFW_PRESS) {
|
if (iMouseState == GLFW_PRESS) {
|
||||||
CCEGLView::sharedOpenGLView()->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y);
|
pEGLView->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y);
|
||||||
|
|
||||||
} else if (iMouseState == GLFW_RELEASE) {
|
} else if (iMouseState == GLFW_RELEASE) {
|
||||||
CCEGLView::sharedOpenGLView()->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y);
|
pEGLView->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,10 +139,13 @@ void mousePosEventHandle(int iPosX,int iPosY) {
|
||||||
|
|
||||||
//to test move
|
//to test move
|
||||||
if (iButtonState == GLFW_PRESS) {
|
if (iButtonState == GLFW_PRESS) {
|
||||||
int id = 0;
|
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||||
float x = (float)iPosX;
|
int id = 0;
|
||||||
float y = (float)iPosY;
|
float x = (float)iPosX;
|
||||||
CCEGLView::sharedOpenGLView()->handleTouchesMove(1, &id, &x, &y);
|
float y = (float)iPosY;
|
||||||
|
x /= pEGLView->m_fFrameZoomFactor;
|
||||||
|
y /= pEGLView->m_fFrameZoomFactor;
|
||||||
|
pEGLView->handleTouchesMove(1, &id, &x, &y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,6 +241,21 @@ void CCEGLView::setFrameSize(float width, float height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setFrameZoom(float fZoomFactor)
|
||||||
|
{
|
||||||
|
m_fFrameZoomFactor = fZoomFactor;
|
||||||
|
glfwSetWindowSize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
|
||||||
|
CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
|
{
|
||||||
|
glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor+ m_obViewPortRect.origin.x * m_fFrameZoomFactor),
|
||||||
|
(GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
|
||||||
|
(GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
|
||||||
|
(GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
|
||||||
|
}
|
||||||
|
|
||||||
bool CCEGLView::isOpenGLReady()
|
bool CCEGLView::isOpenGLReady()
|
||||||
{
|
{
|
||||||
return bIsInit;
|
return bIsInit;
|
||||||
|
|
|
@ -32,6 +32,11 @@ public:
|
||||||
* iDepth is not the buffer depth of opengl, it indicate how may bits for a pixel
|
* iDepth is not the buffer depth of opengl, it indicate how may bits for a pixel
|
||||||
*/
|
*/
|
||||||
virtual void setFrameSize(float width, float height);
|
virtual void setFrameSize(float width, float height);
|
||||||
|
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
||||||
|
/*
|
||||||
|
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
void setFrameZoom(float fZoomFactor);
|
||||||
virtual bool isOpenGLReady();
|
virtual bool isOpenGLReady();
|
||||||
virtual void end();
|
virtual void end();
|
||||||
virtual void swapBuffers();
|
virtual void swapBuffers();
|
||||||
|
@ -42,13 +47,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCEGLView* sharedOpenGLView();
|
static CCEGLView* sharedOpenGLView();
|
||||||
private:
|
private:
|
||||||
bool initGL();
|
bool initGL();
|
||||||
void destroyGL();
|
void destroyGL();
|
||||||
private:
|
private:
|
||||||
bool m_bCaptured;
|
|
||||||
//store current mouse point for moving, valid if and only if the mouse pressed
|
//store current mouse point for moving, valid if and only if the mouse pressed
|
||||||
CCPoint m_mousePoint;
|
CCPoint m_mousePoint;
|
||||||
bool bIsInit;
|
bool bIsInit;
|
||||||
|
float m_fFrameZoomFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -45,6 +45,10 @@ public:
|
||||||
virtual bool setContentScaleFactor(float contentScaleFactor);
|
virtual bool setContentScaleFactor(float contentScaleFactor);
|
||||||
virtual void end();
|
virtual void end();
|
||||||
virtual void swapBuffers(void);
|
virtual void swapBuffers(void);
|
||||||
|
/**
|
||||||
|
* Set opengl view port rectangle with points.
|
||||||
|
*/
|
||||||
|
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
||||||
|
|
||||||
virtual void setIMEKeyboardState(bool bOpen);
|
virtual void setIMEKeyboardState(bool bOpen);
|
||||||
virtual void setMultiTouchMask(bool mask);
|
virtual void setMultiTouchMask(bool mask);
|
||||||
|
|
|
@ -43,8 +43,6 @@ CCEGLView* CCEGLView::sharedOpenGLView(void)
|
||||||
|
|
||||||
CCEGLView::CCEGLView(void)
|
CCEGLView::CCEGLView(void)
|
||||||
{
|
{
|
||||||
m_obScreenSize.width = m_obDesignResolutionSize.width = [[EAGLView sharedEGLView] getWidth];
|
|
||||||
m_obScreenSize.height = m_obDesignResolutionSize.height = [[EAGLView sharedEGLView] getHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCEGLView::~CCEGLView(void)
|
CCEGLView::~CCEGLView(void)
|
||||||
|
@ -90,6 +88,16 @@ void CCEGLView::setIMEKeyboardState(bool bOpen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
|
{
|
||||||
|
float frameZoomFactor = [[EAGLView sharedEGLView] frameZoomFactor];
|
||||||
|
|
||||||
|
glViewport((GLint)(x * m_fScaleX * frameZoomFactor + m_obViewPortRect.origin.x * frameZoomFactor),
|
||||||
|
(GLint)(y * m_fScaleY * frameZoomFactor + m_obViewPortRect.origin.y * frameZoomFactor),
|
||||||
|
(GLsizei)(w * m_fScaleX * frameZoomFactor),
|
||||||
|
(GLsizei)(h * m_fScaleY * frameZoomFactor));
|
||||||
|
}
|
||||||
|
|
||||||
void CCEGLView::setMultiTouchMask(bool mask)
|
void CCEGLView::setMultiTouchMask(bool mask)
|
||||||
{
|
{
|
||||||
//EAGLView *glView = [EAGLView sharedEGLView];
|
//EAGLView *glView = [EAGLView sharedEGLView];
|
||||||
|
|
|
@ -78,6 +78,8 @@ THE SOFTWARE.
|
||||||
NSWindow *windowGLView_;
|
NSWindow *windowGLView_;
|
||||||
NSView *superViewGLView_;
|
NSView *superViewGLView_;
|
||||||
NSRect originalWinRect_; // Original size and position
|
NSRect originalWinRect_; // Original size and position
|
||||||
|
|
||||||
|
float frameZoomFactor_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) id<MacEventDelegate> eventDelegate;
|
@property (nonatomic, readwrite, assign) id<MacEventDelegate> eventDelegate;
|
||||||
|
@ -85,6 +87,8 @@ THE SOFTWARE.
|
||||||
// whether or not the view is in fullscreen mode
|
// whether or not the view is in fullscreen mode
|
||||||
@property (nonatomic, readonly) BOOL isFullScreen;
|
@property (nonatomic, readonly) BOOL isFullScreen;
|
||||||
|
|
||||||
|
@property (nonatomic, readwrite) float frameZoomFactor;
|
||||||
|
|
||||||
// initializes the MacGLView with a frame rect and an OpenGL context
|
// initializes the MacGLView with a frame rect and an OpenGL context
|
||||||
- (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context;
|
- (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context;
|
||||||
|
|
||||||
|
@ -97,6 +101,8 @@ THE SOFTWARE.
|
||||||
/** returns the depth format of the view in BPP */
|
/** returns the depth format of the view in BPP */
|
||||||
- (NSUInteger) depthFormat;
|
- (NSUInteger) depthFormat;
|
||||||
|
|
||||||
|
- (void) setFrameZoomFactor:(float)frameZoomFactor;
|
||||||
|
|
||||||
// get the view object
|
// get the view object
|
||||||
+(id) sharedEGLView;
|
+(id) sharedEGLView;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ THE SOFTWARE.
|
||||||
#import "CCIMEDispatcher.h"
|
#import "CCIMEDispatcher.h"
|
||||||
#import "CCWindow.h"
|
#import "CCWindow.h"
|
||||||
#import "CCEventDispatcher.h"
|
#import "CCEventDispatcher.h"
|
||||||
|
#import "CCEGLView.h"
|
||||||
|
|
||||||
|
|
||||||
//USING_NS_CC;
|
//USING_NS_CC;
|
||||||
|
@ -45,7 +46,7 @@ static EAGLView *view;
|
||||||
|
|
||||||
@implementation EAGLView
|
@implementation EAGLView
|
||||||
|
|
||||||
@synthesize eventDelegate = eventDelegate_, isFullScreen = isFullScreen_;
|
@synthesize eventDelegate = eventDelegate_, isFullScreen = isFullScreen_, frameZoomFactor=frameZoomFactor_;
|
||||||
|
|
||||||
+(id) sharedEGLView
|
+(id) sharedEGLView
|
||||||
{
|
{
|
||||||
|
@ -83,6 +84,10 @@ static EAGLView *view;
|
||||||
// event delegate
|
// event delegate
|
||||||
eventDelegate_ = [CCEventDispatcher sharedDispatcher];
|
eventDelegate_ = [CCEventDispatcher sharedDispatcher];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cocos2d::CCEGLView::sharedOpenGLView()->setFrameSize(frameRect.size.width, frameRect.size.height);
|
||||||
|
|
||||||
|
frameZoomFactor_ = 1.0f;
|
||||||
|
|
||||||
view = self;
|
view = self;
|
||||||
return self;
|
return self;
|
||||||
|
@ -117,6 +122,29 @@ static EAGLView *view;
|
||||||
return 24;
|
return 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) setFrameZoomFactor:(float)frameZoomFactor
|
||||||
|
{
|
||||||
|
frameZoomFactor_ = frameZoomFactor;
|
||||||
|
|
||||||
|
NSRect winRect = [[self window] frame];
|
||||||
|
NSRect viewRect = [self frame];
|
||||||
|
|
||||||
|
// compute the margin width and margin height
|
||||||
|
float diffX = winRect.size.width - viewRect.size.width;
|
||||||
|
float diffY = winRect.size.height - viewRect.size.height;
|
||||||
|
|
||||||
|
// new window width and height
|
||||||
|
float newWindowWidth = (int)(viewRect.size.width * frameZoomFactor + diffX);
|
||||||
|
float newWindowHeight = (int)(viewRect.size.height * frameZoomFactor + diffY);
|
||||||
|
|
||||||
|
// display window in the center of the screen
|
||||||
|
NSRect screenRect = [[NSScreen mainScreen] frame];
|
||||||
|
float originX = (screenRect.size.width - newWindowWidth) / 2;
|
||||||
|
float originY = (screenRect.size.height - newWindowHeight) / 2;
|
||||||
|
|
||||||
|
[[self window] setFrame:NSMakeRect(originX, originY, newWindowWidth, newWindowHeight) display:true];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) reshape
|
- (void) reshape
|
||||||
{
|
{
|
||||||
// We draw on a secondary thread through the display link
|
// We draw on a secondary thread through the display link
|
||||||
|
@ -289,8 +317,8 @@ static EAGLView *view;
|
||||||
float ys[1] = {0.0f};
|
float ys[1] = {0.0f};
|
||||||
|
|
||||||
ids[0] = [theEvent eventNumber];
|
ids[0] = [theEvent eventNumber];
|
||||||
xs[0] = x;
|
xs[0] = x / frameZoomFactor_;
|
||||||
ys[0] = y;
|
ys[0] = y / frameZoomFactor_;
|
||||||
|
|
||||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesBegin(1, ids, xs, ys);
|
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesBegin(1, ids, xs, ys);
|
||||||
}
|
}
|
||||||
|
@ -313,8 +341,8 @@ static EAGLView *view;
|
||||||
float ys[1] = {0.0f};
|
float ys[1] = {0.0f};
|
||||||
|
|
||||||
ids[0] = [theEvent eventNumber];
|
ids[0] = [theEvent eventNumber];
|
||||||
xs[0] = x;
|
xs[0] = x / frameZoomFactor_;
|
||||||
ys[0] = y;
|
ys[0] = y / frameZoomFactor_;
|
||||||
|
|
||||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesMove(1, ids, xs, ys);
|
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesMove(1, ids, xs, ys);
|
||||||
}
|
}
|
||||||
|
@ -332,8 +360,8 @@ static EAGLView *view;
|
||||||
float ys[1] = {0.0f};
|
float ys[1] = {0.0f};
|
||||||
|
|
||||||
ids[0] = [theEvent eventNumber];
|
ids[0] = [theEvent eventNumber];
|
||||||
xs[0] = x;
|
xs[0] = x / frameZoomFactor_;
|
||||||
ys[0] = y;
|
ys[0] = y / frameZoomFactor_;
|
||||||
|
|
||||||
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesEnd(1, ids, xs, ys);
|
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesEnd(1, ids, xs, ys);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ static GetMessageExtraInfoFn s_pfGetMessageExtraInfoFunction = NULL;
|
||||||
static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL;
|
static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL;
|
||||||
static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL;
|
static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL;
|
||||||
|
|
||||||
bool CheckTouchSupport()
|
static bool CheckTouchSupport()
|
||||||
{
|
{
|
||||||
s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow");
|
s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow");
|
||||||
s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow");
|
s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow");
|
||||||
|
@ -96,7 +96,7 @@ static void SetupPixelFormat(HDC hDC)
|
||||||
SetPixelFormat(hDC, pixelFormat, &pfd);
|
SetPixelFormat(hDC, pixelFormat, &pfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool glew_dynamic_binding()
|
static bool glew_dynamic_binding()
|
||||||
{
|
{
|
||||||
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||||
|
|
||||||
|
@ -184,10 +184,7 @@ CCEGLView::CCEGLView()
|
||||||
, m_lpfnAccelerometerKeyHook(NULL)
|
, m_lpfnAccelerometerKeyHook(NULL)
|
||||||
, m_menu(NULL)
|
, m_menu(NULL)
|
||||||
, m_wndproc(NULL)
|
, m_wndproc(NULL)
|
||||||
, m_windowWidth(0)
|
, m_fFrameZoomFactor(1.0f)
|
||||||
, m_windowHeight(0)
|
|
||||||
, m_windowTouchScaleX(1.0f)
|
|
||||||
, m_windowTouchScaleY(1.0f)
|
|
||||||
, m_bSupportTouch(false)
|
, m_bSupportTouch(false)
|
||||||
{
|
{
|
||||||
strcpy(m_szViewName, "Cocos2dxWin32");
|
strcpy(m_szViewName, "Cocos2dxWin32");
|
||||||
|
@ -347,14 +344,14 @@ 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, point.y);
|
CCPoint pt(point.x, point.y);
|
||||||
|
pt.x /= m_fFrameZoomFactor;
|
||||||
|
pt.y /= m_fFrameZoomFactor;
|
||||||
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
||||||
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
||||||
{
|
{
|
||||||
m_bCaptured = true;
|
m_bCaptured = true;
|
||||||
SetCapture(m_hWnd);
|
SetCapture(m_hWnd);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
pt.x *= m_windowTouchScaleX;
|
|
||||||
pt.y *= m_windowTouchScaleY;
|
|
||||||
handleTouchesBegin(1, &id, &pt.x, &pt.y);
|
handleTouchesBegin(1, &id, &pt.x, &pt.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,8 +367,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, point.y);
|
CCPoint pt(point.x, point.y);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
pt.x *= m_windowTouchScaleX;
|
pt.x /= m_fFrameZoomFactor;
|
||||||
pt.y *= m_windowTouchScaleY;
|
pt.y /= m_fFrameZoomFactor;
|
||||||
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -386,8 +383,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, point.y);
|
CCPoint pt(point.x, point.y);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
pt.x *= m_windowTouchScaleX;
|
pt.x /= m_fFrameZoomFactor;
|
||||||
pt.y *= m_windowTouchScaleY;
|
pt.y /= m_fFrameZoomFactor;
|
||||||
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
||||||
|
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
|
@ -415,8 +412,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
||||||
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
||||||
{
|
{
|
||||||
pt.x *= m_windowTouchScaleX;
|
pt.x /= m_fFrameZoomFactor;
|
||||||
pt.y *= m_windowTouchScaleY;
|
pt.y /= m_fFrameZoomFactor;
|
||||||
|
|
||||||
if (ti.dwFlags & TOUCHEVENTF_DOWN)
|
if (ti.dwFlags & TOUCHEVENTF_DOWN)
|
||||||
handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
|
handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
|
||||||
|
@ -620,19 +617,14 @@ void CCEGLView::resize(int width, int height)
|
||||||
rcClient.right = rcClient.left + width;
|
rcClient.right = rcClient.left + width;
|
||||||
rcClient.bottom = rcClient.top + height;
|
rcClient.bottom = rcClient.top + height;
|
||||||
|
|
||||||
m_windowWidth = width;
|
|
||||||
m_windowHeight = height;
|
|
||||||
const CCSize& frameSize = getFrameSize();
|
const CCSize& frameSize = getFrameSize();
|
||||||
if (frameSize.width > 0)
|
if (frameSize.width > 0)
|
||||||
{
|
{
|
||||||
m_windowTouchScaleX = frameSize.width / width;
|
|
||||||
m_windowTouchScaleY = frameSize.height / height;
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
TCHAR buff[MAX_PATH + 1];
|
TCHAR buff[MAX_PATH + 1];
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
swprintf_s(buff, MAX_PATH, L"%s - %0.0fx%0.0f - %0.2f",
|
swprintf_s(buff, MAX_PATH, L"%s - %0.0fx%0.0f - %0.2f",
|
||||||
kWindowClassName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX);
|
kWindowClassName, frameSize.width, frameSize.height, m_fFrameZoomFactor);
|
||||||
SetWindowText(m_hWnd, buff);
|
SetWindowText(m_hWnd, buff);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -644,6 +636,14 @@ void CCEGLView::resize(int width, int height)
|
||||||
SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setFrameZoom(float fZoomFactor)
|
||||||
|
{
|
||||||
|
m_fFrameZoomFactor = fZoomFactor;
|
||||||
|
resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
|
||||||
|
centerWindow();
|
||||||
|
CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection());
|
||||||
|
}
|
||||||
|
|
||||||
void CCEGLView::setFrameSize(float width, float height)
|
void CCEGLView::setFrameSize(float width, float height)
|
||||||
{
|
{
|
||||||
CCEGLViewProtocol::setFrameSize(width, height);
|
CCEGLViewProtocol::setFrameSize(width, height);
|
||||||
|
@ -684,6 +684,14 @@ void CCEGLView::centerWindow()
|
||||||
SetWindowPos(m_hWnd, 0, offsetX, offsetY, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
SetWindowPos(m_hWnd, 0, offsetX, offsetY, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
|
{
|
||||||
|
glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor),
|
||||||
|
(GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
|
||||||
|
(GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
|
||||||
|
(GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
|
||||||
|
}
|
||||||
|
|
||||||
CCEGLView* CCEGLView::sharedOpenGLView()
|
CCEGLView* CCEGLView::sharedOpenGLView()
|
||||||
{
|
{
|
||||||
static CCEGLView* s_pEglView = NULL;
|
static CCEGLView* s_pEglView = NULL;
|
||||||
|
|
|
@ -62,11 +62,16 @@ public:
|
||||||
// win32 platform function
|
// win32 platform function
|
||||||
HWND getHWnd();
|
HWND getHWnd();
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
|
/*
|
||||||
|
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||||
|
*/
|
||||||
|
void setFrameZoom(float fZoomFactor);
|
||||||
void centerWindow();
|
void centerWindow();
|
||||||
|
|
||||||
typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam );
|
typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam );
|
||||||
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
|
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
|
||||||
|
|
||||||
|
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
||||||
// static function
|
// static function
|
||||||
/**
|
/**
|
||||||
@brief get the shared main open gl window
|
@brief get the shared main open gl window
|
||||||
|
@ -86,10 +91,7 @@ private:
|
||||||
LPCWSTR m_menu;
|
LPCWSTR m_menu;
|
||||||
CUSTOM_WND_PROC m_wndproc;
|
CUSTOM_WND_PROC m_wndproc;
|
||||||
|
|
||||||
int m_windowWidth;
|
float m_fFrameZoomFactor;
|
||||||
int m_windowHeight;
|
|
||||||
float m_windowTouchScaleX;
|
|
||||||
float m_windowTouchScaleY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -29,6 +29,9 @@ int main(int argc, char **argv)
|
||||||
AppDelegate app;
|
AppDelegate app;
|
||||||
CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
|
CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
|
||||||
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
||||||
eglView->setFrameSize(960, 640);
|
eglView->setFrameSize(2048, 1536);
|
||||||
|
// The resolution of ipad3 is very large. In general, PC's resolution is smaller than it.
|
||||||
|
// So we need to invoke 'setFrameZoom'(only valid on desktop(win32, mac, linux)) to make the window smaller.
|
||||||
|
eglView->setFrameZoom(0.4f);
|
||||||
return CCApplication::sharedApplication()->run();
|
return CCApplication::sharedApplication()->run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ static AppDelegate s_sharedApplication;
|
||||||
// create the window
|
// create the window
|
||||||
// note that using NSResizableWindowMask causes the window to be a little
|
// note that using NSResizableWindowMask causes the window to be a little
|
||||||
// smaller and therefore ipad graphics are not loaded
|
// smaller and therefore ipad graphics are not loaded
|
||||||
NSRect rect = NSMakeRect(200, 200, 480, 320);
|
NSRect rect = NSMakeRect(0, 0, 2048, 1536);
|
||||||
window = [[NSWindow alloc] initWithContentRect:rect
|
window = [[NSWindow alloc] initWithContentRect:rect
|
||||||
styleMask:( NSClosableWindowMask | NSTitledWindowMask )
|
styleMask:( NSClosableWindowMask | NSTitledWindowMask )
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
|
@ -45,7 +45,6 @@ static AppDelegate s_sharedApplication;
|
||||||
// allocate our GL view
|
// allocate our GL view
|
||||||
// (isn't there already a shared EAGLView?)
|
// (isn't there already a shared EAGLView?)
|
||||||
glView = [[EAGLView alloc] initWithFrame:rect];
|
glView = [[EAGLView alloc] initWithFrame:rect];
|
||||||
[glView initWithFrame:rect];
|
|
||||||
|
|
||||||
// set window parameters
|
// set window parameters
|
||||||
[window becomeFirstResponder];
|
[window becomeFirstResponder];
|
||||||
|
@ -53,6 +52,8 @@ static AppDelegate s_sharedApplication;
|
||||||
[window setTitle:@"HelloCpp"];
|
[window setTitle:@"HelloCpp"];
|
||||||
[window makeKeyAndOrderFront:self];
|
[window makeKeyAndOrderFront:self];
|
||||||
[window setAcceptsMouseMovedEvents:NO];
|
[window setAcceptsMouseMovedEvents:NO];
|
||||||
|
|
||||||
|
[glView setFrameZoomFactor:0.4];
|
||||||
|
|
||||||
cocos2d::CCApplication::sharedApplication()->run();
|
cocos2d::CCApplication::sharedApplication()->run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
15E102C815D389F1001D70A3 /* iphonehd in Resources */ = {isa = PBXBuildFile; fileRef = 15E102C715D389F1001D70A3 /* iphonehd */; };
|
1514DA3F163004980095A81C /* ipad in Resources */ = {isa = PBXBuildFile; fileRef = 1514DA3C163004980095A81C /* ipad */; };
|
||||||
15E102CA15D389F7001D70A3 /* iphone in Resources */ = {isa = PBXBuildFile; fileRef = 15E102C915D389F7001D70A3 /* iphone */; };
|
1514DA40163004980095A81C /* ipadhd in Resources */ = {isa = PBXBuildFile; fileRef = 1514DA3D163004980095A81C /* ipadhd */; };
|
||||||
|
1514DA41163004980095A81C /* iphone in Resources */ = {isa = PBXBuildFile; fileRef = 1514DA3E163004980095A81C /* iphone */; };
|
||||||
41BC70AD15BF7CCE006A0A6C /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 41BC70AC15BF7CCE006A0A6C /* Icon.icns */; };
|
41BC70AD15BF7CCE006A0A6C /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 41BC70AC15BF7CCE006A0A6C /* Icon.icns */; };
|
||||||
41BC70B715BF7E14006A0A6C /* libcocos2dx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 41CD6C5C15BF74E5005E6F29 /* libcocos2dx.a */; };
|
41BC70B715BF7E14006A0A6C /* libcocos2dx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 41CD6C5C15BF74E5005E6F29 /* libcocos2dx.a */; };
|
||||||
41CD6C6515BF7574005E6F29 /* AppController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41CD6C6315BF7574005E6F29 /* AppController.mm */; };
|
41CD6C6515BF7574005E6F29 /* AppController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41CD6C6315BF7574005E6F29 /* AppController.mm */; };
|
||||||
|
@ -47,8 +48,10 @@
|
||||||
/* End PBXContainerItemProxy section */
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
15E102C715D389F1001D70A3 /* iphonehd */ = {isa = PBXFileReference; lastKnownFileType = folder; name = iphonehd; path = ../Resources/iphonehd; sourceTree = "<group>"; };
|
1514DA3C163004980095A81C /* ipad */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ipad; path = ../Resources/ipad; sourceTree = "<group>"; };
|
||||||
15E102C915D389F7001D70A3 /* iphone */ = {isa = PBXFileReference; lastKnownFileType = folder; name = iphone; path = ../Resources/iphone; sourceTree = "<group>"; };
|
1514DA3D163004980095A81C /* ipadhd */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ipadhd; path = ../Resources/ipadhd; sourceTree = "<group>"; };
|
||||||
|
1514DA3E163004980095A81C /* iphone */ = {isa = PBXFileReference; lastKnownFileType = folder; name = iphone; path = ../Resources/iphone; sourceTree = "<group>"; };
|
||||||
|
15A6969B1630E63B00D7A229 /* AppMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppMacros.h; path = ../Classes/AppMacros.h; sourceTree = "<group>"; };
|
||||||
41BC70AC15BF7CCE006A0A6C /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = "<group>"; };
|
41BC70AC15BF7CCE006A0A6C /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = "<group>"; };
|
||||||
41CD6C5115BF748C005E6F29 /* HelloCpp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloCpp.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
41CD6C5115BF748C005E6F29 /* HelloCpp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloCpp.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
41CD6C5415BF74E5005E6F29 /* cocos2dx.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2dx.xcodeproj; path = ../../../cocos2dx/proj.mac/cocos2dx.xcodeproj; sourceTree = "<group>"; };
|
41CD6C5415BF74E5005E6F29 /* cocos2dx.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2dx.xcodeproj; path = ../../../cocos2dx/proj.mac/cocos2dx.xcodeproj; sourceTree = "<group>"; };
|
||||||
|
@ -120,6 +123,7 @@
|
||||||
41CD6C5D15BF750B005E6F29 /* Classes */ = {
|
41CD6C5D15BF750B005E6F29 /* Classes */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
15A6969B1630E63B00D7A229 /* AppMacros.h */,
|
||||||
41CD6C7115BF76FB005E6F29 /* AppDelegate.cpp */,
|
41CD6C7115BF76FB005E6F29 /* AppDelegate.cpp */,
|
||||||
41CD6C7215BF76FB005E6F29 /* AppDelegate.h */,
|
41CD6C7215BF76FB005E6F29 /* AppDelegate.h */,
|
||||||
41CD6C7315BF76FB005E6F29 /* HelloWorldScene.cpp */,
|
41CD6C7315BF76FB005E6F29 /* HelloWorldScene.cpp */,
|
||||||
|
@ -162,8 +166,9 @@
|
||||||
41CD6C6115BF7556005E6F29 /* Resources */ = {
|
41CD6C6115BF7556005E6F29 /* Resources */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
15E102C915D389F7001D70A3 /* iphone */,
|
1514DA3C163004980095A81C /* ipad */,
|
||||||
15E102C715D389F1001D70A3 /* iphonehd */,
|
1514DA3D163004980095A81C /* ipadhd */,
|
||||||
|
1514DA3E163004980095A81C /* iphone */,
|
||||||
);
|
);
|
||||||
name = Resources;
|
name = Resources;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -256,8 +261,9 @@
|
||||||
41CD6C6E15BF7673005E6F29 /* InfoPlist.strings in Resources */,
|
41CD6C6E15BF7673005E6F29 /* InfoPlist.strings in Resources */,
|
||||||
41CD6C6F15BF7673005E6F29 /* MainMenu.xib in Resources */,
|
41CD6C6F15BF7673005E6F29 /* MainMenu.xib in Resources */,
|
||||||
41BC70AD15BF7CCE006A0A6C /* Icon.icns in Resources */,
|
41BC70AD15BF7CCE006A0A6C /* Icon.icns in Resources */,
|
||||||
15E102C815D389F1001D70A3 /* iphonehd in Resources */,
|
1514DA3F163004980095A81C /* ipad in Resources */,
|
||||||
15E102CA15D389F7001D70A3 /* iphone in Resources */,
|
1514DA40163004980095A81C /* ipadhd in Resources */,
|
||||||
|
1514DA41163004980095A81C /* iphone in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,9 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||||
// create the application instance
|
// create the application instance
|
||||||
AppDelegate app;
|
AppDelegate app;
|
||||||
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
||||||
eglView->setFrameSize(1136, 640 );
|
eglView->setFrameSize(2048, 1536);
|
||||||
|
// The resolution of ipad3 is very large. In general, PC's resolution is smaller than it.
|
||||||
|
// So we need to invoke 'setFrameZoom'(only valid on desktop(win32, mac, linux)) to make the window smaller.
|
||||||
|
eglView->setFrameZoom(0.4f);
|
||||||
return CCApplication::sharedApplication()->run();
|
return CCApplication::sharedApplication()->run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue