void GLViewEventHandler::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y) { GLView* eglView = Director::getInstance()->getOpenGLView(); if(nullptr == eglView) return; if (eglView->isRetina()) { x *= 2; y *= 2; } s_mouseX = (float)x; s_mouseY = (float)y; s_mouseX /= eglView->getFrameZoomFactor(); s_mouseY /= eglView->getFrameZoomFactor(); if(s_captured) { if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,eglView->getFrameSize().height - s_mouseY))) { int id = 0; eglView->handleTouchesMove(1, &id, &s_mouseX, &s_mouseY); } } 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); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); }
void GLViewEventHandler::onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y) { GLView* eglView = Director::getInstance()->getOpenGLView(); if(nullptr == eglView) return; EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL); //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); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); }
void GLViewEventHandler::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify) { GLView* eglView = Director::getInstance()->getOpenGLView(); if(nullptr == eglView) return; if(GLFW_MOUSE_BUTTON_LEFT == button) { if(GLFW_PRESS == action) { s_captured = true; if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY))) { int id = 0; eglView->handleTouchesBegin(1, &id, &s_mouseX, &s_mouseY); } } else if(GLFW_RELEASE == action) { s_captured = false; if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY))) { int id = 0; eglView->handleTouchesEnd(1, &id, &s_mouseX, &s_mouseY); } } } 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); 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(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); event.setMouseButton(button); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); } }