diff options
author | trembovetski <[email protected]> | 2009-08-25 15:10:17 -0700 |
---|---|---|
committer | trembovetski <[email protected]> | 2009-08-25 15:10:17 -0700 |
commit | 2e550f9fe080de8ecf23059a38e77b13669805b5 (patch) | |
tree | a2066d379bb1c15258875c525eb18525bdea1bc1 | |
parent | 29b675c229e3d797f2c454803e289765b0bc801c (diff) |
newt: mac os mouse wheel event support, also made it more consistent with windows
-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; } |