diff --git a/Source/OpenTK/Platform/MacOS/Application.cs b/Source/OpenTK/Platform/MacOS/Application.cs index c419a079..a972f1c1 100644 --- a/Source/OpenTK/Platform/MacOS/Application.cs +++ b/Source/OpenTK/Platform/MacOS/Application.cs @@ -85,10 +85,26 @@ namespace OpenTK.Platform.MacOS.Carbon static void ConnectEvents() { - EventTypeSpec[] eventTypes = new EventTypeSpec[] { new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated), new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated), new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDown), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseUp), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseMoved), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDragged), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseEntered), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseExited), new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelMoved), + EventTypeSpec[] eventTypes = new EventTypeSpec[] { + new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated), + new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated), + new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDown), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseUp), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseMoved), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDragged), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseEntered), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseExited), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelMoved), + new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelScroll), - new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyDown), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged), new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent) }; + new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyDown), + new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat), + new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp), + new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged), + new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent), + }; MacOSEventHandler handler = EventHandler; uppHandler = API.NewEventHandlerUPP(handler); diff --git a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs index 3b96ae07..be079f95 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs @@ -246,6 +246,7 @@ namespace OpenTK.Platform.MacOS.Carbon MouseEntered = 8, MouseExited = 9, WheelMoved = 10, + WheelScroll = 11, } internal enum MouseButton : short { @@ -286,8 +287,11 @@ namespace OpenTK.Platform.MacOS.Carbon WindowMouseLocation = 0x776d6f75, // typeHIPoint MouseButton = 0x6d62746e, // typeMouseButton ClickCount = 0x63636e74, // typeUInt32 - MouseWheelAxis = 0x6d776178, // typeMouseWheelAxis - MouseWheelDelta = 0x6d77646c, // typeSInt32 + MouseWheelAxis = 0x6d776178, // typeMouseWheelAxis 'mwax' + MouseWheelDelta = 0x6d77646c, // typeSInt32 'mwdl' + MouseWheelSmoothVerticalDelta = 0x73617879, // typeSInt32 'saxy' + MouseWheelSmoothHorizontalDelta = 0x73617878, // typeSInt32 'saxx' + MouseDelta = 0x6d647461, // typeHIPoint // Keyboard events @@ -712,6 +716,52 @@ namespace OpenTK.Platform.MacOS.Carbon return (MouseButton)button; } + + internal struct ScrollDelta { + internal float deltaX; + internal float deltaY; + } + + static internal ScrollDelta GetEventWheelScroll(IntPtr inEvent) + { + ScrollDelta scrolldelta = new ScrollDelta(); + Int32 delta; + + unsafe + { + Int32* d = δ + OSStatus result; + + // vertical scroll Delta in pixels + result = API.GetEventParameter(inEvent, + EventParamName.MouseWheelSmoothVerticalDelta, EventParamType.typeSInt32, + IntPtr.Zero, (uint)sizeof(int), IntPtr.Zero, (IntPtr)d); + + if (result == OSStatus.EventParameterNotFound) { + // it's okay for it to be simply missing... + } else if (result != OSStatus.NoError) { + throw new MacOSException(result); + } else { + scrolldelta.deltaY = delta / 20.0f; + } + + // horizontal scroll Delta in pixels + result = API.GetEventParameter(inEvent, + EventParamName.MouseWheelSmoothHorizontalDelta, EventParamType.typeSInt32, + IntPtr.Zero, (uint)sizeof(int), IntPtr.Zero, (IntPtr)d); + + if (result == OSStatus.EventParameterNotFound) { + // it's okay for it to be simply missing... + } else if (result != OSStatus.NoError) { + throw new MacOSException(result); + } else { + scrolldelta.deltaY = delta / 20.0f; + } + } + + return scrolldelta; + } + static internal int GetEventMouseWheelDelta(IntPtr inEvent) { int delta; diff --git a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs index 742847f9..1b59b727 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -510,9 +510,19 @@ namespace OpenTK.Platform.MacOS } return OSStatus.NoError; - case MouseEventKind.WheelMoved: - float delta = API.GetEventMouseWheelDelta(inEvent); - InputDriver.Mouse[0].WheelPrecise += delta; + case MouseEventKind.WheelMoved: // older, integer resolution only + { + // this is really an int, we use a float to avoid clipping the wheel value + float delta = API.GetEventMouseWheelDelta (inEvent); + InputDriver.Mouse[0].WheelPrecise += delta; + } + return OSStatus.NoError; + + case MouseEventKind.WheelScroll: // newer, more precise X and Y scroll + { + API.ScrollDelta delta = API.GetEventWheelScroll(inEvent); + InputDriver.Mouse[0].WheelPrecise += delta.deltaY; + } return OSStatus.NoError; case MouseEventKind.MouseMoved: