mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-04 05:08:16 +00:00
Merge pull request #17 from jeske/master
added support for smooth trackpad scrolling on macos
This commit is contained in:
commit
2b7d02bb61
|
@ -85,10 +85,26 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
static void ConnectEvents()
|
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;
|
MacOSEventHandler handler = EventHandler;
|
||||||
uppHandler = API.NewEventHandlerUPP(handler);
|
uppHandler = API.NewEventHandlerUPP(handler);
|
||||||
|
|
|
@ -246,6 +246,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
MouseEntered = 8,
|
MouseEntered = 8,
|
||||||
MouseExited = 9,
|
MouseExited = 9,
|
||||||
WheelMoved = 10,
|
WheelMoved = 10,
|
||||||
|
WheelScroll = 11,
|
||||||
}
|
}
|
||||||
internal enum MouseButton : short
|
internal enum MouseButton : short
|
||||||
{
|
{
|
||||||
|
@ -286,8 +287,11 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
WindowMouseLocation = 0x776d6f75, // typeHIPoint
|
WindowMouseLocation = 0x776d6f75, // typeHIPoint
|
||||||
MouseButton = 0x6d62746e, // typeMouseButton
|
MouseButton = 0x6d62746e, // typeMouseButton
|
||||||
ClickCount = 0x63636e74, // typeUInt32
|
ClickCount = 0x63636e74, // typeUInt32
|
||||||
MouseWheelAxis = 0x6d776178, // typeMouseWheelAxis
|
MouseWheelAxis = 0x6d776178, // typeMouseWheelAxis 'mwax'
|
||||||
MouseWheelDelta = 0x6d77646c, // typeSInt32
|
MouseWheelDelta = 0x6d77646c, // typeSInt32 'mwdl'
|
||||||
|
MouseWheelSmoothVerticalDelta = 0x73617879, // typeSInt32 'saxy'
|
||||||
|
MouseWheelSmoothHorizontalDelta = 0x73617878, // typeSInt32 'saxx'
|
||||||
|
|
||||||
MouseDelta = 0x6d647461, // typeHIPoint
|
MouseDelta = 0x6d647461, // typeHIPoint
|
||||||
|
|
||||||
// Keyboard events
|
// Keyboard events
|
||||||
|
@ -712,6 +716,52 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
|
|
||||||
return (MouseButton)button;
|
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)
|
static internal int GetEventMouseWheelDelta(IntPtr inEvent)
|
||||||
{
|
{
|
||||||
int delta;
|
int delta;
|
||||||
|
|
|
@ -510,9 +510,19 @@ namespace OpenTK.Platform.MacOS
|
||||||
}
|
}
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
case MouseEventKind.WheelMoved:
|
case MouseEventKind.WheelMoved: // older, integer resolution only
|
||||||
float delta = API.GetEventMouseWheelDelta(inEvent);
|
{
|
||||||
InputDriver.Mouse[0].WheelPrecise += delta;
|
// 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;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
case MouseEventKind.MouseMoved:
|
case MouseEventKind.MouseMoved:
|
||||||
|
|
Loading…
Reference in a new issue