From 292d0d74ad9d4d910b4adb91041d99d0f0c6339a Mon Sep 17 00:00:00 2001 From: Nite Luo Date: Fri, 11 Oct 2013 16:39:54 -0700 Subject: [PATCH] Add some comments for mouse scorlling function --- cocos2dx/platform/mac/CCEGLView.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cocos2dx/platform/mac/CCEGLView.mm b/cocos2dx/platform/mac/CCEGLView.mm index b431a18c41..aade8a24cb 100644 --- a/cocos2dx/platform/mac/CCEGLView.mm +++ b/cocos2dx/platform/mac/CCEGLView.mm @@ -221,6 +221,7 @@ void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, in if(GLFW_PRESS == action) { EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN); + //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); event.setMouseButton(button); EventDispatcher::getInstance()->dispatchEvent(&event); @@ -228,6 +229,7 @@ void EGLViewEventHandler::OnGLFWMouseCallBack(GLFWwindow* window, int button, in else if(GLFW_RELEASE == action) { EventMouse event(EventMouse::MouseEventType::MOUSE_UP); + //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); event.setMouseButton(button); EventDispatcher::getInstance()->dispatchEvent(&event); @@ -254,6 +256,7 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, } EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE); + //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); EventDispatcher::getInstance()->dispatchEvent(&event); } @@ -264,7 +267,8 @@ void EGLViewEventHandler::OnGLFWMouseScrollCallback(GLFWwindow* window, double x if(nullptr == eglView) return; EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL); - event.setScrollData((float)x, (float)y); + //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here + event.setScrollData((float)x, -(float)y); event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); EventDispatcher::getInstance()->dispatchEvent(&event); }