Permalink
Browse files

Merge pull request #134 from thefiddler/scrollfix

[Mac][X11] Match win32 wheel coordinate system
  • Loading branch information...
2 parents b9e9485 + 8373782 commit bc555efd03a0602555ec682a0aabb175ad018560 @thefiddler thefiddler committed Jun 11, 2014
@@ -540,7 +540,10 @@ public override void ProcessEvents()
// Only raise wheel events when the user has actually scrolled
if (dx != 0 || dy != 0)
{
- OnMouseWheel(dx, dy);
+ // Note: OpenTK follows the win32 convention, where
+ // (+h, +v) = (right, up). MacOS reports (+h, +v) = (left, up)
+ // so we need to flip the horizontal scroll direction.
+ OnMouseWheel(-dx, dy);
}
}
break;
@@ -180,16 +180,22 @@ void RegisterMouseMonitor()
break;
case CGEventType.ScrollWheel:
- CursorState.SetScrollRelative(
- (float)CG.EventGetDoubleValueField(@event, CGEventField.ScrollWheelEventPointDeltaAxis2) * MacOSFactory.ScrollFactor,
- (float)CG.EventGetDoubleValueField(@event, CGEventField.ScrollWheelEventPointDeltaAxis1) * MacOSFactory.ScrollFactor);
+ {
+ // Note: OpenTK follows the win32 convention, where
+ // (+h, +v) = (right, up). MacOS reports (+h, +v) = (left, up)
+ // so we need to flip the horizontal scroll direction.
+ double h = CG.EventGetDoubleValueField(@event, CGEventField.ScrollWheelEventPointDeltaAxis2) * MacOSFactory.ScrollFactor;
+ double v = CG.EventGetDoubleValueField(@event, CGEventField.ScrollWheelEventPointDeltaAxis1) * MacOSFactory.ScrollFactor;
+ CursorState.SetScrollRelative((float)(-h), (float)v);
+ }
break;
case CGEventType.LeftMouseDown:
case CGEventType.RightMouseDown:
case CGEventType.OtherMouseDown:
{
int n = CG.EventGetIntegerValueField(@event, CGEventField.MouseEventButtonNumber);
+ n = n == 1 ? 2 : n == 2 ? 1 : n; // flip middle and right button numbers to match OpenTK
MouseButton b = MouseButton.Left + n;
CursorState[b] = true;
}
@@ -200,6 +206,7 @@ void RegisterMouseMonitor()
case CGEventType.OtherMouseUp:
{
int n = CG.EventGetIntegerValueField(@event, CGEventField.MouseEventButtonNumber);
+ n = n == 1 ? 2 : n == 2 ? 1 : n; // flip middle and right button numbers to match OpenTK
MouseButton b = MouseButton.Left + n;
CursorState[b] = false;
}
@@ -406,6 +413,11 @@ static void UpdateMouse(MouseData mouse, IOHIDValueRef val)
mouse.State.Y += v_int;
break;
+ case HIDUsageGD.Z:
+ // Horizontal scrolling for apple mouse (old-style with trackball)
+ mouse.State.SetScrollRelative(v_int, 0);
+ break;
+
case HIDUsageGD.Wheel:
mouse.State.SetScrollRelative(0, v_int);
break;
@@ -37,6 +37,9 @@ namespace OpenTK.Platform.MacOS
class MacOSFactory : PlatformFactoryBase
{
+ // Todo: we can query the exact amount via
+ // CGEventSourceGetPixelsPerLine. This is
+ // approximately 0.1f
internal const float ScrollFactor = 0.1f;
internal static bool ExclusiveFullscreen = false;
@@ -544,7 +544,11 @@ unsafe static void ProcessRawMotion(XIMouse d, ref XIRawEvent raw)
d.State.X += (int)Math.Round(x);
d.State.Y += (int)Math.Round(y);
- d.State.SetScrollRelative((float)h, (float)v);
+
+ // Note: OpenTK follows the windows scrolling convention where
+ // (+h, +v) = (right, up). XI2 uses (+h, +v) = (right, down)
+ // instead, so we need to flip the vertical offset.
+ d.State.SetScrollRelative((float)h, (float)(-v));
}
unsafe static double ReadRawValue(ref XIRawEvent raw, int bit)

0 comments on commit bc555ef

Please sign in to comment.