Change HIPoint to NSPoint, hipoint wasn't arch independent

This commit is contained in:
VPeruS 2017-06-08 22:25:59 +03:00 committed by Vlad K
parent 72320ad181
commit d13451d181
3 changed files with 38 additions and 5 deletions

View file

@ -273,7 +273,7 @@ namespace OpenTK.Platform.MacOS
case CGEventType.RightMouseDragged: case CGEventType.RightMouseDragged:
case CGEventType.OtherMouseDragged: case CGEventType.OtherMouseDragged:
{ {
Carbon.HIPoint p = CG.EventGetLocation(@event); NSPoint p = CG.EventGetLocation(@event);
CursorState.X = (int)Math.Round(p.X); CursorState.X = (int)Math.Round(p.X);
CursorState.Y = (int)Math.Round(p.Y); CursorState.Y = (int)Math.Round(p.Y);
} }
@ -1045,7 +1045,15 @@ namespace OpenTK.Platform.MacOS
void IMouseDriver2.SetPosition(double x, double y) void IMouseDriver2.SetPosition(double x, double y)
{ {
CG.SetLocalEventsSuppressionInterval(0.0); CG.SetLocalEventsSuppressionInterval(0.0);
CG.WarpMouseCursorPosition(new Carbon.HIPoint(x, y));
NSPoint p = new NSPoint();
unsafe
{
p.X.Value = *(IntPtr *)&x;
p.Y.Value = *(IntPtr *)&y;
}
CG.WarpMouseCursorPosition(p);
} }
#endregion #endregion

View file

@ -60,7 +60,7 @@ namespace OpenTK.Platform.MacOS
{ {
const string lib = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices"; const string lib = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices";
// CGPoint -> HIPoint // CGPoint -> NSPoint
// CGSize -> HISize // CGSize -> HISize
// CGRect -> HIRect // CGRect -> HIRect
@ -116,7 +116,7 @@ namespace OpenTK.Platform.MacOS
internal static extern IntPtr DisplaySwitchToMode(IntPtr display, IntPtr displayMode); internal static extern IntPtr DisplaySwitchToMode(IntPtr display, IntPtr displayMode);
[DllImport(lib, EntryPoint = "CGWarpMouseCursorPosition")] [DllImport(lib, EntryPoint = "CGWarpMouseCursorPosition")]
internal static extern CGError WarpMouseCursorPosition(HIPoint newCursorPosition); internal static extern CGError WarpMouseCursorPosition(NSPoint newCursorPosition);
[DllImport(lib, EntryPoint = "CGCursorIsVisible")] [DllImport(lib, EntryPoint = "CGCursorIsVisible")]
internal static extern bool CursorIsVisible(); internal static extern bool CursorIsVisible();

View file

@ -66,7 +66,32 @@ namespace OpenTK.Platform.MacOS
CGEventField field); CGEventField field);
[DllImport(lib, EntryPoint = "CGEventGetLocation")] [DllImport(lib, EntryPoint = "CGEventGetLocation")]
internal static extern Carbon.HIPoint EventGetLocation(CGEventRef @event); internal static extern NSPointF EventGetLocationF(CGEventRef @event);
[DllImport(lib, EntryPoint = "CGEventGetLocation")]
internal static extern NSPointD EventGetLocationD(CGEventRef @event);
internal static NSPoint EventGetLocation(CGEventRef @event)
{
NSPoint r = new NSPoint();
unsafe {
if (IntPtr.Size == 4)
{
NSPointF pf = EventGetLocationF(@event);
r.X.Value = *(IntPtr *)&pf.x;
r.Y.Value = *(IntPtr *)&pf.y;
}
else
{
NSPointD pd = EventGetLocationD(@event);
r.X.Value = *(IntPtr *)&pd.x;
r.Y.Value = *(IntPtr *)&pd.y;
}
}
return r;
}
} }
enum CGEventTapLocation enum CGEventTapLocation