예제 #1
0
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);
}
예제 #2
0
void CanvasGLFW::scroll(GLFWwindow* window, double xoffset, double yoffset) {
    CanvasGLFW* thisCanvas = getCanvasGLFW(window);
    thisCanvas->mouseButton_ = MouseEvent::MOUSE_BUTTON_MIDDLE;
    thisCanvas->mouseState_ = MouseEvent::MOUSE_STATE_WHEEL;
    thisCanvas->mouseModifiers_ = KeyboardEvent::MODIFIER_NONE;
    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);
    int delta = static_cast<int>(yoffset < 0.0 ? floor(yoffset) : ceil(yoffset));

    MouseEvent mouseEvent(screenPos, delta, thisCanvas->mouseButton_, thisCanvas->mouseState_,
                          MouseEvent::MOUSE_WHEEL_VERTICAL, thisCanvas->mouseModifiers_,
                          thisCanvas->getScreenDimensions(),
                          thisCanvas->getDepthValueAtCoord(screenPosInvY));

    thisCanvas->mouseWheelEvent(&mouseEvent);
}
예제 #3
0
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);
}