diff options
author | Sven Gothel <[email protected]> | 2009-09-11 01:34:27 -0700 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-09-11 01:34:27 -0700 |
commit | 8d4ab1184acf82c015f3268a201bb6b01bb59add (patch) | |
tree | 508a30d13d818cf81f5a53160aa5d449d7f0dc27 /src/newt/native | |
parent | 8363a11c29c49a1334deeed2a8f060ca4804892e (diff) | |
parent | 2e550f9fe080de8ecf23059a38e77b13669805b5 (diff) |
Merge branch 'master' of ssh://git.kenai.com/jogl~jogl-git
Diffstat (limited to 'src/newt/native')
-rwxr-xr-x | src/newt/native/NewtMacWindow.m | 55 | ||||
-rwxr-xr-x | src/newt/native/WindowsWindow.c | 2 |
2 files changed, 54 insertions, 3 deletions
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index f52d3b1bb..1c1aecc47 100755 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -36,6 +36,42 @@ #import "KeyEvent.h" #import "MouseEvent.h" +jint GetDeltaY(NSEvent *event, jint javaMods) { + CGFloat deltaY = 0.0; + CGEventRef cgEvent = [event CGEvent]; + + if (CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventIsContinuous)) { + // mouse pad case + deltaY = + CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1); + } else { + // traditional mouse wheel case + deltaY = [event 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) { + deltaY *= 10.0; + } else { + if (deltaY < 0.0) { + deltaY = deltaY - 0.5f; + } else { + deltaY = deltaY + 0.5f; + } + } + } + + if (deltaY > 0) { + return (NSInteger)deltaY; + } else if (deltaY < 0) { + return -(NSInteger)deltaY; + } + + return 0; +} + @implementation NewtView - (void) setJNIEnv: (JNIEnv*) theEnv { @@ -225,8 +261,14 @@ static jint mods2JavaMods(NSUInteger mods) curLocation.y - frameRect.origin.y); // convert to 1-based button number (or use zero if no button is involved) - jint javaButtonNum; + // TODO: detect mouse button when mouse wheel scrolled + jint javaButtonNum = 0; + jint scrollDeltaY = 0; switch ([event type]) { + case NSScrollWheel: { + scrollDeltaY = GetDeltaY(event, javaMods); + break; + } case NSLeftMouseDown: case NSLeftMouseUp: case NSLeftMouseDragged: @@ -247,11 +289,15 @@ static jint mods2JavaMods(NSUInteger mods) break; } + if (evType == EVENT_MOUSE_WHEEL_MOVED && scrollDeltaY == 0) { + // ignore 0 increment wheel scroll events + return; + } (*env)->CallVoidMethod(env, javaWindowObject, sendMouseEventID, evType, javaMods, (jint) location.x, (jint) (contentRect.size.height - location.y), - javaButtonNum, 0); + javaButtonNum, scrollDeltaY); } - (void) mouseEntered: (NSEvent*) theEvent @@ -269,6 +315,11 @@ static jint mods2JavaMods(NSUInteger mods) [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; } +- (void) scrollWheel: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_WHEEL_MOVED]; +} + - (void) mouseDown: (NSEvent*) theEvent { [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_PRESSED]; diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 5628fac81..edc3f0796 100755 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -833,7 +833,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)); + (jint) 0, (jint) (GET_WHEEL_DELTA_WPARAM(wParam)/120.0f)); useDefWindowProc = 1; break; } |