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(0, 0, 0)); } #endregion @@ -196,8 +195,6 @@ namespace OpenTK.Platform.MacOS void ConnectEvents() { - mInputDriver = new CarbonInput(); - EventTypeSpec[] eventTypes = new EventTypeSpec[] { new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClose), @@ -369,17 +366,16 @@ namespace OpenTK.Platform.MacOS switch (evt.KeyboardEventKind) { case KeyboardEventKind.RawKeyRepeat: - InputDriver.Keyboard[0].KeyRepeat = true; + keyboard.KeyRepeat = true; goto case KeyboardEventKind.RawKeyDown; case KeyboardEventKind.RawKeyDown: OnKeyPress(mKeyPressArgs); - InputDriver.Keyboard[0][Keymap[code]] = true; + keyboard[Keymap[code]] = true; return OSStatus.NoError; case KeyboardEventKind.RawKeyUp: - InputDriver.Keyboard[0][Keymap[code]] = false; - + keyboard[Keymap[code]] = false; return OSStatus.NoError; case KeyboardEventKind.RawKeyModifiersChanged: @@ -441,8 +437,8 @@ namespace OpenTK.Platform.MacOS } protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) { - System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Mouse); - MouseButton button = MouseButton.Primary; + Debug.Assert(evt.EventClass == EventClass.Mouse); + MacOSMouseButton button; HIPoint pt = new HIPoint(); HIPoint screenLoc = new HIPoint(); @@ -484,20 +480,18 @@ namespace OpenTK.Platform.MacOS switch (button) { - case MouseButton.Primary: - InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = true; + case MacOSMouseButton.Primary: + mouse[MouseButton.Left] = true; break; - case MouseButton.Secondary: - InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = true; + case MacOSMouseButton.Secondary: + mouse[MouseButton.Right] = true; break; - case MouseButton.Tertiary: - InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = true; + case MacOSMouseButton.Tertiary: + mouse[MouseButton.Middle] = true; break; } - - return OSStatus.NoError; case MouseEventKind.MouseUp: @@ -505,29 +499,25 @@ namespace OpenTK.Platform.MacOS switch (button) { - case MouseButton.Primary: - InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = false; + case MacOSMouseButton.Primary: + mouse[MouseButton.Left] = false; break; - case MouseButton.Secondary: - InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = false; + case MacOSMouseButton.Secondary: + mouse[MouseButton.Right] = false; break; - case MouseButton.Tertiary: - InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = false; + case MacOSMouseButton.Tertiary: + mouse[MouseButton.Middle] = false; break; } - button = API.GetEventMouseButton(inEvent); - return OSStatus.NoError; case MouseEventKind.WheelMoved: int delta = API.GetEventMouseWheelDelta(inEvent) / 3; - - InputDriver.Mouse[0].Wheel += delta; - + mouse.Wheel += delta; return OSStatus.NoError; case MouseEventKind.MouseMoved: @@ -535,32 +525,23 @@ namespace OpenTK.Platform.MacOS //Debug.Print("Mouse Location: {0}, {1}", pt.X, pt.Y); - if (this.windowState == WindowState.Fullscreen) - { - if (mousePosInClient.X != InputDriver.Mouse[0].X || - mousePosInClient.Y != InputDriver.Mouse[0].Y) - { - InputDriver.Mouse[0].Position = mousePosInClient; + if (windowState == WindowState.Fullscreen) { + if (mousePosInClient.X != mouse.X || mousePosInClient.Y != mouse.Y) { + mouse.Position = mousePosInClient; } - } - else - { + } else { // ignore clicks in the title bar if (pt.Y < 0) return OSStatus.EventNotHandled; - if (mousePosInClient.X != InputDriver.Mouse[0].X || - mousePosInClient.Y != InputDriver.Mouse[0].Y) - { - InputDriver.Mouse[0].Position = mousePosInClient; + if (mousePosInClient.X != mouse.X || mousePosInClient.Y != mouse.Y) { + mouse.Position = mousePosInClient; } } - return OSStatus.EventNotHandled; default: Debug.Print("{0}", evt); - return OSStatus.EventNotHandled; } } @@ -591,6 +572,7 @@ namespace OpenTK.Platform.MacOS code = API.GetEventKeyboardKeyCode(inEvent); charCode = API.GetEventKeyboardChar(inEvent); } + private void ProcessModifierKey(IntPtr inEvent) { MacOSKeyModifiers modifiers = API.GetEventKeyModifiers(inEvent); @@ -603,42 +585,35 @@ namespace OpenTK.Platform.MacOS Debug.Print("Modifiers Changed: {0}", modifiers); - Input.KeyboardDevice keyboard = InputDriver.Keyboard[0]; + if (keyboard[Key.AltLeft] ^ option) + keyboard[Key.AltLeft] = option; - if (keyboard[OpenTK.Input.Key.AltLeft] ^ option) - keyboard[OpenTK.Input.Key.AltLeft] = option; + if (keyboard[Key.ShiftLeft] ^ shift) + keyboard[Key.ShiftLeft] = shift; - if (keyboard[OpenTK.Input.Key.ShiftLeft] ^ shift) - keyboard[OpenTK.Input.Key.ShiftLeft] = shift; + if (keyboard[Key.WinLeft] ^ command) + keyboard[Key.WinLeft] = command; - if (keyboard[OpenTK.Input.Key.WinLeft] ^ command) - keyboard[OpenTK.Input.Key.WinLeft] = command; + if (keyboard[Key.ControlLeft] ^ control) + keyboard[Key.ControlLeft] = control; - if (keyboard[OpenTK.Input.Key.ControlLeft] ^ control) - keyboard[OpenTK.Input.Key.ControlLeft] = control; - - if (keyboard[OpenTK.Input.Key.CapsLock] ^ caps) - keyboard[OpenTK.Input.Key.CapsLock] = caps; + if (keyboard[Key.CapsLock] ^ caps) + keyboard[Key.CapsLock] = caps; } - Rect GetRegion() - { - Rect retval = API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion); - - return retval; + Rect GetRegion() { + return API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion); } - void SetLocation(short x, short y) - { + void SetLocation(short x, short y) { if (windowState == WindowState.Fullscreen) return; API.MoveWindow(window.WindowRef, x, y, false); } - void SetSize(short width, short height) - { + void SetSize(short width, short height) { if (WindowState == WindowState.Fullscreen) return; @@ -651,26 +626,21 @@ namespace OpenTK.Platform.MacOS API.SizeWindow(window.WindowRef, width, height, true); } - void SetClientSize(short width, short height) - { + void SetClientSize(short width, short height) { if (WindowState == WindowState.Fullscreen) return; API.SizeWindow(window.WindowRef, width, height, true); } - protected void OnResize() - { + protected void OnResize() { LoadSize(); - - if (Resize != null) - { + if (Resize != null) { Resize(this, EventArgs.Empty); } } - private void LoadSize() - { + private void LoadSize() { if (WindowState == WindowState.Fullscreen) return; @@ -724,15 +694,10 @@ namespace OpenTK.Platform.MacOS get { return true; } } - public OpenTK.Input.IInputDriver InputDriver - { - get - { - return mInputDriver; - } + public IInputDriver InputDriver { + get { return this; } } - public Icon Icon { get { return mIcon; } @@ -836,28 +801,14 @@ namespace OpenTK.Platform.MacOS } } - public Point Location - { - get - { - return Bounds.Location; - } - set - { - SetLocation((short)value.X, (short)value.Y); - } + public Point Location { + get { return Bounds.Location; } + set { SetLocation((short)value.X, (short)value.Y); } } - public Size Size - { - get - { - return bounds.Size; - } - set - { - SetSize((short)value.Width, (short)value.Height); - } + public Size Size { + get { return bounds.Size; } + set { SetSize((short)value.Width, (short)value.Height); } } public int Width @@ -872,28 +823,14 @@ namespace OpenTK.Platform.MacOS set { SetClientSize((short)Width, (short)value); } } - public int X - { - get - { - return ClientRectangle.X; - } - set - { - Location = new Point(value, Y); - } + public int X { + get { return ClientRectangle.X; } + set { Location = new Point(value, Y); } } - public int Y - { - get - { - return ClientRectangle.Y; - } - set - { - Location = new Point(X, value); - } + public int Y { + get { return ClientRectangle.Y; } + set { Location = new Point(X, value); } } public Rectangle ClientRectangle @@ -1124,5 +1061,40 @@ namespace OpenTK.Platform.MacOS public event EventHandler MouseLeave; #endregion + + #region IInputDriver Members + + KeyboardDevice keyboard = new KeyboardDevice(); + MouseDevice mouse = new MouseDevice(); + List dummy_joystick_list = new List(1); + + public void Poll() { + } + + public KeyboardDevice Keyboard { + get { return keyboard; } + } + + public MouseDevice Mouse { + get { return mouse; } + } + + // TODO: Implement using native API, rather than through Mono. + // http://webnnel.googlecode.com/svn/trunk/lib/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/CarbonEventsCore.h + // GetPos --> GetGlobalMouse (no 64 bit support?), and HIGetMousePosition() + // https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/index.html#//apple_ref/c/func/CGWarpMouseCursorPosition + // SetPos --> CGWarpMouseCursorPosition + // Note that: CGPoint uses float on 32 bit systems, double on 64 bit systems + // The rest of the MacOS OpenTK API will probably need to be fixed for this too... + public Point DesktopCursorPos { + get { return System.Windows.Forms.Cursor.Position; } + set { System.Windows.Forms.Cursor.Position = value; } + } + + public IList Joysticks { + get { return dummy_joystick_list; } + } + + #endregion } } diff --git a/OpenTK/Platform/MacOS/CarbonInput.cs b/OpenTK/Platform/MacOS/CarbonInput.cs deleted file mode 100644 index d5af2f5de..000000000 --- a/OpenTK/Platform/MacOS/CarbonInput.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using OpenTK.Input; - -namespace OpenTK.Platform.MacOS -{ - class CarbonInput : IInputDriver - { - List dummy_keyboard_list = new List(1); - List dummy_mice_list = new List(1); - List dummy_joystick_list = new List(1); - - internal CarbonInput() - { - dummy_mice_list.Add(new MouseDevice()); - dummy_keyboard_list.Add(new KeyboardDevice()); - dummy_joystick_list.Add(new JoystickDevice(0, 0, 0)); - } - - #region IInputDriver Members - - public void Poll() - { - } - - #endregion - - #region IKeyboardDriver Members - - public IList Keyboard - { - get { return dummy_keyboard_list; } - } - - #endregion - - #region IMouseDriver Members - - public IList Mouse - { - get { return dummy_mice_list; } - } - - // TODO: Implement using native API, rather than through Mono. - // http://webnnel.googlecode.com/svn/trunk/lib/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/CarbonEventsCore.h - // GetPos --> GetGlobalMouse (no 64 bit support?), and HIGetMousePosition() - // https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/index.html#//apple_ref/c/func/CGWarpMouseCursorPosition - // SetPos --> CGWarpMouseCursorPosition - // Note that: CGPoint uses float on 32 bit systems, double on 64 bit systems - // The rest of the MacOS OpenTK API will probably need to be fixed for this too... - public Point DesktopCursorPos { - get { return System.Windows.Forms.Cursor.Position; } - set { System.Windows.Forms.Cursor.Position = value; } - } - - #endregion - - #region IJoystickDriver Members - - public IList Joysticks - { - get { return dummy_joystick_list; } - } - - #endregion - - #region IDisposable Members - - public void Dispose() - { - } - - #endregion - } -} diff --git a/OpenTK/Platform/Windows/WinGLNative.cs b/OpenTK/Platform/Windows/WinGLNative.cs index 6275c2d09..3e19a5eca 100644 --- a/OpenTK/Platform/Windows/WinGLNative.cs +++ b/OpenTK/Platform/Windows/WinGLNative.cs @@ -78,8 +78,6 @@ namespace OpenTK.Platform.Windows WinMMJoystick joystick_driver = new WinMMJoystick(); KeyboardDevice keyboard = new KeyboardDevice(); MouseDevice mouse = new MouseDevice(); - IList keyboards = new List(1); - IList mice = new List(1); static readonly WinKeyMap KeyMap = new WinKeyMap(); const long ExtendedBit = 1 << 24; // Used to distinguish left and right control, alt and enter keys. static readonly uint ShiftRightScanCode = Functions.MapVirtualKey(VirtualKeys.RSHIFT, 0); // Used to distinguish left and right shift keys. @@ -112,18 +110,6 @@ namespace OpenTK.Platform.Windows CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window); exists = true; - - keyboard.Description = "Standard Windows keyboard"; - keyboard.NumberOfFunctionKeys = 12; - keyboard.NumberOfKeys = 101; - keyboard.NumberOfLeds = 3; - - mouse.Description = "Standard Windows mouse"; - mouse.NumberOfButtons = 3; - mouse.NumberOfWheels = 1; - - keyboards.Add(keyboard); - mice.Add(mouse); } #endregion @@ -1125,29 +1111,18 @@ namespace OpenTK.Platform.Windows #region IInputDriver Members - public void Poll() - { + public void Poll() { joystick_driver.Poll(); } - - #endregion - - #region IKeyboardDriver Members - - public IList Keyboard - { - get { return keyboards; } - } - - #endregion - - #region IMouseDriver Members - - public IList Mouse - { - get { return mice; } + + public KeyboardDevice Keyboard { + get { return keyboard; } } + public MouseDevice Mouse { + get { return mouse; } + } + public Point DesktopCursorPos { get { Point pos = default( Point ); @@ -1158,7 +1133,7 @@ namespace OpenTK.Platform.Windows Functions.SetCursorPos( value.X, value.Y ); } } - + #endregion #region IJoystickDriver Members diff --git a/OpenTK/Platform/X11/X11Input.cs b/OpenTK/Platform/X11/X11Input.cs index 93544d6e7..37549b190 100644 --- a/OpenTK/Platform/X11/X11Input.cs +++ b/OpenTK/Platform/X11/X11Input.cs @@ -26,8 +26,6 @@ namespace OpenTK.Platform.X11 //X11WindowInfo window; KeyboardDevice keyboard = new KeyboardDevice(); MouseDevice mouse = new MouseDevice(); - List dummy_keyboard_list = new List(1); - List dummy_mice_list = new List(1); X11KeyMap keymap = new X11KeyMap(); int firstKeyCode, lastKeyCode; // The smallest and largest KeyCode supported by the X server. @@ -54,13 +52,6 @@ namespace OpenTK.Platform.X11 //window = new X11WindowInfo(attach); X11WindowInfo window = (X11WindowInfo)attach; - - // Init mouse - mouse.Description = "Default X11 mouse"; - mouse.DeviceID = IntPtr.Zero; - mouse.NumberOfButtons = 5; - mouse.NumberOfWheels = 1; - dummy_mice_list.Add(mouse); using (new XLock(window.Display)) { @@ -76,12 +67,6 @@ namespace OpenTK.Platform.X11 Marshal.PtrToStructure(keysym_ptr, keysyms); API.Free(keysym_ptr); - KeyboardDevice kb = new KeyboardDevice(); - keyboard.Description = "Default X11 keyboard"; - keyboard.NumberOfKeys = lastKeyCode - firstKeyCode + 1; - keyboard.DeviceID = IntPtr.Zero; - dummy_keyboard_list.Add(keyboard); - // Request that auto-repeat is only set on devices that support it physically. // This typically means that it's turned off for keyboards (which is what we want). // We prefer this method over XAutoRepeatOff/On, because the latter needs to @@ -212,23 +197,13 @@ namespace OpenTK.Platform.X11 #region --- IInputDriver Members --- - #region public IList Keyboard - - public IList Keyboard - { - get { return dummy_keyboard_list; }//return keyboardDriver.Keyboard; + public KeyboardDevice Keyboard { + get { return keyboard; } } - #endregion - - #region public IList Mouse - - public IList Mouse - { - get { return (IList)dummy_mice_list; } //return mouseDriver.Mouse; + public MouseDevice Mouse { + get { return mouse; } } - - #endregion // TODO: Implement using native API, rather than through Mono. public Point DesktopCursorPos {