Search in sources :

Example 1 with MouseButton

use of javafx.scene.input.MouseButton in project TestFX by TestFX.

the class JavafxRobotAdapter method createMouseEvent.

private MouseEvent createMouseEvent(EventType<MouseEvent> eventType, double x, double y, MouseButton mouseButton, int clickCount) {
    screenMouseX = scene.getWindow().getX() + scene.getX() + x;
    screenMouseY = scene.getWindow().getY() + scene.getY() + y;
    sceneMouseX = x;
    sceneMouseY = y;
    MouseButton button = mouseButton;
    EventType<MouseEvent> type = eventType;
    if (type == MouseEvent.MOUSE_PRESSED || type == MouseEvent.MOUSE_RELEASED) {
        boolean pressed = type == MouseEvent.MOUSE_PRESSED;
        switch(button) {
            case PRIMARY:
                isButton1Pressed = pressed;
                break;
            case MIDDLE:
                isButton2Pressed = pressed;
                break;
            case SECONDARY:
                isButton3Pressed = pressed;
                break;
        }
        if (pressed) {
            lastButtonPressed = button;
        } else {
            if (!(isButton1Pressed || isButton2Pressed || isButton3Pressed)) {
                lastButtonPressed = MouseButton.NONE;
            }
        }
    } else if (type == MouseEvent.MOUSE_MOVED) {
        boolean someButtonPressed = isButton1Pressed || isButton2Pressed || isButton3Pressed;
        if (someButtonPressed) {
            type = MouseEvent.MOUSE_DRAGGED;
            button = MouseButton.NONE;
        }
    }
    return new MouseEvent(type, (int) sceneMouseX, (int) sceneMouseY, (int) screenMouseX, (int) screenMouseY, button, clickCount, isShiftDown, isControlDown, isAltDown, isMetaDown, isButton1Pressed, isButton2Pressed, isButton3Pressed, false, button == MouseButton.SECONDARY, false, null);
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) MouseButton(javafx.scene.input.MouseButton)

Aggregations

MouseButton (javafx.scene.input.MouseButton)1 MouseEvent (javafx.scene.input.MouseEvent)1