mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
working out issues with mouse wheel (#1461)
This commit is contained in:
@@ -2736,18 +2736,20 @@ public class PApplet extends Applet
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// disabling for now; requires Java 1.7 and "precise" semantics are odd...
|
||||
// returns 0.1 for tick-by-tick scrolling on OS X, but it's not a matter of
|
||||
// calling ceil() on the value: 1.5 goes to 1, but 2.3 goes to 2.
|
||||
// "precise" is a whole different animal, so add later API to shore that up.
|
||||
static protected Method preciseWheelMethod;
|
||||
static {
|
||||
// Class<?> callbackClass = callbackObject.getClass();
|
||||
// Method selectMethod =
|
||||
// callbackClass.getMethod(callbackMethod, new Class[] { File.class });
|
||||
// selectMethod.invoke(callbackObject, new Object[] { selectedFile });
|
||||
try {
|
||||
preciseWheelMethod = MouseWheelEvent.class.getMethod("getPreciseWheelRotation", new Class[] { });
|
||||
} catch (Exception e) {
|
||||
// ignored, the method will just be set to null
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
@@ -2758,7 +2760,7 @@ public class PApplet extends Applet
|
||||
protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
|
||||
// the 'amount' is the number of button clicks for a click event,
|
||||
// or the number of steps/clicks on the wheel for a mouse wheel event.
|
||||
float peAmount = nativeEvent.getClickCount();
|
||||
int peCount = nativeEvent.getClickCount();
|
||||
|
||||
int peAction = 0;
|
||||
switch (nativeEvent.getID()) {
|
||||
@@ -2783,8 +2785,10 @@ public class PApplet extends Applet
|
||||
case java.awt.event.MouseEvent.MOUSE_EXITED:
|
||||
peAction = MouseEvent.EXIT;
|
||||
break;
|
||||
case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
|
||||
//case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
|
||||
case java.awt.event.MouseEvent.MOUSE_WHEEL:
|
||||
peAction = MouseEvent.WHEEL;
|
||||
/*
|
||||
if (preciseWheelMethod != null) {
|
||||
try {
|
||||
peAmount = ((Double) preciseWheelMethod.invoke(nativeEvent, (Object[]) null)).floatValue();
|
||||
@@ -2792,9 +2796,8 @@ public class PApplet extends Applet
|
||||
preciseWheelMethod = null;
|
||||
}
|
||||
}
|
||||
if (preciseWheelMethod == null) {
|
||||
peAmount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
|
||||
}
|
||||
*/
|
||||
peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2848,7 +2851,7 @@ public class PApplet extends Applet
|
||||
peAction, peModifiers,
|
||||
nativeEvent.getX(), nativeEvent.getY(),
|
||||
peButton,
|
||||
peAmount));
|
||||
peCount));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ public class MouseEvent extends Event {
|
||||
protected int x, y;
|
||||
protected int button;
|
||||
// protected int clickCount;
|
||||
protected float amount;
|
||||
// protected float amount;
|
||||
protected int count;
|
||||
|
||||
|
||||
// public MouseEvent(int x, int y) {
|
||||
@@ -50,14 +51,15 @@ public class MouseEvent extends Event {
|
||||
|
||||
public MouseEvent(Object nativeObject,
|
||||
long millis, int action, int modifiers,
|
||||
int x, int y, int button, float amount) { //int clickCount) {
|
||||
int x, int y, int button, int count) { //float amount) { //int clickCount) {
|
||||
super(nativeObject, millis, action, modifiers);
|
||||
this.flavor = MOUSE;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.button = button;
|
||||
//this.clickCount = clickCount;
|
||||
this.amount = amount;
|
||||
//this.amount = amount;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +84,19 @@ public class MouseEvent extends Event {
|
||||
// }
|
||||
|
||||
|
||||
/** Do not use, getCount() is the correct method. */
|
||||
@Deprecated
|
||||
public int getClickCount() {
|
||||
return (int) amount; //clickCount;
|
||||
//return (int) amount; //clickCount;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/** Do not use, getCount() is the correct method. */
|
||||
@Deprecated
|
||||
public float getAmount() {
|
||||
//return amount;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +104,8 @@ public class MouseEvent extends Event {
|
||||
* Number of clicks for mouse button events, or the number of steps (positive
|
||||
* or negative depending on direction) for a mouse wheel event.
|
||||
*/
|
||||
public float getAmount() {
|
||||
return amount;
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3289,15 +3289,15 @@ public class PGL {
|
||||
}
|
||||
}
|
||||
|
||||
float peAmount = peAction == MouseEvent.WHEEL ?
|
||||
nativeEvent.getWheelRotation() :
|
||||
int peCount = peAction == MouseEvent.WHEEL ?
|
||||
(int) nativeEvent.getWheelRotation() :
|
||||
nativeEvent.getClickCount();
|
||||
|
||||
MouseEvent me = new MouseEvent(nativeEvent, nativeEvent.getWhen(),
|
||||
peAction, peModifiers,
|
||||
nativeEvent.getX(), nativeEvent.getY(),
|
||||
peButton,
|
||||
peAmount);
|
||||
peCount);
|
||||
|
||||
pg.parent.postEvent(me);
|
||||
}
|
||||
|
||||
+15
-1
@@ -13,6 +13,9 @@ X getContent() or getStringContent()?
|
||||
X switch to CATEGORY instead of CATEGORICAL
|
||||
X removed createXML() and createTable()... just use 'new' for these
|
||||
|
||||
before release
|
||||
_ "deleted n framebuffer objects"
|
||||
|
||||
_ draw() called again before finishing on OS X (retina issue)
|
||||
_ https://github.com/processing/processing/issues/1709
|
||||
|
||||
@@ -216,8 +219,19 @@ o might be more effort than it's worth?
|
||||
X peasycam uses e.getWheelRotation()
|
||||
X js has a couple versions
|
||||
X http://www.javascriptkit.com/javatutors/onmousewheel.shtml
|
||||
X e.detail is 1 for 1 click up, -2 for 2 clicks down
|
||||
X e.detail is 1 for 1 tick upward (away), -2 for 2 ticks down
|
||||
X e.wheelDelta is 120 for 1 click up, -240 for two clicks down
|
||||
X this is for non-natural! opposite of Java.. ugh
|
||||
_ testing with Java on OS X
|
||||
|
||||
natural on OS X: up is 1 unit, down is -1 units
|
||||
non-natural: up is -1 units, down is +1 unit
|
||||
Windows says 3 units per notch, OS X says just 1
|
||||
appears to be opposite of JS
|
||||
|
||||
ref: "negative values if the mouse wheel was rotated up or away from the user"
|
||||
http://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseWheelEvent.html#getWheelRotation()
|
||||
|
||||
X using float value (/120.0f)
|
||||
X high-precision method grabbed if 1.7 is in use
|
||||
_ test with actual wheel mouse
|
||||
|
||||
Reference in New Issue
Block a user