Fix macos x64 wrong mouse input
authorVperus <vperus@Vperuss-iMac.local>
Tue, 6 Jun 2017 21:05:06 +0000 (00:05 +0300)
committerVlad K <vperus@gmail.com>
Tue, 13 Jun 2017 02:30:49 +0000 (05:30 +0300)
src/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs
src/OpenTK/Platform/MacOS/Cocoa/NSFloat.cs

index b2b9d28..03c494d 100644 (file)
@@ -160,7 +160,32 @@ namespace OpenTK.Platform.MacOS
         // Not the _stret version, perhaps because a NSPoint fits in one register?
         // thefiddler: gcc is indeed using objc_msgSend for NSPoint on i386
         [DllImport (LibObjC, EntryPoint="objc_msgSend")]
-        public extern static NSPoint SendPoint(IntPtr receiver, IntPtr selector);
+        public extern static NSPointF SendPointF(IntPtr receiver, IntPtr selector);
+        [DllImport (LibObjC, EntryPoint="objc_msgSend")]
+        public extern static NSPointD SendPointD(IntPtr receiver, IntPtr selector);
+
+        public static NSPoint SendPoint(IntPtr receiver, IntPtr selector)
+        {
+            NSPoint r = new NSPoint();
+
+            unsafe
+            {
+                if (IntPtr.Size == 4)
+                {
+                    NSPointF pf = SendPointF(receiver, selector);
+                    r.X.Value = *(IntPtr *)&pf.x;
+                    r.Y.Value = *(IntPtr *)&pf.y;
+                }
+                else
+                {
+                    NSPointD pd = SendPointD(receiver, selector);
+                    r.X.Value = *(IntPtr *)&pd.x;
+                    r.Y.Value = *(IntPtr *)&pd.y;
+                }
+            }
+
+            return r;
+        }
 
         [DllImport (LibObjC, EntryPoint="objc_msgSend_stret")]
         extern static void SendRect(out NSRect retval, IntPtr receiver, IntPtr selector);
index 09c7fa3..899ecc3 100644 (file)
@@ -45,6 +45,18 @@ namespace OpenTK.Platform.MacOS
     {
         IntPtr value;
 
+        public IntPtr Value
+        {
+            get
+            {
+                return value;
+            }
+            set
+            {
+                this.value = value;
+            }
+        }
+
         public static implicit operator NSFloat(float v)
         {
             NSFloat f;
@@ -179,5 +191,17 @@ namespace OpenTK.Platform.MacOS
             return new RectangleF(s.Location, s.Size);
         } 
     }
-}
 
+    // Using IntPtr in NSFloat cause that if imported function
+    // return struct that consist of them you will get wrong data 
+    // This types are used for such function.
+    public struct NSPointF
+    {
+        public float x, y;
+    }
+
+    public struct NSPointD
+    {
+        public double x, y;
+    }
+}