diff --git a/OpenTK/GameWindow.cs b/OpenTK/GameWindow.cs
index 9afdcfa71..f0ce00fb3 100644
--- a/OpenTK/GameWindow.cs
+++ b/OpenTK/GameWindow.cs
@@ -474,7 +474,7 @@ namespace OpenTK
///
public KeyboardDevice Keyboard
{
- get { return InputDriver.Keyboard.Count > 0 ? InputDriver.Keyboard[0] : null; }
+ get { return InputDriver.Keyboard; }
}
#endregion
@@ -484,9 +484,8 @@ namespace OpenTK
///
/// Gets the primary Mouse device, or null if no Mouse exists.
///
- public MouseDevice Mouse
- {
- get { return InputDriver.Mouse.Count > 0 ? InputDriver.Mouse[0] : null; }
+ public MouseDevice Mouse {
+ get { return InputDriver.Mouse; }
}
#endregion
diff --git a/OpenTK/Input/Interfaces.cs b/OpenTK/Input/Interfaces.cs
index b43d09940..23752e58a 100644
--- a/OpenTK/Input/Interfaces.cs
+++ b/OpenTK/Input/Interfaces.cs
@@ -12,9 +12,6 @@ namespace OpenTK.Input {
/// Defines a common interface for all input devices.
public interface IInputDevice {
-
- /// Gets a System.String with a unique description of this IInputDevice instance.
- string Description { get; }
/// Gets an OpenTK.Input.InputDeviceType value, representing the device type of this IInputDevice instance.
InputDeviceType DeviceType { get; }
@@ -32,10 +29,18 @@ namespace OpenTK.Input {
}
/// Defines the interface for an input driver.
- public interface IInputDriver : IKeyboardDriver, IMouseDriver, IJoystickDriver, IDisposable {
-
+ public interface IInputDriver : IJoystickDriver, IDisposable {
+
+ /// Gets the list of available KeyboardDevices.
+ KeyboardDevice Keyboard { get; }
+
+ /// Gets the list of available MouseDevices.
+ MouseDevice Mouse { get; }
+
/// Updates the state of the driver.
void Poll();
+
+ Point DesktopCursorPos { get; set; }
}
/// Defines the interface for JoystickDevice drivers.
@@ -44,20 +49,4 @@ namespace OpenTK.Input {
/// Gets the list of available JoystickDevices.
IList Joysticks { get; }
}
-
- /// Defines the interface for KeyboardDevice drivers.
- public interface IKeyboardDriver {
-
- /// Gets the list of available KeyboardDevices.
- IList Keyboard { get; }
- }
-
- /// Defines the interface for MouseDevice drivers.
- public interface IMouseDriver {
-
- /// Gets the list of available MouseDevices.
- IList Mouse { get; }
-
- Point DesktopCursorPos { get; set; }
- }
}
diff --git a/OpenTK/Input/Key.cs b/OpenTK/Input/Key.cs
index 2f6bc5130..8cff94917 100644
--- a/OpenTK/Input/Key.cs
+++ b/OpenTK/Input/Key.cs
@@ -27,9 +27,7 @@
namespace OpenTK.Input
{
- ///
- /// The available keyboard keys.
- ///
+ /// The available keyboard keys.
public enum Key : int
{
/// A key outside the known keys.
diff --git a/OpenTK/Input/KeyboardDevice.cs b/OpenTK/Input/KeyboardDevice.cs
index e7e54c79e..f488fd79e 100644
--- a/OpenTK/Input/KeyboardDevice.cs
+++ b/OpenTK/Input/KeyboardDevice.cs
@@ -13,11 +13,7 @@ namespace OpenTK.Input
///
public sealed class KeyboardDevice : IInputDevice
{
- //private IKeyboard keyboard;
private bool[] keys = new bool[(int)Key.LastKey];
- private string description;
- private int numKeys, numFKeys, numLeds;
- private IntPtr devID;
private bool repeat;
private KeyboardKeyEventArgs args = new KeyboardKeyEventArgs();
@@ -57,42 +53,6 @@ namespace OpenTK.Input
}
}
- ///
- /// Gets an integer representing the number of keys on this KeyboardDevice.
- ///
- public int NumberOfKeys
- {
- get { return numKeys; }
- internal set { numKeys = value; }
- }
-
- ///
- /// Gets an integer representing the number of function keys (F-keys) on this KeyboardDevice.
- ///
- public int NumberOfFunctionKeys
- {
- get { return numFKeys; }
- internal set { numFKeys = value; }
- }
-
- ///
- /// Gets a value indicating the number of led indicators on this KeyboardDevice.
- ///
- public int NumberOfLeds
- {
- get { return numLeds; }
- internal set { numLeds = value; }
- }
-
- ///
- /// Gets an IntPtr representing a device dependent ID.
- ///
- public IntPtr DeviceID
- {
- get { return devID; }
- internal set { devID = value; }
- }
-
#region public bool KeyRepeat
///
@@ -138,51 +98,11 @@ namespace OpenTK.Input
#endregion
#endregion
-
- #region --- IInputDevice Members ---
-
- ///
- /// Gets a which describes this instance.
- ///
- public string Description
- {
- get { return description; }
- internal set { description = value; }
- }
-
- ///
- /// Gets the for this instance.
- ///
- public InputDeviceType DeviceType
- {
+
+ public InputDeviceType DeviceType {
get { return InputDeviceType.Keyboard; }
}
- #endregion
-
- #region --- Public Methods ---
-
- /// Returns the hash code for this KeyboardDevice.
- /// A 32-bit signed integer hash code.
- public override int GetHashCode()
- {
- //return base.GetHashCode();
- return (int)(numKeys ^ numFKeys ^ numLeds ^ devID.GetHashCode() ^ description.GetHashCode());
- }
-
- ///
- /// Returns a System.String representing this KeyboardDevice.
- ///
- /// A System.String representing this KeyboardDevice.
- public override string ToString()
- {
- //return base.ToString();
- return String.Format("ID: {0} ({1}). Keys: {2}, Function keys: {3}, Leds: {4}",
- DeviceID, Description, NumberOfKeys, NumberOfFunctionKeys, NumberOfLeds);
- }
-
- #endregion
-
#region --- Internal Methods ---
#region internal void ClearKeys()
diff --git a/OpenTK/Input/MouseDevice.cs b/OpenTK/Input/MouseDevice.cs
index bbd79fc21..e611d46a5 100644
--- a/OpenTK/Input/MouseDevice.cs
+++ b/OpenTK/Input/MouseDevice.cs
@@ -35,90 +35,19 @@ namespace OpenTK.Input
///
public sealed class MouseDevice : IInputDevice
{
- #region --- Fields ---
-
- string description;
- IntPtr id;
- int numButtons, numWheels;
readonly bool[] button_state = new bool[(int)MouseButton.LastButton];
float wheel, last_wheel;
- Point pos = new Point(), last_pos = new Point();
+ Point pos, last_pos;
MouseMoveEventArgs move_args = new MouseMoveEventArgs();
MouseButtonEventArgs button_args = new MouseButtonEventArgs();
MouseWheelEventArgs wheel_args = new MouseWheelEventArgs();
- #endregion
-
- #region --- IInputDevice Members ---
-
- #region public string Description
-
- ///
- /// Gets a string describing this MouseDevice.
- ///
- public string Description
- {
- get { return description; }
- internal set { description = value; }
- }
-
- #endregion
-
- #region public InputDeviceType DeviceType
-
- ///
- /// Gets a value indicating the InputDeviceType of this InputDevice.
- ///
- public InputDeviceType DeviceType
- {
+ public InputDeviceType DeviceType {
get { return InputDeviceType.Mouse; }
}
- #endregion
-
- #endregion
-
#region --- Public Members ---
- #region public int NumberOfButtons
-
- ///
- /// Gets an integer representing the number of buttons on this MouseDevice.
- ///
- public int NumberOfButtons
- {
- get { return numButtons; }
- internal set { numButtons = value; }
- }
-
- #endregion
-
- #region public int NumberOfWheels
-
- ///
- /// Gets an integer representing the number of wheels on this MouseDevice.
- ///
- public int NumberOfWheels
- {
- get { return numWheels; }
- internal set { numWheels = value; }
- }
-
- #endregion
-
- #region public IntPtr DeviceID
-
- ///
- /// Gets an IntPtr representing a device dependent ID.
- ///
- public IntPtr DeviceID
- {
- get { return id; }
- internal set { id = value; }
- }
-
- #endregion
-
#region public int Wheel
///
@@ -257,30 +186,7 @@ namespace OpenTK.Input
/// Occurs when one of the mouse wheels is moved.
///
public event EventHandler WheelChanged = delegate { };
-
- #region --- Overrides ---
-
- ///
- /// Calculates the hash code for this instance.
- ///
- ///
- public override int GetHashCode()
- {
- return (int)(numButtons ^ numWheels ^ id.GetHashCode() ^ description.GetHashCode());
- }
-
- ///
- /// Returns a that describes this instance.
- ///
- /// A that describes this instance.
- public override string ToString()
- {
- return String.Format("ID: {0} ({1}). Buttons: {2}, Wheels: {3}",
- DeviceID, Description, NumberOfButtons, NumberOfWheels);
- }
-
- #endregion
-
+
#endregion
}
diff --git a/OpenTK/OpenTK.csproj b/OpenTK/OpenTK.csproj
index 3157a5594..976f2b725 100644
--- a/OpenTK/OpenTK.csproj
+++ b/OpenTK/OpenTK.csproj
@@ -93,7 +93,6 @@
-
diff --git a/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs b/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs
index 6771e2342..1592366b4 100644
--- a/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs
+++ b/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs
@@ -209,7 +209,7 @@ namespace OpenTK.Platform.MacOS.Carbon
MouseExited = 9,
WheelMoved = 10,
}
- internal enum MouseButton : short
+ internal enum MacOSMouseButton : short
{
Primary = 1,
Secondary = 2,
@@ -586,190 +586,110 @@ namespace OpenTK.Platform.MacOS.Carbon
#endregion
#region --- Getting Event Parameters ---
- [DllImport(carbon,EntryPoint="CreateEvent")]
- static extern OSStatus _CreateEvent( IntPtr inAllocator,
+ [DllImport(carbon)]
+ static extern OSStatus CreateEvent( IntPtr inAllocator,
EventClass inClassID, UInt32 kind, EventTime when,
- EventAttributes flags,out IntPtr outEvent);
-
- internal static IntPtr CreateWindowEvent(WindowEventKind kind)
- {
+ EventAttributes flags, out IntPtr outEvent);
+
+ internal static IntPtr CreateWindowEvent(WindowEventKind kind) {
IntPtr retval;
-
- OSStatus stat = _CreateEvent(IntPtr.Zero, EventClass.Window, (uint)kind,
- 0, EventAttributes.kEventAttributeNone, out retval);
+ OSStatus stat = CreateEvent(IntPtr.Zero, EventClass.Window, (uint)kind,
+ 0, EventAttributes.kEventAttributeNone, out retval);
if (stat != OSStatus.NoError)
- {
throw new MacOSException(stat);
- }
-
return retval;
}
- [DllImport(carbon)]
- static extern OSStatus GetEventParameter(
- IntPtr inEvent, EventParamName inName, EventParamType inDesiredType,
- IntPtr outActualType, uint inBufferSize, IntPtr outActualSize, IntPtr outData);
+ [DllImport(carbon)]
+ static extern OSStatus GetEventParameter(
+ IntPtr inEvent, EventParamName inName, EventParamType inDesiredType,
+ IntPtr outActualType, int inBufferSize, IntPtr outActualSize, IntPtr outData);
- static internal MacOSKeyCode GetEventKeyboardKeyCode(IntPtr inEvent)
- {
- int code;
+ internal unsafe static MacOSKeyCode GetEventKeyboardKeyCode(IntPtr inEvent) {
+ int code;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.KeyCode, EventParamType.typeUInt32, IntPtr.Zero,
+ sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
- unsafe
- {
- int* codeAddr = &code;
+ if (result != OSStatus.NoError)
+ throw new MacOSException(result);
+ return (MacOSKeyCode)code;
+ }
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.KeyCode, EventParamType.typeUInt32, IntPtr.Zero,
- (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(UInt32)), IntPtr.Zero,
- (IntPtr) codeAddr);
+ internal unsafe static char GetEventKeyboardChar(IntPtr inEvent) {
+ char code;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.KeyMacCharCode, EventParamType.typeChar, IntPtr.Zero,
+ Marshal.SizeOf(typeof(char)), IntPtr.Zero, (IntPtr)(void*)&code);
- if (result != OSStatus.NoError)
- {
- throw new MacOSException(result);
- }
- }
+ if (result != OSStatus.NoError)
+ throw new MacOSException(result);
+ return code;
+ }
- return (MacOSKeyCode)code;
- }
+ internal unsafe static MacOSMouseButton GetEventMouseButton(IntPtr inEvent) {
+ int button;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.MouseButton, EventParamType.typeMouseButton, IntPtr.Zero,
+ sizeof(short), IntPtr.Zero, (IntPtr)(void*)&button);
- internal static char GetEventKeyboardChar(IntPtr inEvent)
- {
- char code;
-
- unsafe
- {
- char* codeAddr = &code;
-
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.KeyMacCharCode, EventParamType.typeChar, IntPtr.Zero,
- (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(char)), IntPtr.Zero,
- (IntPtr)codeAddr);
-
- if (result != OSStatus.NoError)
- {
- throw new MacOSException(result);
- }
- }
-
- return code;
- }
-
- static internal MouseButton GetEventMouseButton(IntPtr inEvent)
- {
- int button;
-
- unsafe
- {
- int* btn = &button;
-
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.MouseButton, EventParamType.typeMouseButton, IntPtr.Zero,
- (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(short)), IntPtr.Zero,
- (IntPtr)btn);
-
- if (result != OSStatus.NoError)
- throw new MacOSException(result);
- }
-
- return (MouseButton)button;
- }
- static internal int GetEventMouseWheelDelta(IntPtr inEvent)
- {
+ if (result != OSStatus.NoError)
+ throw new MacOSException(result);
+ return (MacOSMouseButton)button;
+ }
+
+ internal unsafe static int GetEventMouseWheelDelta(IntPtr inEvent) {
int delta;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.MouseWheelDelta, EventParamType.typeSInt32,
+ IntPtr.Zero, sizeof(int), IntPtr.Zero, (IntPtr)(void*)&delta);
- unsafe
- {
- int* d = δ
-
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.MouseWheelDelta, EventParamType.typeSInt32,
- IntPtr.Zero, (uint)sizeof(int), IntPtr.Zero, (IntPtr)d);
-
- if (result != OSStatus.NoError)
- throw new MacOSException(result);
- }
-
+ if (result != OSStatus.NoError)
+ throw new MacOSException(result);
return delta;
}
- static internal OSStatus GetEventWindowMouseLocation(IntPtr inEvent, out HIPoint pt)
- {
- HIPoint point;
+ internal unsafe static OSStatus GetEventWindowMouseLocation(IntPtr inEvent, out HIPoint pt) {
+ HIPoint point;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
+ Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
- unsafe
- {
- HIPoint* parm = &point;
-
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
- (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero,
- (IntPtr)parm);
-
- pt = point;
-
- return result;
- }
-
- }
-
- static internal OSStatus GetEventWindowRef(IntPtr inEvent, out IntPtr windowRef)
- {
- IntPtr retval;
-
- unsafe
- {
- IntPtr* parm = &retval;
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.WindowRef, EventParamType.typeWindowRef, IntPtr.Zero,
- (uint)sizeof(IntPtr), IntPtr.Zero, (IntPtr)parm);
-
- windowRef = retval;
-
- return result;
- }
+ pt = point;
+ return result;
}
- static internal OSStatus GetEventMouseLocation(IntPtr inEvent, out HIPoint pt)
- {
- HIPoint point;
+ internal unsafe static OSStatus GetEventWindowRef(IntPtr inEvent, out IntPtr windowRef) {
+ IntPtr retval;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.WindowRef, EventParamType.typeWindowRef, IntPtr.Zero,
+ sizeof(IntPtr), IntPtr.Zero, (IntPtr)(void*)&retval);
- unsafe
- {
- HIPoint* parm = &point;
+ windowRef = retval;
+ return result;
+ }
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.MouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
- (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero,
- (IntPtr)parm);
+ internal unsafe static OSStatus GetEventMouseLocation(IntPtr inEvent, out HIPoint pt) {
+ HIPoint point;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.MouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
+ Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
- pt = point;
+ pt = point;
+ return result;
+ }
+
+ internal unsafe static MacOSKeyModifiers GetEventKeyModifiers(IntPtr inEvent) {
+ uint code;
+ OSStatus result = API.GetEventParameter(inEvent,
+ EventParamName.KeyModifiers, EventParamType.typeUInt32, IntPtr.Zero,
+ sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
- return result;
- }
-
- }
- static internal MacOSKeyModifiers GetEventKeyModifiers(IntPtr inEvent)
- {
- uint code;
-
- unsafe
- {
- uint* codeAddr = &code;
-
- OSStatus result = API.GetEventParameter(inEvent,
- EventParamName.KeyModifiers, EventParamType.typeUInt32, IntPtr.Zero,
- (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(uint)), IntPtr.Zero,
- (IntPtr)codeAddr);
-
- if (result != OSStatus.NoError)
- {
- throw new MacOSException(result);
- }
- }
-
- return (MacOSKeyModifiers)code;
- }
+ if (result != OSStatus.NoError)
+ throw new MacOSException(result);
+ return (MacOSKeyModifiers)code;
+ }
#endregion
#region --- Event Handlers ---
diff --git a/OpenTK/Platform/MacOS/CarbonGLNative.cs b/OpenTK/Platform/MacOS/CarbonGLNative.cs
index 7d67468cc..296f1d281 100644
--- a/OpenTK/Platform/MacOS/CarbonGLNative.cs
+++ b/OpenTK/Platform/MacOS/CarbonGLNative.cs
@@ -32,18 +32,16 @@ using System.Diagnostics;
using System.Drawing;
using OpenTK.Graphics;
using OpenTK.Platform.MacOS.Carbon;
+using OpenTK.Input;
namespace OpenTK.Platform.MacOS
{
- class CarbonGLNative : INativeWindow
+ class CarbonGLNative : INativeWindow, IInputDriver
{
#region Fields
CarbonWindowInfo window;
- CarbonInput mInputDriver;
-
static MacOSKeyMap Keymap = new MacOSKeyMap();
-
IntPtr uppHandler;
string title = "OpenTK Window";
@@ -108,6 +106,7 @@ namespace OpenTK.Platform.MacOS
new Rect((short)x, (short)y, (short)width, (short)height));
mDisplayDevice = device;
+ dummy_joystick_list.Add(new JoystickDevice