Skip to content

Commit 683a586

Browse files
committed
Unify mouse pressed/released events across renderers
OPENGL and FX renderers will now correctly report button which triggered this pressed/released event (same as JAVA2D). Previously: - OPENGL would report currently pressed buttons in order LEFT, CENTER, RIGHT regardless of which button triggered the event. E.g. when holding LEFT and presing RIGHT, LEFT would be reported. When holding CENTER and pressing LEFT, LEFT would be reported - FX would report only first button which is down, so in RELEASE event button would be missing Now: - event contains only button which triggred this event (button just pressed or just released)
1 parent 5c219a3 commit 683a586

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

core/src/processing/javafx/PSurfaceFX.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -806,11 +806,6 @@ protected void fxMouseEvent(MouseEvent fxEvent) {
806806
int count = fxEvent.getClickCount();
807807

808808
int action = mouseMap.get(fxEvent.getEventType());
809-
//EventType<? extends MouseEvent> et = nativeEvent.getEventType();
810-
// if (et == MouseEvent.MOUSE_PRESSED) {
811-
// peAction = processing.event.MouseEvent.PRESS;
812-
// } else if (et == MouseEvent.MOUSE_RELEASED) {
813-
// peAction = processing.event.MouseEvent.RELEASE;
814809

815810
int modifiers = 0;
816811
if (fxEvent.isShiftDown()) {
@@ -827,12 +822,16 @@ protected void fxMouseEvent(MouseEvent fxEvent) {
827822
}
828823

829824
int button = 0;
830-
if (fxEvent.isPrimaryButtonDown()) {
831-
button = PConstants.LEFT;
832-
} else if (fxEvent.isSecondaryButtonDown()) {
833-
button = PConstants.RIGHT;
834-
} else if (fxEvent.isMiddleButtonDown()) {
835-
button = PConstants.CENTER;
825+
switch (fxEvent.getButton()) {
826+
case PRIMARY:
827+
button = PConstants.LEFT;
828+
break;
829+
case SECONDARY:
830+
button = PConstants.RIGHT;
831+
break;
832+
case MIDDLE:
833+
button = PConstants.CENTER;
834+
break;
836835
}
837836

838837
// If running on Mac OS, allow ctrl-click as right mouse.

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,12 +1060,16 @@ protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
10601060
InputEvent.ALT_MASK);
10611061

10621062
int peButton = 0;
1063-
if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
1064-
peButton = PConstants.LEFT;
1065-
} else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
1066-
peButton = PConstants.CENTER;
1067-
} else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
1068-
peButton = PConstants.RIGHT;
1063+
switch (nativeEvent.getButton()) {
1064+
case com.jogamp.newt.event.MouseEvent.BUTTON1:
1065+
peButton = PConstants.LEFT;
1066+
break;
1067+
case com.jogamp.newt.event.MouseEvent.BUTTON2:
1068+
peButton = PConstants.CENTER;
1069+
break;
1070+
case com.jogamp.newt.event.MouseEvent.BUTTON3:
1071+
peButton = PConstants.RIGHT;
1072+
break;
10691073
}
10701074

10711075
if (PApplet.platform == PConstants.MACOSX) {

0 commit comments

Comments
 (0)