mirror of https://github.com/axmolengine/axmol.git
Merge pull request #7262 from pandamicro/origin_v3
Indicate correct button and cursor position infomation in mouse move event
This commit is contained in:
commit
c2474ea7c0
|
@ -30,7 +30,7 @@ NS_CC_BEGIN
|
||||||
EventMouse::EventMouse(MouseEventType mouseEventCode)
|
EventMouse::EventMouse(MouseEventType mouseEventCode)
|
||||||
: Event(Type::MOUSE)
|
: Event(Type::MOUSE)
|
||||||
, _mouseEventType(mouseEventCode)
|
, _mouseEventType(mouseEventCode)
|
||||||
, _mouseButton(0)
|
, _mouseButton(-1)
|
||||||
, _x(0.0f)
|
, _x(0.0f)
|
||||||
, _y(0.0f)
|
, _y(0.0f)
|
||||||
, _scrollX(0.0f)
|
, _scrollX(0.0f)
|
||||||
|
|
|
@ -565,19 +565,21 @@ 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)
|
if(GLFW_PRESS == action)
|
||||||
{
|
{
|
||||||
EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN);
|
EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN);
|
||||||
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
|
event.setCursorPosition(cursorX, cursorY);
|
||||||
event.setCursorPosition(_mouseX, this->getViewPortRect().size.height - _mouseY);
|
|
||||||
event.setMouseButton(button);
|
event.setMouseButton(button);
|
||||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||||
}
|
}
|
||||||
else if(GLFW_RELEASE == action)
|
else if(GLFW_RELEASE == action)
|
||||||
{
|
{
|
||||||
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
|
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
|
||||||
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
|
event.setCursorPosition(cursorX, cursorY);
|
||||||
event.setCursorPosition(_mouseX, this->getViewPortRect().size.height - _mouseY);
|
|
||||||
event.setMouseButton(button);
|
event.setMouseButton(button);
|
||||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||||
}
|
}
|
||||||
|
@ -606,9 +608,25 @@ void GLView::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
|
||||||
this->handleTouchesMove(1, &id, &_mouseX, &_mouseY);
|
this->handleTouchesMove(1, &id, &_mouseX, &_mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE);
|
|
||||||
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
|
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
|
||||||
event.setCursorPosition(_mouseX, this->getViewPortRect().size.height - _mouseY);
|
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
|
||||||
|
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
event.setMouseButton(GLFW_MOUSE_BUTTON_LEFT);
|
||||||
|
}
|
||||||
|
else if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
event.setMouseButton(GLFW_MOUSE_BUTTON_RIGHT);
|
||||||
|
}
|
||||||
|
else if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
event.setMouseButton(GLFW_MOUSE_BUTTON_MIDDLE);
|
||||||
|
}
|
||||||
|
event.setCursorPosition(cursorX, cursorY);
|
||||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue