Skip to content

Commit 26d04ae

Browse files
committed
swap getModifiers() for getModifiersEx() to deal with deprecation (fixes #4)
1 parent 4a6cdf5 commit 26d04ae

File tree

5 files changed

+37
-76
lines changed

5 files changed

+37
-76
lines changed

core/src/processing/awt/PSurfaceAWT.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,44 +1316,24 @@ protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
13161316
break;
13171317
}
13181318

1319-
//System.out.println(nativeEvent);
1320-
//int modifiers = nativeEvent.getModifiersEx();
1321-
// If using getModifiersEx(), the regular modifiers don't set properly.
1322-
int modifiers = nativeEvent.getModifiers();
1323-
1324-
int peModifiers = modifiers &
1325-
(InputEvent.SHIFT_MASK |
1326-
InputEvent.CTRL_MASK |
1327-
InputEvent.META_MASK |
1328-
InputEvent.ALT_MASK);
1329-
1330-
// Windows and OS X seem to disagree on how to handle this. Windows only
1331-
// sets BUTTON1_DOWN_MASK, while OS X seems to set BUTTON1_MASK.
1332-
// This is an issue in particular with mouse release events:
1319+
// Switching to getModifiersEx() for 4.0a2 because of Java 9 deprecation.
1320+
// Had trouble with this in the past and rolled it back because it was
1321+
// optional at the time. This time around, just need to iron out the issue.
13331322
// http://code.google.com/p/processing/issues/detail?id=1294
1334-
// The fix for which led to a regression (fixed here by checking both):
13351323
// http://code.google.com/p/processing/issues/detail?id=1332
1324+
int modifiers = nativeEvent.getModifiersEx();
1325+
13361326
int peButton = 0;
1337-
// if ((modifiers & InputEvent.BUTTON1_MASK) != 0 ||
1338-
// (modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
1339-
// peButton = LEFT;
1340-
// } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0 ||
1341-
// (modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
1342-
// peButton = CENTER;
1343-
// } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0 ||
1344-
// (modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
1345-
// peButton = RIGHT;
1346-
// }
1347-
if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
1327+
if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
13481328
peButton = PConstants.LEFT;
1349-
} else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
1329+
} else if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
13501330
peButton = PConstants.CENTER;
1351-
} else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
1331+
} else if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
13521332
peButton = PConstants.RIGHT;
13531333
}
13541334

13551335
sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
1356-
peAction, peModifiers,
1336+
peAction, modifiers,
13571337
nativeEvent.getX() / windowScaleFactor,
13581338
nativeEvent.getY() / windowScaleFactor,
13591339
peButton,
@@ -1375,6 +1355,9 @@ protected void nativeKeyEvent(java.awt.event.KeyEvent event) {
13751355
break;
13761356
}
13771357

1358+
int modifiers = event.getModifiersEx();
1359+
1360+
/*
13781361
// int peModifiers = event.getModifiersEx() &
13791362
// (InputEvent.SHIFT_DOWN_MASK |
13801363
// InputEvent.CTRL_DOWN_MASK |
@@ -1385,9 +1368,10 @@ protected void nativeKeyEvent(java.awt.event.KeyEvent event) {
13851368
InputEvent.CTRL_MASK |
13861369
InputEvent.META_MASK |
13871370
InputEvent.ALT_MASK);
1371+
*/
13881372

13891373
sketch.postEvent(new KeyEvent(event, event.getWhen(),
1390-
peAction, peModifiers,
1374+
peAction, modifiers,
13911375
event.getKeyChar(), event.getKeyCode()));
13921376
}
13931377

