diff options
author | Sven Gothel <[email protected]> | 2013-01-14 05:58:21 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-01-14 05:58:21 +0100 |
commit | da14d647581751f3d2f6d651741eaec485e255b5 (patch) | |
tree | e8d228fa27ca2ccf5820abcd7c49a9f054377ae9 /src/newt/native/NewtMacWindow.m | |
parent | 955a444939ba67c6077b6937e191719aa184dafe (diff) |
NEWT-MouseEvent getWheelRotation() API Update - Fixes Bug 659: NEWT Horizontal Scrolling Behavior (OSX, X11, Win32); Bug 639: High-Res Mouse-Wheel
- API update 'float getWheelRotation()':
Usually a wheel rotation of > 0.0f is up, and < 0.0f is down.
Usually a wheel rotations is considered a vertical scroll.
If isShiftDown(), a wheel rotations is considered a horizontal scroll,
where shift-up = left = > 0.0f, and shift-down = right = < 0.0f.
However, on some OS this might be flipped due to the OS default behavior.
The latter is true for OS X 10.7 (Lion) for example.
The events will be send usually in steps of one, ie. -1.0f and 1.0f.
Higher values may result due to fast scrolling.
Fractional values may result due to slow scrolling with high resolution devices.
The button number refers to the wheel number.
- Fix Bug 659: NEWT Horizontal Scrolling Behavior (OSX, X11, Win32)
- See new API doc above
- X11/Horiz: Keep using button1 and set SHIFT modifier
- OSX/Horiz:
- PAD: Use highes absolute scrolling value (Axis1/Axis2)
and set SHIFT modifier for horizontal scrolling (Axis2)
- XXX: Use deltaX for horizontal scrolling, detected by SHIFT modifier. (traditional)
- Windows/Horiz:
- Add WM_MOUSEHWHEEL support (-> set SHIFT modifier), but it's rarely impl. for trackpads!
- Add exp. WM_HSCROLL, but it will only be delivered if windows has WS_HSCROLL, hence dead code!
- Android:
- Add ACTION_SCROLL (API Level 12), only used if layout is a scroll layout
- Using GestureDetector to detect scroll even w/ pointerCount > 2, while:
- skipping 1st scroll event (value too high)
- skipping other events while in-scroll mode
- waiting until all pointers were released before cont. normally
- using View config's 1/touchSlope as scale factor
- Fix Bug 639: High-Res Mouse-Wheel
- getWheelRotation() return value changed: int -> float
allowing fractions, see API doc changes above.
- Fractions are currently supported natively (API) on
- Windows
- OSX
- Android
- AndroidNewtEventFactory ir refactored (requires an instance now) and
AndroidNewtEventTranslator (event listener) is pulled our of Android WindowDriver.
Diffstat (limited to 'src/newt/native/NewtMacWindow.m')
-rw-r--r-- | src/newt/native/NewtMacWindow.m | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index b89b5c21d..5b826566b 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -36,36 +36,49 @@ #import "KeyEvent.h" #import "MouseEvent.h" -jint GetDeltaY(NSEvent *event, jint javaMods) { - CGFloat deltaY = 0.0; +#include <math.h> + +static jfloat GetDelta(NSEvent *event, jint javaMods[]) { CGEventRef cgEvent = [event CGEvent]; + CGFloat deltaY = 0.0; + CGFloat deltaX = 0.0; + CGFloat delta = 0.0; if (CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventIsContinuous)) { // mouse pad case - deltaY = - CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1); - // fprintf(stderr, "WHEEL/PAD: %lf\n", (double)deltaY); + deltaX = CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis2); + deltaY = CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1); + // fprintf(stderr, "WHEEL/PAD: %lf/%lf - 0x%X\n", (double)deltaX, (double)deltaY, javaMods[0]); + if( fabsf(deltaX) > fabsf(deltaY) ) { + javaMods[0] |= EVENT_SHIFT_MASK; + delta = deltaX; + } else { + delta = deltaY; + } } else { // traditional mouse wheel case + deltaX = [event deltaX]; deltaY = [event deltaY]; - // fprintf(stderr, "WHEEL/TRAD: %lf\n", (double)deltaY); - if (deltaY == 0.0 && (javaMods & EVENT_SHIFT_MASK) != 0) { + // fprintf(stderr, "WHEEL/TRACK: %lf/%lf - 0x%X\n", (double)deltaX, (double)deltaY, javaMods[0]); + if (deltaY == 0.0 && (javaMods[0] & EVENT_SHIFT_MASK) != 0) { // shift+vertical wheel scroll produces horizontal scroll // we convert it to vertical - deltaY = [event deltaX]; + delta = deltaX; + } else { + delta = deltaY; } - if (-1.0 < deltaY && deltaY < 1.0) { - deltaY *= 10.0; + if (-1.0 < delta && delta < 1.0) { + delta *= 10.0; } else { - if (deltaY < 0.0) { - deltaY = deltaY - 0.5f; + if (delta < 0.0) { + delta = delta - 0.5f; } else { - deltaY = deltaY + 0.5f; + delta = delta + 0.5f; } } } - // fprintf(stderr, "WHEEL/res: %d\n", (int)deltaY); - return (jint) deltaY; + // fprintf(stderr, "WHEEL/RES: %lf - 0x%X\n", (double)delta, javaMods[0]); + return (jfloat) delta; } static jmethodID enqueueMouseEventID = NULL; @@ -328,8 +341,8 @@ static jmethodID windowRepaintID = NULL; + (BOOL) initNatives: (JNIEnv*) env forClass: (jclass) clazz { - enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZIIIIII)V"); - sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZIIIIIF)V"); + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIIF)V"); enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZIIIC)V"); sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); @@ -686,15 +699,16 @@ static jint mods2JavaMods(NSUInteger mods) DBG_PRINT("sendMouseEvent: null JNIEnv\n"); return; } - jint javaMods = mods2JavaMods([event modifierFlags]); + jint javaMods[] = { 0 } ; + javaMods[0] = mods2JavaMods([event modifierFlags]); // convert to 1-based button number (or use zero if no button is involved) // TODO: detect mouse button when mouse wheel scrolled jint javaButtonNum = 0; - jint scrollDeltaY = 0; + jfloat scrollDeltaY = 0.0f; switch ([event type]) { case NSScrollWheel: { - scrollDeltaY = GetDeltaY(event, javaMods); + scrollDeltaY = GetDelta(event, javaMods); javaButtonNum = 1; break; } @@ -727,12 +741,12 @@ static jint mods2JavaMods(NSUInteger mods) #ifdef USE_SENDIO_DIRECT (*env)->CallVoidMethod(env, javaWindowObject, sendMouseEventID, - evType, javaMods, + evType, javaMods[0], (jint) location.x, (jint) location.y, javaButtonNum, scrollDeltaY); #else (*env)->CallVoidMethod(env, javaWindowObject, enqueueMouseEventID, JNI_FALSE, - evType, javaMods, + evType, javaMods[0], (jint) location.x, (jint) location.y, javaButtonNum, scrollDeltaY); #endif |