mirror of https://github.com/axmolengine/axmol.git
issue #1515: [LINUX support] Adding a zoom function for debugging large resolution (e.g.new ipad) app on desktop.
This commit is contained in:
parent
0b101bedd0
commit
41c784ec61
|
@ -77,6 +77,7 @@ NS_CC_BEGIN
|
|||
|
||||
CCEGLView::CCEGLView()
|
||||
: bIsInit(false)
|
||||
, m_fFrameZoomFactor(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -109,6 +110,7 @@ void charEventHandle(int iCharID,int iCharState) {
|
|||
|
||||
void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
||||
if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) {
|
||||
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||
//get current mouse pos
|
||||
int x,y;
|
||||
glfwGetMousePos(&x, &y);
|
||||
|
@ -120,12 +122,14 @@ void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
|||
return;
|
||||
}
|
||||
*/
|
||||
oPoint.x /= pEGLView->m_fFrameZoomFactor;
|
||||
oPoint.y /= pEGLView->m_fFrameZoomFactor;
|
||||
int id = 0;
|
||||
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) {
|
||||
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
|
||||
if (iButtonState == GLFW_PRESS) {
|
||||
int id = 0;
|
||||
float x = (float)iPosX;
|
||||
float y = (float)iPosY;
|
||||
CCEGLView::sharedOpenGLView()->handleTouchesMove(1, &id, &x, &y);
|
||||
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||
int id = 0;
|
||||
float x = (float)iPosX;
|
||||
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()
|
||||
{
|
||||
return bIsInit;
|
||||
|
|
|
@ -32,6 +32,11 @@ public:
|
|||
* 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 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 void end();
|
||||
virtual void swapBuffers();
|
||||
|
@ -42,13 +47,13 @@ public:
|
|||
*/
|
||||
static CCEGLView* sharedOpenGLView();
|
||||
private:
|
||||
bool initGL();
|
||||
void destroyGL();
|
||||
bool initGL();
|
||||
void destroyGL();
|
||||
private:
|
||||
bool m_bCaptured;
|
||||
//store current mouse point for moving, valid if and only if the mouse pressed
|
||||
CCPoint m_mousePoint;
|
||||
bool bIsInit;
|
||||
float m_fFrameZoomFactor;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -29,6 +29,9 @@ int main(int argc, char **argv)
|
|||
AppDelegate app;
|
||||
CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue