void CanvasGLFW::mouseMotion(GLFWwindow* window, double x, double y) { CanvasGLFW* thisCanvas = getCanvasGLFW(window); ivec2 screenPos(floor(x), floor(y)); ivec2 screenPosInvY(screenPos.x, static_cast<int>(thisCanvas->getScreenDimensions().y) - 1 - screenPos.y); MouseEvent::MouseState state = (thisCanvas->mouseState_ == MouseEvent::MOUSE_STATE_PRESS ? MouseEvent::MOUSE_STATE_MOVE : thisCanvas->mouseState_); MouseEvent mouseEvent(screenPos, thisCanvas->mouseButton_, state, thisCanvas->mouseModifiers_, thisCanvas->getScreenDimensions(), thisCanvas->getDepthValueAtCoord(screenPosInvY)); if (state == MouseEvent::MOUSE_STATE_MOVE) thisCanvas->mouseMoveEvent(&mouseEvent); else if (state == MouseEvent::MOUSE_STATE_RELEASE) thisCanvas->mouseReleaseEvent(&mouseEvent); }
void CanvasGLFW::mouseButton(GLFWwindow* window, int button, int action, int mods) { CanvasGLFW* thisCanvas = getCanvasGLFW(window); thisCanvas->mouseButton_ = mapMouseButton(button); thisCanvas->mouseState_ = mapMouseState(action); thisCanvas->mouseModifiers_ = mapModifiers(mods); double x; double y; glfwGetCursorPos(window, &x, &y); ivec2 screenPos(floor(x), floor(y)); ivec2 screenPosInvY(screenPos.x, static_cast<int>(thisCanvas->getScreenDimensions().y) - 1 - screenPos.y); MouseEvent mouseEvent(screenPos, thisCanvas->mouseButton_, thisCanvas->mouseState_, thisCanvas->mouseModifiers_, thisCanvas->getScreenDimensions(), thisCanvas->getDepthValueAtCoord(screenPosInvY)); if (thisCanvas->mouseState_ == MouseEvent::MOUSE_STATE_PRESS) thisCanvas->mousePressEvent(&mouseEvent); else if (thisCanvas->mouseState_ == MouseEvent::MOUSE_STATE_RELEASE) thisCanvas->mouseReleaseEvent(&mouseEvent); }