core/src/processing/event/MouseEvent.java

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,17 @@ public class MouseEvent extends Event {
3737

3838
protected int x, y;
3939
protected int button;
40-
// protected int clickCount;
41-
// protected float amount;
4240
protected int count;
4341

4442

45-
// public MouseEvent(int x, int y) {
46-
// this(null,
47-
// System.currentTimeMillis(), PRESSED, 0,
48-
// x, y, PConstants.LEFT, 1);
49-
// }
50-
51-
5243
public MouseEvent(Object nativeObject,
5344
long millis, int action, int modifiers,
54-
int x, int y, int button, int count) { //float amount) { //int clickCount) {
45+
int x, int y, int button, int count) {
5546
super(nativeObject, millis, action, modifiers);
5647
this.flavor = MOUSE;
5748
this.x = x;
5849
this.y = y;
5950
this.button = button;
60-
//this.clickCount = clickCount;
61-
//this.amount = amount;
6251
this.count = count;
6352
}
6453

@@ -79,27 +68,6 @@ public int getButton() {
7968
}
8069

8170

82-
// public void setButton(int button) {
83-
// this.button = button;
84-
// }
85-
86-
87-
/** Do not use, getCount() is the correct method. */
88-
@Deprecated
89-
public int getClickCount() {
90-
//return (int) amount; //clickCount;
91-
return count;
92-
}
93-
94-
95-
/** Do not use, getCount() is the correct method. */
96-
@Deprecated
97-
public float getAmount() {
98-
//return amount;
99-
return count;
100-
}
101-
102-
10371
/**
10472
* Number of clicks for mouse button events, or the number of steps (positive
10573
* or negative depending on direction) for a mouse wheel event.
@@ -114,10 +82,6 @@ public int getCount() {
11482
}
11583

11684

117-
// public void setClickCount(int clickCount) {
118-
// this.clickCount = clickCount;
119-
// }
120-
12185
private String actionString() {
12286
switch (action) {
12387
default:

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ public PSurface createSurface() { // ignore
751751
}
752752

753753

754+
@Override
754755
public boolean saveImpl(String filename) {
755756
// return super.save(filename); // ASYNC save frame using PBOs not yet available on Android
756757

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import com.jogamp.newt.NewtFactory;
6666
import com.jogamp.newt.Screen;
6767
import com.jogamp.newt.awt.NewtCanvasAWT;
68-
import com.jogamp.newt.event.InputEvent;
6968
import com.jogamp.newt.opengl.GLWindow;
7069
import com.jogamp.opengl.util.FPSAnimator;
7170

@@ -77,6 +76,7 @@
7776
import processing.event.KeyEvent;
7877
import processing.event.MouseEvent;
7978
import processing.awt.PImageAWT;
79+
8080
// have this removed by 4.0 final
8181
import processing.awt.ShimAWT;
8282

@@ -1110,11 +1110,13 @@ public void keyTyped(com.jogamp.newt.event.KeyEvent e) {
11101110
protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
11111111
int peAction) {
11121112
int modifiers = nativeEvent.getModifiers();
1113+
/*
11131114
int peModifiers = modifiers &
11141115
(InputEvent.SHIFT_MASK |
11151116
InputEvent.CTRL_MASK |
11161117
InputEvent.META_MASK |
11171118
InputEvent.ALT_MASK);
1119+
*/
11181120

11191121
int peButton = 0;
11201122
switch (nativeEvent.getButton()) {
@@ -1163,7 +1165,7 @@ protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
11631165
}
11641166

11651167
MouseEvent me = new MouseEvent(nativeEvent, nativeEvent.getWhen(),
1166-
peAction, peModifiers,
1168+
peAction, modifiers,
11671169
mx, my,
11681170
peButton,
11691171
peCount);
@@ -1174,11 +1176,12 @@ protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
11741176

11751177
protected void nativeKeyEvent(com.jogamp.newt.event.KeyEvent nativeEvent,
11761178
int peAction) {
1177-
int peModifiers = nativeEvent.getModifiers() &
1178-
(InputEvent.SHIFT_MASK |
1179-
InputEvent.CTRL_MASK |
1180-
InputEvent.META_MASK |
1181-
InputEvent.ALT_MASK);
1179+
int modifiers = nativeEvent.getModifiers();
1180+
// int peModifiers = nativeEvent.getModifiers() &
1181+
// (InputEvent.SHIFT_MASK |
1182+
// InputEvent.CTRL_MASK |
1183+
// InputEvent.META_MASK |
1184+
// InputEvent.ALT_MASK);
11821185

11831186
short code = nativeEvent.getKeyCode();
11841187
char keyChar;
@@ -1204,7 +1207,7 @@ protected void nativeKeyEvent(com.jogamp.newt.event.KeyEvent nativeEvent,
12041207
// In contrast to key symbol, key code uses a fixed US keyboard layout and therefore is keyboard layout independent.
12051208
// E.g. virtual key code VK_Y denotes the same physical key regardless whether keyboard layout QWERTY or QWERTZ is active. The key symbol of the former is VK_Y, where the latter produces VK_Y.
12061209
KeyEvent ke = new KeyEvent(nativeEvent, nativeEvent.getWhen(),
1207-
peAction, peModifiers,
1210+
peAction, modifiers,
12081211
keyChar,
12091212
keyCode,
12101213
nativeEvent.isAutoRepeat());
@@ -1216,7 +1219,7 @@ protected void nativeKeyEvent(com.jogamp.newt.event.KeyEvent nativeEvent,
12161219
// Create key typed event
12171220
// TODO: combine dead keys with the following key
12181221
KeyEvent tke = new KeyEvent(nativeEvent, nativeEvent.getWhen(),
1219-
KeyEvent.TYPE, peModifiers,
1222+
KeyEvent.TYPE, modifiers,
12201223
keyChar,
12211224
0,
12221225
nativeEvent.isAutoRepeat());

core/todo.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@ X move loadImage() into ShimAWT
1515
X desktopFile() and desktopPath() methods are supported, unless we find they're trouble
1616
X move ShimAWT.loadImage() to the PSurface subclasses
1717
X move all java.awt and javax.imageio out of PImage
18+
X make the switch to getModifiersEx() instead of getModifiers()
19+
X pass all modifiers to the KeyEvent and MouseEvent constructors
20+
X though they aren't even being stored, so what's the point?
21+
22+
contribs
23+
X remove redundant boxing and casting
24+
X https://github.com/processing/processing4/pull/51
1825

1926
api changes
2027
_ static versions of selectInput/selectOutput/selectFolder in PApplet have been removed
2128
_ java.awt.Frame object "frame" removed from PApplet (been warning since 2015)
2229
_ protected PImage.checkAlpha() now public
2330
_ all AWT calls have been moved out of PImage
2431
_ this may be a problem for anything that was relying on those internals
32+
_ removed MouseEvent.getClickCount() and MouseEvent.getAmount()
33+
_ these had been deprecated, not clear they were used anywhere
2534

2635
api todo
2736
_ Surface not available inside handleSettings()

0 commit comments

Comments
 (0)