Skip to content

Commit 36b76c7

Browse files
committed
working out issues with mouse wheel (processing#1461)
1 parent e893237 commit 36b76c7

4 files changed

Lines changed: 50 additions & 20 deletions

File tree

core/src/processing/core/PApplet.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,18 +2736,20 @@ protected void handleMouseEvent(MouseEvent event) {
27362736
}
27372737

27382738

2739+
/*
2740+
// disabling for now; requires Java 1.7 and "precise" semantics are odd...
2741+
// returns 0.1 for tick-by-tick scrolling on OS X, but it's not a matter of
2742+
// calling ceil() on the value: 1.5 goes to 1, but 2.3 goes to 2.
2743+
// "precise" is a whole different animal, so add later API to shore that up.
27392744
static protected Method preciseWheelMethod;
27402745
static {
2741-
// Class<?> callbackClass = callbackObject.getClass();
2742-
// Method selectMethod =
2743-
// callbackClass.getMethod(callbackMethod, new Class[] { File.class });
2744-
// selectMethod.invoke(callbackObject, new Object[] { selectedFile });
27452746
try {
27462747
preciseWheelMethod = MouseWheelEvent.class.getMethod("getPreciseWheelRotation", new Class[] { });
27472748
} catch (Exception e) {
27482749
// ignored, the method will just be set to null
27492750
}
27502751
}
2752+
*/
27512753

27522754

27532755
/**
@@ -2758,7 +2760,7 @@ protected void handleMouseEvent(MouseEvent event) {
27582760
protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
27592761
// the 'amount' is the number of button clicks for a click event,
27602762
// or the number of steps/clicks on the wheel for a mouse wheel event.
2761-
float peAmount = nativeEvent.getClickCount();
2763+
int peCount = nativeEvent.getClickCount();
27622764

27632765
int peAction = 0;
27642766
switch (nativeEvent.getID()) {
@@ -2783,18 +2785,19 @@ protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
27832785
case java.awt.event.MouseEvent.MOUSE_EXITED:
27842786
peAction = MouseEvent.EXIT;
27852787
break;
2786-
case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
2788+
//case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
2789+
case java.awt.event.MouseEvent.MOUSE_WHEEL:
27872790
peAction = MouseEvent.WHEEL;
2791+
/*
27882792
if (preciseWheelMethod != null) {
27892793
try {
27902794
peAmount = ((Double) preciseWheelMethod.invoke(nativeEvent, (Object[]) null)).floatValue();
27912795
} catch (Exception e) {
27922796
preciseWheelMethod = null;
27932797
}
27942798
}
2795-
if (preciseWheelMethod == null) {
2796-
peAmount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
2797-
}
2799+
*/
2800+
peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
27982801
break;
27992802
}
28002803

@@ -2848,7 +2851,7 @@ protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
28482851
peAction, peModifiers,
28492852
nativeEvent.getX(), nativeEvent.getY(),
28502853
peButton,
2851-
peAmount));
2854+
peCount));
28522855
}
28532856

28542857

core/src/processing/event/MouseEvent.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class MouseEvent extends Event {
3838
protected int x, y;
3939
protected int button;
4040
// protected int clickCount;
41-
protected float amount;
41+
// protected float amount;
42+
protected int count;
4243

4344

4445
// public MouseEvent(int x, int y) {
@@ -50,14 +51,15 @@ public class MouseEvent extends Event {
5051

5152
public MouseEvent(Object nativeObject,
5253
long millis, int action, int modifiers,
53-
int x, int y, int button, float amount) { //int clickCount) {
54+
int x, int y, int button, int count) { //float amount) { //int clickCount) {
5455
super(nativeObject, millis, action, modifiers);
5556
this.flavor = MOUSE;
5657
this.x = x;
5758
this.y = y;
5859
this.button = button;
5960
//this.clickCount = clickCount;
60-
this.amount = amount;
61+
//this.amount = amount;
62+
this.count = count;
6163
}
6264

6365

@@ -82,17 +84,28 @@ public int getButton() {
8284
// }
8385

8486

87+
/** Do not use, getCount() is the correct method. */
88+
@Deprecated
8589
public int getClickCount() {
86-
return (int) amount; //clickCount;
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;
87100
}
88101

89102

90103
/**
91104
* Number of clicks for mouse button events, or the number of steps (positive
92105
* or negative depending on direction) for a mouse wheel event.
93106
*/
94-
public float getAmount() {
95-
return amount;
107+
public int getCount() {
108+
return count;
96109
}
97110

98111

core/src/processing/opengl/PGL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,15 +3289,15 @@ protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
32893289
}
32903290
}
32913291

3292-
float peAmount = peAction == MouseEvent.WHEEL ?
3293-
nativeEvent.getWheelRotation() :
3292+
int peCount = peAction == MouseEvent.WHEEL ?
3293+
(int) nativeEvent.getWheelRotation() :
32943294
nativeEvent.getClickCount();
32953295

32963296
MouseEvent me = new MouseEvent(nativeEvent, nativeEvent.getWhen(),
32973297
peAction, peModifiers,
32983298
nativeEvent.getX(), nativeEvent.getY(),
32993299
peButton,
3300-
peAmount);
3300+
peCount);
33013301

33023302
pg.parent.postEvent(me);
33033303
}

core/todo.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ X getContent() or getStringContent()?
1313
X switch to CATEGORY instead of CATEGORICAL
1414
X removed createXML() and createTable()... just use 'new' for these
1515

16+
before release
17+
_ "deleted n framebuffer objects"
18+
1619
_ draw() called again before finishing on OS X (retina issue)
1720
_ https://github.com/processing/processing/issues/1709
1821

@@ -216,8 +219,19 @@ o might be more effort than it's worth?
216219
X peasycam uses e.getWheelRotation()
217220
X js has a couple versions
218221
X http://www.javascriptkit.com/javatutors/onmousewheel.shtml
219-
X e.detail is 1 for 1 click up, -2 for 2 clicks down
222+
X e.detail is 1 for 1 tick upward (away), -2 for 2 ticks down
220223
X e.wheelDelta is 120 for 1 click up, -240 for two clicks down
224+
X this is for non-natural! opposite of Java.. ugh
225+
_ testing with Java on OS X
226+
227+
natural on OS X: up is 1 unit, down is -1 units
228+
non-natural: up is -1 units, down is +1 unit
229+
Windows says 3 units per notch, OS X says just 1
230+
appears to be opposite of JS
231+
232+
ref: "negative values if the mouse wheel was rotated up or away from the user"
233+
http://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseWheelEvent.html#getWheelRotation()
234+
221235
X using float value (/120.0f)
222236
X high-precision method grabbed if 1.7 is in use
223237
_ test with actual wheel mouse

0 commit comments

Comments
 (0)