Merge pull request #7262 from pandamicro/origin_v3

Indicate correct button and cursor position infomation in mouse move event
This commit is contained in:
minggo 2014-07-08 21:07:09 +08:00
commit c2474ea7c0
2 changed files with 25 additions and 7 deletions

View File

@ -30,7 +30,7 @@ NS_CC_BEGIN
EventMouse::EventMouse(MouseEventType mouseEventCode)
: Event(Type::MOUSE)
, _mouseEventType(mouseEventCode)
, _mouseButton(0)
, _mouseButton(-1)
, _x(0.0f)
, _y(0.0f)
, _scrollX(0.0f)

View File

@ -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,10 +607,26 @@ 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);
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
event.setCursorPosition(_mouseX, this->getViewPortRect().size.height - _mouseY);
// 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);
}