mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-03-26 13:05:03 +00:00
[Platform] Refactored INativeWindow backends
All INativeWindow implementations are now derived from NativeWindowBase. They no longer implement legacy IInputDriver themselves, but rather rely on LegacyInputDriver provided by NativeWindowBase for compatibility. They also implement the new Mouse* events.
This commit is contained in:
parent
674cd54c29
commit
3e33ac9280
|
@ -197,7 +197,7 @@ namespace OpenTK.Input
|
|||
|
||||
#endregion
|
||||
|
||||
internal void SetKey(Key key, uint scancode, bool state)
|
||||
internal void SetKey(Key key, uint scancode, KeyModifiers mods, bool state)
|
||||
{
|
||||
if (keys[(int)key] != state || KeyRepeat)
|
||||
{
|
||||
|
@ -211,14 +211,14 @@ namespace OpenTK.Input
|
|||
{
|
||||
args.Key = key;
|
||||
args.ScanCode = scancode;
|
||||
args.Modifiers = GetModifiers();
|
||||
args.Modifiers = mods;
|
||||
KeyDown(this, args);
|
||||
}
|
||||
else if (!state && KeyUp != null)
|
||||
{
|
||||
args.Key = key;
|
||||
args.ScanCode = scancode;
|
||||
args.Modifiers = GetModifiers();
|
||||
args.Modifiers = mods;
|
||||
KeyUp(this, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -379,7 +379,7 @@ namespace OpenTK.Input
|
|||
#region Fields
|
||||
|
||||
int x, y;
|
||||
float wheel_x, wheel_y;
|
||||
int buttons;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -412,12 +412,35 @@ namespace OpenTK.Input
|
|||
{
|
||||
}
|
||||
|
||||
internal MouseEventArgs(float x, float y, float wx, float wy)
|
||||
#endregion
|
||||
|
||||
#region Protected Members
|
||||
|
||||
protected internal void SetButton(MouseButton button, ButtonState state)
|
||||
{
|
||||
X = (int)Math.Round(x);
|
||||
Y = (int)Math.Round(y);
|
||||
WheelX = wx;
|
||||
WheelY = wy;
|
||||
if (button < 0 || button > MouseButton.LastButton)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ButtonState.Pressed:
|
||||
buttons |= 1 << (int)button;
|
||||
break;
|
||||
|
||||
case ButtonState.Released:
|
||||
buttons &= ~(1 << (int)button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected internal ButtonState GetButton(MouseButton button)
|
||||
{
|
||||
if (button < 0 || button > MouseButton.LastButton)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
return
|
||||
(buttons & (1 << (int)button)) != 0 ?
|
||||
ButtonState.Pressed : ButtonState.Released;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -449,37 +472,65 @@ namespace OpenTK.Input
|
|||
/// This is an alias to <see cref="MouseEventArgs.WheelY"/>
|
||||
/// </summary>
|
||||
/// <value>The wheel.</value>
|
||||
public float Wheel { get { return WheelY; } }
|
||||
public float Wheel { get { return WheelY; } internal set { WheelY = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ButtonState"/> of the left mouse button.
|
||||
/// </summary>
|
||||
public ButtonState LeftButton { get; internal set; }
|
||||
public ButtonState LeftButton
|
||||
{
|
||||
get { return GetButton(MouseButton.Left); }
|
||||
internal set { SetButton(MouseButton.Left, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ButtonState"/> of the right mouse button.
|
||||
/// </summary>
|
||||
public ButtonState RightButton { get; internal set; }
|
||||
public ButtonState RightButton
|
||||
{
|
||||
get { return GetButton(MouseButton.Right); }
|
||||
internal set { SetButton(MouseButton.Right, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ButtonState"/> of the middle mouse button.
|
||||
/// </summary>
|
||||
public ButtonState MiddleButton { get; internal set; }
|
||||
public ButtonState MiddleButton
|
||||
{
|
||||
get { return GetButton(MouseButton.Middle); }
|
||||
internal set { SetButton(MouseButton.Middle, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ButtonState"/> of the first extra mouse button.
|
||||
/// </summary>
|
||||
public ButtonState X1Button { get; internal set; }
|
||||
public ButtonState X1Button
|
||||
{
|
||||
get { return GetButton(MouseButton.Button1); }
|
||||
internal set { SetButton(MouseButton.Button1, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ButtonState"/> of the second extra mouse button.
|
||||
/// </summary>
|
||||
public ButtonState X2Button { get; internal set; }
|
||||
public ButtonState X2Button
|
||||
{
|
||||
get { return GetButton(MouseButton.Button2); }
|
||||
internal set { SetButton(MouseButton.Button2, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a System.Drawing.Points representing the location of the mouse for the event.
|
||||
/// Gets a <see cref="System.Drawing.Point"/> representing the location of the mouse for the event.
|
||||
/// </summary>
|
||||
public Point Position { get { return new Point(x, y); } }
|
||||
public Point Position
|
||||
{
|
||||
get { return new Point(x, y); }
|
||||
set
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
@ -603,14 +654,18 @@ namespace OpenTK.Input
|
|||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// The mouse button for the event.
|
||||
/// Gets the <see cref="MouseButton"/> that triggered this event.
|
||||
/// </summary>
|
||||
public MouseButton Button { get { return button; } internal set { button = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a System.Boolean representing the state of the mouse button for the event.
|
||||
/// </summary>
|
||||
public bool IsPressed { get { return pressed; } internal set { pressed = value; } }
|
||||
public bool IsPressed
|
||||
{
|
||||
get { return GetButton(Button) == ButtonState.Pressed; }
|
||||
internal set { SetButton(Button, value ? ButtonState.Pressed : ButtonState.Released); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
@ -629,7 +684,6 @@ namespace OpenTK.Input
|
|||
{
|
||||
#region Fields
|
||||
|
||||
float value;
|
||||
float delta;
|
||||
|
||||
#endregion
|
||||
|
@ -651,7 +705,7 @@ namespace OpenTK.Input
|
|||
public MouseWheelEventArgs(int x, int y, int value, int delta)
|
||||
: base(x, y)
|
||||
{
|
||||
this.value = value;
|
||||
WheelY = value;
|
||||
this.delta = delta;
|
||||
}
|
||||
|
||||
|
@ -672,7 +726,7 @@ namespace OpenTK.Input
|
|||
/// Gets the value of the wheel in integer units.
|
||||
/// To support high-precision mice, it is recommended to use <see cref="ValuePrecise"/> instead.
|
||||
/// </summary>
|
||||
public int Value { get { return (int)Math.Round(value, MidpointRounding.AwayFromZero); } }
|
||||
public int Value { get { return (int)Math.Round(WheelY, MidpointRounding.AwayFromZero); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the change in value of the wheel for this event in integer units.
|
||||
|
@ -683,7 +737,7 @@ namespace OpenTK.Input
|
|||
/// <summary>
|
||||
/// Gets the precise value of the wheel in floating-point units.
|
||||
/// </summary>
|
||||
public float ValuePrecise { get { return value; } internal set { this.value = value; } }
|
||||
public float ValuePrecise { get { return WheelY; } internal set { WheelY = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the precise change in value of the wheel for this event in floating-point units.
|
||||
|
|
|
@ -42,18 +42,63 @@ namespace OpenTK.Platform
|
|||
|
||||
readonly LegacyJoystickDriver JoystickDriver = new LegacyJoystickDriver();
|
||||
|
||||
internal LegacyInputDriver()
|
||||
internal LegacyInputDriver(INativeWindow window)
|
||||
{
|
||||
dummy_mice_list.Add(new MouseDevice());
|
||||
Mouse[0].Description = "Standard Mouse";
|
||||
Mouse[0].NumberOfButtons = 3;
|
||||
Mouse[0].NumberOfWheels = 1;
|
||||
if (window == null)
|
||||
throw new ArgumentNullException();
|
||||
|
||||
dummy_keyboard_list.Add(new KeyboardDevice());
|
||||
Keyboard[0].Description = "Standard Keyboard";
|
||||
Keyboard[0].NumberOfKeys = 101;
|
||||
Keyboard[0].NumberOfLeds = 3;
|
||||
Keyboard[0].NumberOfFunctionKeys = 12;
|
||||
var mouse = new MouseDevice();
|
||||
mouse.Description = "Standard Mouse";
|
||||
mouse.NumberOfButtons = 3;
|
||||
mouse.NumberOfWheels = 1;
|
||||
dummy_mice_list.Add(mouse);
|
||||
|
||||
var keyboard = new KeyboardDevice();
|
||||
keyboard.Description = "Standard Keyboard";
|
||||
keyboard.NumberOfKeys = 101;
|
||||
keyboard.NumberOfLeds = 3;
|
||||
keyboard.NumberOfFunctionKeys = 12;
|
||||
dummy_keyboard_list.Add(keyboard);
|
||||
|
||||
// Hook mouse events
|
||||
window.MouseDown += (sender, e) =>
|
||||
{
|
||||
mouse[e.Button] = true;
|
||||
};
|
||||
|
||||
window.MouseUp += (sender, e) =>
|
||||
{
|
||||
mouse[e.Button] = false;
|
||||
};
|
||||
|
||||
window.MouseMove += (sender, e) =>
|
||||
{
|
||||
mouse.Position = e.Position;
|
||||
};
|
||||
|
||||
window.MouseWheel += (sender, e) =>
|
||||
{
|
||||
mouse.WheelPrecise = e.WheelY;
|
||||
};
|
||||
|
||||
// Hook keyboard events
|
||||
window.KeyDown += (sender, e) =>
|
||||
{
|
||||
keyboard.SetKey(e.Key, e.ScanCode, e.Modifiers, true);
|
||||
};
|
||||
|
||||
window.KeyUp += (sender, e) =>
|
||||
{
|
||||
keyboard.SetKey(e.Key, e.ScanCode, e.Modifiers, false);
|
||||
};
|
||||
|
||||
window.FocusedChanged += (sender, e) =>
|
||||
{
|
||||
if (!window.Focused)
|
||||
{
|
||||
keyboard.ClearKeys();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#region IInputDriver Members
|
||||
|
|
|
@ -422,7 +422,6 @@ namespace OpenTK.Platform.MacOS
|
|||
var modifierFlags = (NSEventModifierMask)Cocoa.SendUint(e, selModifierFlags);
|
||||
var isARepeat = Cocoa.SendBool(e, selIsARepeat);
|
||||
GetKey(keyCode, modifierFlags, keyArgs);
|
||||
InputDriver.Keyboard[0].SetKey(keyArgs.Key, keyArgs.ScanCode, true);
|
||||
|
||||
if (!isARepeat || InputDriver.Keyboard[0].KeyRepeat)
|
||||
{
|
||||
|
@ -450,8 +449,6 @@ namespace OpenTK.Platform.MacOS
|
|||
var modifierFlags = (NSEventModifierMask)Cocoa.SendUint(e, selModifierFlags);
|
||||
|
||||
GetKey(keyCode, modifierFlags, keyArgs);
|
||||
InputDriver.Keyboard[0].SetKey(keyArgs.Key, keyArgs.ScanCode, false);
|
||||
|
||||
OnKeyUp(keyArgs);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -38,8 +38,21 @@ namespace OpenTK.Platform
|
|||
// Common base class for all INativeWindow implementations
|
||||
abstract class NativeWindowBase : INativeWindow
|
||||
{
|
||||
readonly LegacyInputDriver LegacyInputDriver =
|
||||
new LegacyInputDriver();
|
||||
readonly LegacyInputDriver LegacyInputDriver;
|
||||
|
||||
readonly protected MouseButtonEventArgs MouseDownArgs = new MouseButtonEventArgs();
|
||||
readonly protected MouseButtonEventArgs MouseUpArgs = new MouseButtonEventArgs();
|
||||
readonly protected MouseMoveEventArgs MouseMoveArgs = new MouseMoveEventArgs();
|
||||
readonly protected MouseWheelEventArgs MouseWheelArgs = new MouseWheelEventArgs();
|
||||
|
||||
readonly protected KeyboardKeyEventArgs KeyDownArgs = new KeyboardKeyEventArgs();
|
||||
readonly protected KeyboardKeyEventArgs KeyUpArgs = new KeyboardKeyEventArgs();
|
||||
readonly protected KeyPressEventArgs KeyPressArgs = new KeyPressEventArgs((char)0);
|
||||
|
||||
internal NativeWindowBase()
|
||||
{
|
||||
LegacyInputDriver = new LegacyInputDriver(this);
|
||||
}
|
||||
|
||||
#region Protected Members
|
||||
|
||||
|
@ -133,7 +146,7 @@ namespace OpenTK.Platform
|
|||
MouseUp(this, e);
|
||||
}
|
||||
|
||||
protected void OnMouseDown(MouseMoveEventArgs e)
|
||||
protected void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
MouseMove(this, e);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||
{
|
||||
return new Sdl2NativeWindow(x, y, width, height, title, options, device, InputDriver);
|
||||
return new Sdl2NativeWindow(x, y, width, height, title, options, device);
|
||||
}
|
||||
|
||||
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
|
|
|
@ -34,7 +34,7 @@ using OpenTK.Input;
|
|||
|
||||
namespace OpenTK.Platform.SDL2
|
||||
{
|
||||
class Sdl2InputDriver : IInputDriver2, IInputDriver
|
||||
class Sdl2InputDriver : IInputDriver2
|
||||
{
|
||||
readonly static Dictionary<IntPtr, Sdl2InputDriver> DriverHandles =
|
||||
new Dictionary<IntPtr, Sdl2InputDriver>();
|
||||
|
@ -154,51 +154,6 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
#endregion
|
||||
|
||||
#region IInputDriver Members
|
||||
|
||||
public void Poll()
|
||||
{
|
||||
joystick_driver.Poll();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IJoystickDriver Members
|
||||
|
||||
public IList<JoystickDevice> Joysticks
|
||||
{
|
||||
get
|
||||
{
|
||||
return joystick_driver.Joysticks;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMouseDriver Members
|
||||
|
||||
public IList<MouseDevice> Mouse
|
||||
{
|
||||
get
|
||||
{
|
||||
return mouse_driver.Mouse;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IKeyboardDriver Members
|
||||
|
||||
public IList<KeyboardDevice> Keyboard
|
||||
{
|
||||
get
|
||||
{
|
||||
return keyboard_driver.Keyboard;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IInputDriver2 Members
|
||||
|
||||
public IMouseDriver2 MouseDriver
|
||||
|
|
|
@ -298,6 +298,15 @@ namespace OpenTK.Platform.SDL2
|
|||
return Key.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public static KeyModifiers GetModifiers(Keymod mod)
|
||||
{
|
||||
KeyModifiers result = 0;
|
||||
result |= (mod & Keymod.ALT) != 0 ? KeyModifiers.Alt : 0;
|
||||
result |= (mod & Keymod.CTRL) != 0 ? KeyModifiers.Control : 0;
|
||||
result |= (mod & Keymod.SHIFT) != 0 ? KeyModifiers.Shift : 0;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ using OpenTK.Input;
|
|||
|
||||
namespace OpenTK.Platform.SDL2
|
||||
{
|
||||
class Sdl2Keyboard : IKeyboardDriver2, IKeyboardDriver
|
||||
class Sdl2Keyboard : IKeyboardDriver2
|
||||
{
|
||||
KeyboardState state;
|
||||
|
||||
|
@ -42,13 +42,6 @@ namespace OpenTK.Platform.SDL2
|
|||
public Sdl2Keyboard()
|
||||
{
|
||||
state.IsConnected = true;
|
||||
|
||||
keyboards.Add(new KeyboardDevice());
|
||||
keyboards[0].Description = "Standard keyboard";
|
||||
keyboards[0].NumberOfFunctionKeys = 12;
|
||||
keyboards[0].NumberOfKeys = 101;
|
||||
keyboards[0].NumberOfLeds = 3;
|
||||
keyboards_readonly = keyboards.AsReadOnly();
|
||||
}
|
||||
|
||||
#region Private Members
|
||||
|
@ -86,22 +79,11 @@ namespace OpenTK.Platform.SDL2
|
|||
bool pressed = e.State != 0;
|
||||
var scancode = e.Keysym.Scancode;
|
||||
Key key = Sdl2KeyMap.GetKey(scancode);
|
||||
KeyModifiers mods = Sdl2KeyMap.GetModifiers(e.Keysym.Mod);
|
||||
|
||||
if (key != Key.Unknown)
|
||||
{
|
||||
state.SetKeyState(key, (byte)scancode, pressed);
|
||||
keyboards[0].SetKey(key, (byte)scancode, pressed);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IKeyboardDriver Members
|
||||
|
||||
public IList<KeyboardDevice> Keyboard
|
||||
{
|
||||
get
|
||||
{
|
||||
return keyboards_readonly;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ using System.Text;
|
|||
|
||||
namespace OpenTK.Platform.SDL2
|
||||
{
|
||||
class Sdl2NativeWindow : NativeWindowBase, IInputDriver
|
||||
class Sdl2NativeWindow : NativeWindowBase
|
||||
{
|
||||
readonly object sync = new object();
|
||||
|
||||
|
@ -72,19 +72,14 @@ namespace OpenTK.Platform.SDL2
|
|||
// Argument for KeyDown and KeyUp events (allocated once to avoid runtime allocations)
|
||||
readonly KeyboardKeyEventArgs key_args = new KeyboardKeyEventArgs();
|
||||
|
||||
readonly IInputDriver input_driver;
|
||||
|
||||
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
|
||||
new Dictionary<uint, Sdl2NativeWindow>();
|
||||
|
||||
public Sdl2NativeWindow(int x, int y, int width, int height,
|
||||
string title, GameWindowFlags options, DisplayDevice device,
|
||||
IInputDriver input_driver)
|
||||
string title, GameWindowFlags options, DisplayDevice device)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
this.input_driver = input_driver;
|
||||
|
||||
var bounds = device.Bounds;
|
||||
var flags = TranslateFlags(options);
|
||||
flags |= WindowFlags.OPENGL;
|
||||
|
@ -233,7 +228,7 @@ namespace OpenTK.Platform.SDL2
|
|||
var key = ev.Key.Keysym;
|
||||
window.key_args.Key = TranslateKey(key.Scancode);
|
||||
window.key_args.ScanCode = (uint)key.Scancode;
|
||||
window.key_args.Modifiers = window.input_driver.Keyboard[0].GetModifiers();
|
||||
window.key_args.Modifiers = Sdl2KeyMap.GetModifiers(key.Mod);
|
||||
if (key_pressed)
|
||||
{
|
||||
window.OnKeyDown(window.key_args);
|
||||
|
@ -890,14 +885,6 @@ namespace OpenTK.Platform.SDL2
|
|||
}
|
||||
}
|
||||
|
||||
public override IInputDriver InputDriver
|
||||
{
|
||||
get
|
||||
{
|
||||
return input_driver;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CursorVisible
|
||||
{
|
||||
get
|
||||
|
@ -919,51 +906,6 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
#endregion
|
||||
|
||||
#region IInputDriver Members
|
||||
|
||||
public void Poll()
|
||||
{
|
||||
InputDriver.Poll();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IJoystickDriver Members
|
||||
|
||||
public IList<JoystickDevice> Joysticks
|
||||
{
|
||||
get
|
||||
{
|
||||
return InputDriver.Joysticks;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMouseDriver Members
|
||||
|
||||
public IList<MouseDevice> Mouse
|
||||
{
|
||||
get
|
||||
{
|
||||
return InputDriver.Mouse;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IKeyboardDriver Members
|
||||
|
||||
public IList<KeyboardDevice> Keyboard
|
||||
{
|
||||
get
|
||||
{
|
||||
return InputDriver.Keyboard;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable implementation
|
||||
|
||||
protected override void Dispose(bool manual)
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// Drives GameWindow on Windows.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal sealed class WinGLNative : NativeWindowBase, IInputDriver
|
||||
internal sealed class WinGLNative : NativeWindowBase
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
@ -82,12 +82,6 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
const ClassStyle DefaultClassStyle = ClassStyle.OwnDC;
|
||||
|
||||
// Used for IInputDriver implementation
|
||||
IJoystickDriver joystick_driver = Factory.Default.CreateLegacyJoystickDriver();
|
||||
KeyboardDevice keyboard = new KeyboardDevice();
|
||||
MouseDevice mouse = new MouseDevice();
|
||||
IList<KeyboardDevice> keyboards = new List<KeyboardDevice>(1);
|
||||
IList<MouseDevice> mice = new List<MouseDevice>(1);
|
||||
const long ExtendedBit = 1 << 24; // Used to distinguish left and right control, alt and enter keys.
|
||||
|
||||
public static readonly uint ShiftLeftScanCode = Functions.MapVirtualKey(VirtualKeys.LSHIFT, 0);
|
||||
|
@ -97,10 +91,6 @@ namespace OpenTK.Platform.Windows
|
|||
public static readonly uint AltLeftScanCode = Functions.MapVirtualKey(VirtualKeys.LMENU, 0);
|
||||
public static readonly uint AltRightScanCode = Functions.MapVirtualKey(VirtualKeys.RMENU, 0);
|
||||
|
||||
KeyboardKeyEventArgs key_down = new KeyboardKeyEventArgs();
|
||||
KeyboardKeyEventArgs key_up = new KeyboardKeyEventArgs();
|
||||
KeyPressEventArgs key_press = new KeyPressEventArgs((char)0);
|
||||
|
||||
MouseCursor cursor = MouseCursor.Default;
|
||||
IntPtr cursor_handle = Functions.LoadCursor(CursorName.Arrow);
|
||||
int cursor_visible_count = 0;
|
||||
|
@ -160,18 +150,6 @@ namespace OpenTK.Platform.Windows
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +232,7 @@ namespace OpenTK.Platform.Windows
|
|||
focused = (wParam.ToInt64() & 0xFFFF) != 0;
|
||||
|
||||
if (new_focused_state != Focused)
|
||||
FocusedChanged(this, EventArgs.Empty);
|
||||
OnFocusedChanged(EventArgs.Empty);
|
||||
}
|
||||
|
||||
void HandleEnterModalLoop(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
|
@ -292,7 +270,7 @@ namespace OpenTK.Platform.Windows
|
|||
if (Location != new_location)
|
||||
{
|
||||
bounds.Location = new_location;
|
||||
Move(this, EventArgs.Empty);
|
||||
OnMove(EventArgs.Empty);
|
||||
}
|
||||
|
||||
Size new_size = new Size(pos->cx, pos->cy);
|
||||
|
@ -310,7 +288,7 @@ namespace OpenTK.Platform.Windows
|
|||
SetWindowPosFlags.NOACTIVATE | SetWindowPosFlags.NOSENDCHANGING);
|
||||
|
||||
if (suppress_resize <= 0)
|
||||
Resize(this, EventArgs.Empty);
|
||||
OnResize(EventArgs.Empty);
|
||||
}
|
||||
|
||||
if (!is_in_modal_loop)
|
||||
|
@ -352,7 +330,7 @@ namespace OpenTK.Platform.Windows
|
|||
GrabCursor();
|
||||
|
||||
windowBorder = new_border;
|
||||
WindowBorderChanged(this, EventArgs.Empty);
|
||||
OnWindowBorderChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,7 +358,7 @@ namespace OpenTK.Platform.Windows
|
|||
if (new_state != windowState)
|
||||
{
|
||||
windowState = new_state;
|
||||
WindowStateChanged(this, EventArgs.Empty);
|
||||
OnWindowStateChanged(EventArgs.Empty);
|
||||
|
||||
// Ensure cursor remains grabbed
|
||||
if (!CursorVisible)
|
||||
|
@ -415,8 +393,8 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
if (!Char.IsControl(c))
|
||||
{
|
||||
key_press.KeyChar = c;
|
||||
KeyPress(this, key_press);
|
||||
KeyPressArgs.KeyChar = c;
|
||||
OnKeyPress(KeyPressArgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,7 +437,8 @@ namespace OpenTK.Platform.Windows
|
|||
if (points == 0 || (points == -1 && lastError == Constants.ERROR_POINT_NOT_FOUND))
|
||||
{
|
||||
// Just use the mouse move position
|
||||
mouse.Position = point;
|
||||
MouseMoveArgs.Position = point;
|
||||
OnMouseMove(MouseMoveArgs);
|
||||
}
|
||||
else if (points == -1)
|
||||
{
|
||||
|
@ -468,7 +447,7 @@ namespace OpenTK.Platform.Windows
|
|||
else
|
||||
{
|
||||
// Exclude the current position.
|
||||
Point currentScreenPosition = new Point(mouse.X, mouse.Y);
|
||||
Point currentScreenPosition = new Point(InputDriver.Mouse[0].X, InputDriver.Mouse[0].Y);
|
||||
Functions.ClientToScreen(handle, ref currentScreenPosition);
|
||||
|
||||
// Find the first move point we've already seen.
|
||||
|
@ -497,7 +476,8 @@ namespace OpenTK.Platform.Windows
|
|||
position.Y -= 65536;
|
||||
}
|
||||
Functions.ScreenToClient(handle, ref position);
|
||||
mouse.Position = position;
|
||||
MouseMoveArgs.Position = position;
|
||||
OnMouseMove(MouseMoveArgs);
|
||||
}
|
||||
}
|
||||
mouse_last_timestamp = timestamp;
|
||||
|
@ -510,7 +490,7 @@ namespace OpenTK.Platform.Windows
|
|||
mouse_outside_window = false;
|
||||
EnableMouseTracking();
|
||||
|
||||
MouseEnter(this, EventArgs.Empty);
|
||||
OnMouseEnter(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,64 +499,85 @@ namespace OpenTK.Platform.Windows
|
|||
mouse_outside_window = true;
|
||||
// Mouse tracking is disabled automatically by the OS
|
||||
|
||||
MouseLeave(this, EventArgs.Empty);
|
||||
OnMouseLeave(EventArgs.Empty);
|
||||
}
|
||||
|
||||
void HandleMouseWheel(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
// This is due to inconsistent behavior of the WParam value on 64bit arch, whese
|
||||
// wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000
|
||||
mouse.WheelPrecise += ((long)wParam << 32 >> 48) / 120.0f;
|
||||
MouseWheelArgs.Wheel += ((long)wParam << 32 >> 48) / 120.0f;
|
||||
OnMouseWheel(MouseWheelArgs);
|
||||
}
|
||||
|
||||
void HandleLButtonDown(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.SetCapture(window.Handle);
|
||||
mouse[MouseButton.Left] = true;
|
||||
MouseDownArgs.Button = MouseButton.Left;
|
||||
MouseDownArgs.IsPressed = true;
|
||||
OnMouseDown(MouseDownArgs);
|
||||
}
|
||||
|
||||
void HandleMButtonDown(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.SetCapture(window.Handle);
|
||||
mouse[MouseButton.Middle] = true;
|
||||
MouseDownArgs.Button = MouseButton.Middle;
|
||||
MouseDownArgs.IsPressed = true;
|
||||
OnMouseDown(MouseDownArgs);
|
||||
}
|
||||
|
||||
void HandleRButtonDown(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.SetCapture(window.Handle);
|
||||
mouse[MouseButton.Right] = true;
|
||||
MouseDownArgs.Button = MouseButton.Right;
|
||||
MouseDownArgs.IsPressed = true;
|
||||
OnMouseDown(MouseDownArgs);
|
||||
}
|
||||
|
||||
void HandleXButtonDown(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.SetCapture(window.Handle);
|
||||
mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) == 1 ?
|
||||
MouseButton.Button1 : MouseButton.Button2] = true;
|
||||
MouseButton button =
|
||||
((wParam.ToInt32() & 0xFFFF0000) >> 16) == 1 ?
|
||||
MouseButton.Button1 : MouseButton.Button2;
|
||||
MouseDownArgs.Button = button;
|
||||
MouseDownArgs.IsPressed = true;
|
||||
OnMouseDown(MouseDownArgs);
|
||||
}
|
||||
|
||||
void HandleLButtonUp(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.ReleaseCapture();
|
||||
mouse[MouseButton.Left] = false;
|
||||
MouseDownArgs.Button = MouseButton.Left;
|
||||
MouseDownArgs.IsPressed = false;
|
||||
OnMouseUp(MouseUpArgs);
|
||||
}
|
||||
|
||||
void HandleMButtonUp(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.ReleaseCapture();
|
||||
mouse[MouseButton.Middle] = false;
|
||||
MouseDownArgs.Button = MouseButton.Middle;
|
||||
MouseDownArgs.IsPressed = false;
|
||||
OnMouseUp(MouseUpArgs);
|
||||
}
|
||||
|
||||
void HandleRButtonUp(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.ReleaseCapture();
|
||||
mouse[MouseButton.Right] = false;
|
||||
MouseDownArgs.Button = MouseButton.Right;
|
||||
MouseDownArgs.IsPressed = false;
|
||||
OnMouseUp(MouseUpArgs);
|
||||
}
|
||||
|
||||
void HandleXButtonUp(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
Functions.ReleaseCapture();
|
||||
mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) == 1 ?
|
||||
MouseButton.Button1 : MouseButton.Button2] = false;
|
||||
MouseButton button =
|
||||
((wParam.ToInt32() & 0xFFFF0000) >> 16) == 1 ?
|
||||
MouseButton.Button1 : MouseButton.Button2;
|
||||
MouseDownArgs.Button = button;
|
||||
MouseDownArgs.IsPressed = false;
|
||||
OnMouseUp(MouseUpArgs);
|
||||
}
|
||||
|
||||
void HandleKeyboard(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
|
@ -600,26 +601,23 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
if (is_valid)
|
||||
{
|
||||
keyboard.SetKey(key, (byte)scancode, pressed);
|
||||
|
||||
if (pressed)
|
||||
{
|
||||
key_down.Key = key;
|
||||
key_down.Modifiers = keyboard.GetModifiers();
|
||||
KeyDown(this, key_down);
|
||||
KeyDownArgs.Key = key;
|
||||
KeyDownArgs.Modifiers = InputDriver.Keyboard[0].GetModifiers();
|
||||
OnKeyDown(KeyDownArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
key_up.Key = key;
|
||||
key_up.Modifiers = keyboard.GetModifiers();
|
||||
KeyUp(this, key_up);
|
||||
KeyUpArgs.Key = key;
|
||||
KeyUpArgs.Modifiers = InputDriver.Keyboard[0].GetModifiers();
|
||||
OnKeyUp(KeyUpArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleKillFocus(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
keyboard.ClearKeys();
|
||||
}
|
||||
|
||||
void HandleCreate(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
|
@ -644,7 +642,7 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs();
|
||||
|
||||
Closing(this, e);
|
||||
OnClosing(e);
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
|
@ -663,7 +661,7 @@ namespace OpenTK.Platform.Windows
|
|||
window.Dispose();
|
||||
child_window.Dispose();
|
||||
|
||||
Closed(this, EventArgs.Empty);
|
||||
OnClosed(EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -1117,7 +1115,7 @@ namespace OpenTK.Platform.Windows
|
|||
Functions.SendMessage(window.Handle, WindowMessage.SETICON, (IntPtr)0, icon == null ? IntPtr.Zero : value.Handle);
|
||||
Functions.SendMessage(window.Handle, WindowMessage.SETICON, (IntPtr)1, icon == null ? IntPtr.Zero : value.Handle);
|
||||
}
|
||||
IconChanged(this, EventArgs.Empty);
|
||||
OnIconChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1151,7 +1149,7 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
if (!Functions.SetWindowText(window.Handle, value))
|
||||
Debug.Print("Failed to change window title (window:{0}, new title:{1}, reason:{2}).", window.Handle, value, Marshal.GetLastWin32Error());
|
||||
TitleChanged(this, EventArgs.Empty);
|
||||
OnTitleChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1184,7 +1182,7 @@ namespace OpenTK.Platform.Windows
|
|||
Functions.ShowWindow(window.Handle, ShowWindowCommand.HIDE);
|
||||
}
|
||||
|
||||
VisibleChanged(this, EventArgs.Empty);
|
||||
OnVisibleChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1526,27 +1524,6 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<EventArgs> Move = delegate { };
|
||||
public event EventHandler<EventArgs> Resize = delegate { };
|
||||
public event EventHandler<System.ComponentModel.CancelEventArgs> Closing = delegate { };
|
||||
public event EventHandler<EventArgs> Closed = delegate { };
|
||||
public event EventHandler<EventArgs> Disposed = delegate { };
|
||||
public event EventHandler<EventArgs> IconChanged = delegate { };
|
||||
public event EventHandler<EventArgs> TitleChanged = delegate { };
|
||||
public event EventHandler<EventArgs> VisibleChanged = delegate { };
|
||||
public event EventHandler<EventArgs> FocusedChanged = delegate { };
|
||||
public event EventHandler<EventArgs> WindowBorderChanged = delegate { };
|
||||
public event EventHandler<EventArgs> WindowStateChanged = delegate { };
|
||||
public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyDown = delegate { };
|
||||
public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
|
||||
public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyUp = delegate { };
|
||||
public event EventHandler<EventArgs> MouseEnter = delegate { };
|
||||
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region INativeGLWindow Members
|
||||
|
@ -1565,15 +1542,6 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region public IInputDriver InputDriver
|
||||
|
||||
public IInputDriver InputDriver
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public IWindowInfo WindowInfo
|
||||
|
||||
public override IWindowInfo WindowInfo
|
||||
|
@ -1585,61 +1553,8 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region IInputDriver Members
|
||||
|
||||
public void Poll()
|
||||
{
|
||||
if (joystick_driver is WinMMJoystick)
|
||||
(joystick_driver as WinMMJoystick).Poll();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IKeyboardDriver Members
|
||||
|
||||
public IList<KeyboardDevice> Keyboard
|
||||
{
|
||||
get { return keyboards; }
|
||||
}
|
||||
|
||||
public KeyboardState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public KeyboardState GetState(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMouseDriver Members
|
||||
|
||||
public IList<MouseDevice> Mouse
|
||||
{
|
||||
get { return mice; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IJoystickDriver Members
|
||||
|
||||
public IList<JoystickDevice> Joysticks
|
||||
{
|
||||
get { return joystick_driver.Joysticks; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool calledManually)
|
||||
{
|
||||
if (!disposed)
|
||||
|
@ -1662,7 +1577,7 @@ namespace OpenTK.Platform.Windows
|
|||
Debug.Print("[Warning] INativeWindow leaked ({0}). Did you forget to call INativeWindow.Dispose()?", this);
|
||||
}
|
||||
|
||||
Disposed(this, EventArgs.Empty);
|
||||
OnDisposed(EventArgs.Empty);
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -862,9 +862,6 @@ namespace OpenTK.Platform.X11
|
|||
Key key;
|
||||
if (driver.TranslateKey(ref e.KeyEvent, out key))
|
||||
{
|
||||
// Update legacy GameWindow.Keyboard API:
|
||||
keyboard.SetKey(key, (uint)e.KeyEvent.keycode, pressed);
|
||||
|
||||
if (pressed)
|
||||
{
|
||||
// Raise KeyDown event
|
||||
|
|
Loading…
Reference in a new issue