summaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/MouseEvent.java14
-rw-r--r--src/newt/classes/com/jogamp/newt/event/MouseListener.java2
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java5
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Window.java50
-rw-r--r--src/newt/native/NewtMacWindow.m18
-rw-r--r--src/newt/native/WindowsWindow.c2
6 files changed, 75 insertions, 16 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
index ccc674f1d..9bc3be1e5 100644
--- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
@@ -139,6 +139,20 @@ public class MouseEvent extends InputEvent
return pressure[index];
}
+ /**
+ * <i>Usually</i> a wheel rotation of <b>&gt; 0 is up</b>,
+ * and <b>&lt; 0 is down</b>.<br>
+ * <i>However</i>, on some OS this might be flipped due to the OS <i>default</i> behavior.
+ * The latter is true for OS X 10.7 (Lion) for example.
+ * <p>
+ * The events will be send usually in steps of one, ie. <i>-1</i> and <i>1</i>.
+ * Higher values may result due to fast scrolling.
+ * </p>
+ * <p>
+ * The button number refers to the wheel number.
+ * </p>
+ * @return
+ */
public int getWheelRotation() {
return wheelRotation;
}
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseListener.java b/src/newt/classes/com/jogamp/newt/event/MouseListener.java
index 5ec086b94..7668b755c 100644
--- a/src/newt/classes/com/jogamp/newt/event/MouseListener.java
+++ b/src/newt/classes/com/jogamp/newt/event/MouseListener.java
@@ -43,6 +43,8 @@ public interface MouseListener extends NEWTEventListener
public void mouseReleased(MouseEvent e);
public void mouseMoved(MouseEvent e);
public void mouseDragged(MouseEvent e);
+
+ /** See {@link MouseEvent#getWheelRotation() } */
public void mouseWheelMoved(MouseEvent e);
}
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index e496ae4fb..f0abd9625 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -1904,8 +1904,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
int x, int y, int button, int rotation) {
doMouseEvent(true, wait, eventType, modifiers, x, y, button, rotation);
}
- private void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers,
- int x, int y, int button, int rotation) {
+
+ protected void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers,
+ int x, int y, int button, int rotation) {
if(eventType == MouseEvent.EVENT_MOUSE_ENTERED ||
eventType == MouseEvent.EVENT_MOUSE_EXITED) {
if(eventType == MouseEvent.EVENT_MOUSE_EXITED && x==-1 && y==-1) {
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
index 1cff26fad..bfaf53f0d 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
@@ -44,9 +44,15 @@ import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.InsetsImmutable;
import javax.media.nativewindow.util.Point;
+import com.jogamp.newt.event.MouseEvent;
+
public class X11Window extends WindowImpl {
private static final String WINDOW_CLASS_NAME = "NewtWindow";
-
+ private static final int X11_WHEEL_ONE_UP_BUTTON = 4;
+ private static final int X11_WHEEL_ONE_DOWN_BUTTON = 5;
+ private static final int X11_WHEEL_TWO_UP_BUTTON = 6;
+ private static final int X11_WHEEL_TWO_DOWN_BUTTON = 7;
+
static {
X11Display.initSingleton();
}
@@ -175,6 +181,48 @@ public class X11Window extends WindowImpl {
// nop - using event driven insetsChange(..)
}
+ protected void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers,
+ int x, int y, int button, int rotation) {
+ switch(eventType) {
+ case MouseEvent.EVENT_MOUSE_PRESSED:
+ switch(button) {
+ case X11_WHEEL_ONE_UP_BUTTON:
+ case X11_WHEEL_ONE_DOWN_BUTTON:
+ case X11_WHEEL_TWO_UP_BUTTON:
+ case X11_WHEEL_TWO_DOWN_BUTTON:
+ // ignore wheel pressed !
+ return;
+ }
+ break;
+ case MouseEvent.EVENT_MOUSE_RELEASED:
+ switch(button) {
+ case X11_WHEEL_ONE_UP_BUTTON:
+ eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
+ button = 1;
+ rotation = 1;
+ break;
+ case X11_WHEEL_ONE_DOWN_BUTTON:
+ eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
+ button = 1;
+ rotation = -1;
+ break;
+ case X11_WHEEL_TWO_UP_BUTTON:
+ eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
+ button = 2;
+ rotation = 1;
+ break;
+ case X11_WHEEL_TWO_DOWN_BUTTON:
+ eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
+ button = 2;
+ rotation = -1;
+ break;
+ }
+ break;
+ }
+ super.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, rotation);
+ }
+
+
//----------------------------------------------------------------------
// Internals only
//
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 1018633b1..ce41673c4 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -44,15 +44,17 @@ jint GetDeltaY(NSEvent *event, jint javaMods) {
// mouse pad case
deltaY =
CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1);
+ // fprintf(stderr, "WHEEL/PAD: %lf\n", (double)deltaY);
} else {
// traditional mouse wheel case
deltaY = [event deltaY];
+ // fprintf(stderr, "WHEEL/TRAD: %lf\n", (double)deltaY);
if (deltaY == 0.0 && (javaMods & EVENT_SHIFT_MASK) != 0) {
// shift+vertical wheel scroll produces horizontal scroll
// we convert it to vertical
deltaY = [event deltaX];
}
- if (deltaY < 1.0 && deltaY > -1.0) {
+ if (-1.0 < deltaY && deltaY < 1.0) {
deltaY *= 10.0;
} else {
if (deltaY < 0.0) {
@@ -62,14 +64,8 @@ jint GetDeltaY(NSEvent *event, jint javaMods) {
}
}
}
-
- if (deltaY > 0) {
- return (NSInteger)deltaY;
- } else if (deltaY < 0) {
- return -(NSInteger)deltaY;
- }
-
- return 0;
+ // fprintf(stderr, "WHEEL/res: %d\n", (int)deltaY);
+ return (jint) deltaY;
}
static jmethodID enqueueMouseEventID = NULL;
@@ -581,6 +577,7 @@ static jint mods2JavaMods(NSUInteger mods)
switch ([event type]) {
case NSScrollWheel: {
scrollDeltaY = GetDeltaY(event, javaMods);
+ javaButtonNum = 1;
break;
}
case NSLeftMouseDown:
@@ -598,9 +595,6 @@ static jint mods2JavaMods(NSUInteger mods)
case NSOtherMouseDragged:
javaButtonNum = 2;
break;
- default:
- javaButtonNum = 0;
- break;
}
if (evType == EVENT_MOUSE_WHEEL_MOVED && scrollDeltaY == 0) {
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index b654fbe85..9b97895c6 100644
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -953,7 +953,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
(jint) EVENT_MOUSE_WHEEL_MOVED,
GetModifiers(),
(jint) eventPt.x, (jint) eventPt.y,
- (jint) 0, (jint) (GET_WHEEL_DELTA_WPARAM(wParam)/120.0f));
+ (jint) 1, (jint) (GET_WHEEL_DELTA_WPARAM(wParam)/120.0f));
useDefWindowProc = 1;
break;
}