Skip to content

Commit 4e052f0

Browse files
author
Jonathan Feinberg
committed
Fix bug preventing first mouse PRESS from setting mouseX/mouseY when sketch window gains focus from the PRESS.
1 parent 29b8945 commit 4e052f0

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

core/src/processing/core/PApplet.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,10 +2772,14 @@ protected void handleMouseEvent(MouseEvent event) {
27722772
// also prevents mouseExited() on the mac from hosing the mouse
27732773
// position, because x/y are bizarre values on the exit event.
27742774
// see also the id check below.. both of these go together.
2775-
// Not necessary to set mouseX/Y on PRESS or RELEASE events because the
2776-
// actual position will have been set by a MOVE or DRAG event.
2777-
if (event.getAction() == MouseEvent.DRAG ||
2778-
event.getAction() == MouseEvent.MOVE) {
2775+
// Not necessary to set mouseX/Y on RELEASE events because the
2776+
// actual position will have been set by a PRESS or DRAG event.
2777+
// However, PRESS events might come without a preceeding move,
2778+
// if the sketch window gains focus on that PRESS.
2779+
final int action = event.getAction();
2780+
if (action == MouseEvent.DRAG ||
2781+
action == MouseEvent.MOVE ||
2782+
action == MouseEvent.PRESS) {
27792783
pmouseX = emouseX;
27802784
pmouseY = emouseY;
27812785
mouseX = event.getX();
@@ -2809,7 +2813,7 @@ protected void handleMouseEvent(MouseEvent event) {
28092813
// Do this up here in case a registered method relies on the
28102814
// boolean for mousePressed.
28112815

2812-
switch (event.getAction()) {
2816+
switch (action) {
28132817
case MouseEvent.PRESS:
28142818
mousePressed = true;
28152819
break;
@@ -2820,7 +2824,7 @@ protected void handleMouseEvent(MouseEvent event) {
28202824

28212825
handleMethods("mouseEvent", new Object[] { event });
28222826

2823-
switch (event.getAction()) {
2827+
switch (action) {
28242828
case MouseEvent.PRESS:
28252829
// mousePressed = true;
28262830
mousePressed(event);
@@ -2849,8 +2853,8 @@ protected void handleMouseEvent(MouseEvent event) {
28492853
break;
28502854
}
28512855

2852-
if ((event.getAction() == MouseEvent.DRAG) ||
2853-
(event.getAction() == MouseEvent.MOVE)) {
2856+
if ((action == MouseEvent.DRAG) ||
2857+
(action == MouseEvent.MOVE)) {
28542858
emouseX = mouseX;
28552859
emouseY = mouseY;
28562860
}

core/src/processing/event/MouseEvent.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,33 @@ public int getCount() {
117117
// public void setClickCount(int clickCount) {
118118
// this.clickCount = clickCount;
119119
// }
120+
121+
private String actionString() {
122+
switch (action) {
123+
default:
124+
return "UNKNOWN";
125+
case CLICK:
126+
return "CLICK";
127+
case DRAG:
128+
return "DRAG";
129+
case ENTER:
130+
return "ENTER";
131+
case EXIT:
132+
return "EXIT";
133+
case MOVE:
134+
return "MOVE";
135+
case PRESS:
136+
return "PRESS";
137+
case RELEASE:
138+
return "RELEASE";
139+
case WHEEL:
140+
return "WHEEL";
141+
}
142+
}
143+
144+
@Override
145+
public String toString() {
146+
return String.format("<MouseEvent %s@%d,%d count:%d button:%d>",
147+
actionString(), x, y, count, button);
148+
}
120149
}

0 commit comments

Comments
 (0)