Implemented SetPosition in terms of CGWarpMouseCursorPosition.

Added constructors to HIPoint.
This commit is contained in:
the_fiddler 2010-11-25 00:30:16 +00:00
parent 5caf6204de
commit 1a3df17dff
3 changed files with 31 additions and 3 deletions

View file

@ -99,6 +99,14 @@ namespace OpenTK.Platform.MacOS.Carbon
{ {
public float X; public float X;
public float Y; public float Y;
public HIPoint(float x, float y)
{
X = x;
Y = y;
}
public HIPoint(double x, double y)
: this((float)x, (float)y)
{ }
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct HISize internal struct HISize

View file

@ -12,6 +12,21 @@ namespace OpenTK.Platform.MacOS.Carbon
} }
enum CGError
{
Success = 0,
Failure = 1000,
IllegalArgument = 1001,
InvalidConnection = 1002,
InvalidContext = 1003,
CannotComplete = 1004,
NotImplemented = 1006,
RangeCheck = 1007,
TypeCheck = 1008,
InvalidOperation = 1010,
NoneAvailable = 1011,
}
internal static class CG internal static class CG
{ {
const string appServices = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices"; const string appServices = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices";
@ -50,5 +65,7 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(appServices, EntryPoint = "CGDisplaySwitchToMode")] [DllImport(appServices, EntryPoint = "CGDisplaySwitchToMode")]
internal static extern IntPtr DisplaySwitchToMode(IntPtr display, IntPtr displayMode); internal static extern IntPtr DisplaySwitchToMode(IntPtr display, IntPtr displayMode);
[DllImport(appServices, EntryPoint = "CGWarpMouseCursorPosition")]
internal static extern CGError WarpMouseCursorPosition(HIPoint newCursorPosition);
} }
} }

View file

@ -48,6 +48,8 @@ namespace OpenTK.Platform.MacOS
using IOOptionBits = System.IntPtr; using IOOptionBits = System.IntPtr;
using IOReturn = System.IntPtr; using IOReturn = System.IntPtr;
// Requires Mac OS X 10.5 or higher.
// Todo: create a driver for older installations. Maybe use CGGetLastMouseDelta for that?
class HIDInput : IMouseDriver2 class HIDInput : IMouseDriver2
{ {
#region Fields #region Fields
@ -195,7 +197,7 @@ namespace OpenTK.Platform.MacOS
#region IMouseDriver2 Members #region IMouseDriver2 Members
public MouseState GetState() MouseState IMouseDriver2.GetState()
{ {
MouseState master = new MouseState(); MouseState master = new MouseState();
foreach (KeyValuePair<IntPtr, MouseState> item in MouseDevices) foreach (KeyValuePair<IntPtr, MouseState> item in MouseDevices)
@ -206,7 +208,7 @@ namespace OpenTK.Platform.MacOS
return master; return master;
} }
public MouseState GetState(int index) MouseState IMouseDriver2.GetState(int index)
{ {
IntPtr device; IntPtr device;
if (MouseIndexToDevice.TryGetValue(index, out device)) if (MouseIndexToDevice.TryGetValue(index, out device))
@ -217,8 +219,9 @@ namespace OpenTK.Platform.MacOS
return new MouseState(); return new MouseState();
} }
public void SetPosition(double x, double y) void IMouseDriver2.SetPosition(double x, double y)
{ {
CG.WarpMouseCursorPosition(new Carbon.HIPoint(x, y));
} }
#endregion #endregion