mirror of https://github.com/axmolengine/axmol.git
Fixed #5635: Correction of mouse event's cursor position
This commit is contained in:
parent
abfbc4bffb
commit
81df54b82e
|
@ -564,20 +564,22 @@ void GLView::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
|
||||
float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
|
||||
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;
|
||||
|
||||
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(_mouseX, this->getViewPortRect().size.height - _mouseY);
|
||||
event.setCursorPosition(cursorX, cursorY);
|
||||
event.setMouseButton(button);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
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(_mouseX, this->getViewPortRect().size.height - _mouseY);
|
||||
event.setCursorPosition(cursorX, cursorY);
|
||||
event.setMouseButton(button);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
|
@ -605,6 +607,10 @@ void GLView::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
|||
intptr_t id = 0;
|
||||
this->handleTouchesMove(1, &id, &_mouseX, &_mouseY);
|
||||
}
|
||||
|
||||
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
|
||||
float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
|
||||
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;
|
||||
|
||||
EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE);
|
||||
// Set current button
|
||||
|
@ -620,8 +626,7 @@ void GLView::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
|||
{
|
||||
event.setMouseButton(GLFW_MOUSE_BUTTON_MIDDLE);
|
||||
}
|
||||
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
|
||||
event.setCursorPosition(_mouseX, this->getViewPortRect().size.height - _mouseY);
|
||||
event.setCursorPosition(cursorX, cursorY);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue