[Platform] Inherit NativeWindowBase

This commit is contained in:
thefiddler 2014-05-02 14:18:40 +02:00
parent 300203f73b
commit 612652910f
7 changed files with 177 additions and 184 deletions

View file

@ -379,6 +379,7 @@ namespace OpenTK.Input
#region Fields
int x, y;
float wheel_x, wheel_y;
#endregion
@ -411,6 +412,14 @@ namespace OpenTK.Input
{
}
internal MouseEventArgs(float x, float y, float wx, float wy)
{
X = (int)Math.Round(x);
Y = (int)Math.Round(y);
WheelX = wx;
WheelY = wy;
}
#endregion
#region Public Members
@ -425,6 +434,48 @@ namespace OpenTK.Input
/// </summary>
public int Y { get { return y; } internal set { y = value; } }
/// <summary>
/// Gets the offset of the horizontal wheel, if one exists.
/// </summary>
public float WheelX { get; internal set; }
/// <summary>
/// Gets the offset of the vertical wheel, if one exists.
/// </summary>
public float WheelY { get; internal set; }
/// <summary>
/// Gets the offset of the vertical wheel, if one exists.
/// This is an alias to <see cref="MouseEventArgs.WheelY"/>
/// </summary>
/// <value>The wheel.</value>
public float Wheel { get { return WheelY; } }
/// <summary>
/// Gets the <see cref="ButtonState"/> of the left mouse button.
/// </summary>
public ButtonState LeftButton { get; internal set; }
/// <summary>
/// Gets the <see cref="ButtonState"/> of the right mouse button.
/// </summary>
public ButtonState RightButton { get; internal set; }
/// <summary>
/// Gets the <see cref="ButtonState"/> of the middle mouse button.
/// </summary>
public ButtonState MiddleButton { get; internal set; }
/// <summary>
/// Gets the <see cref="ButtonState"/> of the first extra mouse button.
/// </summary>
public ButtonState X1Button { get; internal set; }
/// <summary>
/// Gets the <see cref="ButtonState"/> of the second extra mouse button.
/// </summary>
public ButtonState X2Button { get; internal set; }
/// <summary>
/// Gets a System.Drawing.Points representing the location of the mouse for the event.
/// </summary>

View file

@ -680,6 +680,26 @@ namespace OpenTK
/// </summary>
public event EventHandler<EventArgs> WindowStateChanged = delegate { };
/// <summary>
/// Occurs when a <see cref="MouseButton"/> is pressed.
/// </summary>
public event EventHandler<MouseButtonEventArgs> MouseDown = delegate { };
/// <summary>
/// Occurs when a <see cref="MouseButton"/> is released.
/// </summary>
public event EventHandler<MouseButtonEventArgs> MouseUp = delegate { };
/// <summary>
/// Occurs whenever the mouse is moved.
/// </summary>
public event EventHandler<MouseMoveEventArgs> MouseMove = delegate { };
/// <summary>
/// Occurs whenever a mouse wheel is moved;
/// </summary>
public event EventHandler<MouseWheelEventArgs> MouseWheel = delegate { };
#endregion
#endregion

View file

@ -835,7 +835,7 @@ namespace OpenTK.Platform.MacOS
}
}
public MouseCursor Cursor
public override MouseCursor Cursor
{
get
{
@ -957,7 +957,7 @@ namespace OpenTK.Platform.MacOS
Cocoa.SendVoid(windowInfo.Handle, selInvalidateCursorRectsForView, windowInfo.ViewHandle);
}
public bool CursorVisible
public override bool CursorVisible
{
get { return cursorVisible; }
set

View file

@ -35,7 +35,7 @@ using OpenTK.Input;
namespace OpenTK.Platform
{
// Common base class for all INativeWindow implementations
abstract class NativeWindowBase : INativeWindow
{
readonly LegacyInputDriver LegacyInputDriver =
@ -123,6 +123,26 @@ namespace OpenTK.Platform
MouseEnter(this, e);
}
protected void OnMouseDown(MouseButtonEventArgs e)
{
MouseDown(this, e);
}
protected void OnMouseUp(MouseButtonEventArgs e)
{
MouseUp(this, e);
}
protected void OnMouseDown(MouseMoveEventArgs e)
{
MouseMove(this, e);
}
protected void OnMouseWheel(MouseWheelEventArgs e)
{
MouseWheel(this, e);
}
#endregion
#region INativeWindow Members
@ -143,6 +163,10 @@ namespace OpenTK.Platform
public event EventHandler<KeyboardKeyEventArgs> KeyUp = delegate { };
public event EventHandler<EventArgs> MouseLeave = delegate { };
public event EventHandler<EventArgs> MouseEnter = delegate { };
public event EventHandler<MouseButtonEventArgs> MouseDown = delegate { };
public event EventHandler<MouseButtonEventArgs> MouseUp = delegate { };
public event EventHandler<MouseMoveEventArgs> MouseMove = delegate { };
public event EventHandler<MouseWheelEventArgs> MouseWheel = delegate { };
public abstract void Close();
@ -182,7 +206,7 @@ namespace OpenTK.Platform
}
}
public Size Size
public virtual Size Size
{
get
{
@ -270,6 +294,8 @@ namespace OpenTK.Platform
public abstract bool CursorVisible { get; set; }
public abstract MouseCursor Cursor { get; set; }
#endregion
#region IDisposable Members

View file

@ -41,7 +41,7 @@ using System.Text;
namespace OpenTK.Platform.SDL2
{
class Sdl2NativeWindow : INativeWindow, IInputDriver
class Sdl2NativeWindow : NativeWindowBase, IInputDriver
{
readonly object sync = new object();
@ -236,11 +236,11 @@ namespace OpenTK.Platform.SDL2
window.key_args.Modifiers = window.input_driver.Keyboard[0].GetModifiers();
if (key_pressed)
{
window.KeyDown(window, window.key_args);
window.OnKeyDown(window.key_args);
}
else
{
window.KeyUp(window, window.key_args);
window.OnKeyUp(window.key_args);
}
//window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
}
@ -274,7 +274,7 @@ namespace OpenTK.Platform.SDL2
for (int i = 0; i < decoded_length; i++)
{
window.keypress_args.KeyChar = window.DecodeTextBuffer[i];
window.KeyPress(window, window.keypress_args);
window.OnKeyPress(window.keypress_args);
}
}
@ -299,7 +299,7 @@ namespace OpenTK.Platform.SDL2
try
{
window.is_in_closing_event = true;
window.Closing(window, close_args);
window.OnClosing(close_args);
}
finally
{
@ -308,17 +308,17 @@ namespace OpenTK.Platform.SDL2
if (!close_args.Cancel)
{
window.Closed(window, EventArgs.Empty);
window.OnClosed(EventArgs.Empty);
window.must_destroy = true;
}
break;
case WindowEventID.ENTER:
window.MouseEnter(window, EventArgs.Empty);
window.OnMouseEnter(EventArgs.Empty);
break;
case WindowEventID.LEAVE:
window.MouseLeave(window, EventArgs.Empty);
window.OnMouseLeave(EventArgs.Empty);
break;
case WindowEventID.EXPOSED:
@ -327,47 +327,47 @@ namespace OpenTK.Platform.SDL2
case WindowEventID.FOCUS_GAINED:
window.is_focused = true;
window.FocusedChanged(window, EventArgs.Empty);
window.OnFocusedChanged(EventArgs.Empty);
break;
case WindowEventID.FOCUS_LOST:
window.is_focused = false;
window.FocusedChanged(window, EventArgs.Empty);
window.OnFocusedChanged(EventArgs.Empty);
break;
case WindowEventID.HIDDEN:
window.is_visible = false;
window.VisibleChanged(window, EventArgs.Empty);
window.OnVisibleChanged(EventArgs.Empty);
break;
case WindowEventID.SHOWN:
window.is_visible = true;
window.VisibleChanged(window, EventArgs.Empty);
window.OnVisibleChanged(EventArgs.Empty);
break;
case WindowEventID.MAXIMIZED:
window.window_state = WindowState.Maximized;
window.WindowStateChanged(window, EventArgs.Empty);
window.OnWindowStateChanged(EventArgs.Empty);
break;
case WindowEventID.MINIMIZED:
window.previous_window_state = window.window_state;
window.window_state = WindowState.Minimized;
window.WindowStateChanged(window, EventArgs.Empty);
window.OnWindowStateChanged(EventArgs.Empty);
break;
case WindowEventID.RESTORED:
window.window_state = window.previous_window_state;
window.WindowStateChanged(window, EventArgs.Empty);
window.OnWindowStateChanged(EventArgs.Empty);
break;
case WindowEventID.MOVED:
window.Move(window, EventArgs.Empty);
window.OnMove(EventArgs.Empty);
break;
case WindowEventID.RESIZED:
case WindowEventID.SIZE_CHANGED:
window.Resize(window, EventArgs.Empty);
window.OnResize(EventArgs.Empty);
break;
default:
@ -443,24 +443,7 @@ namespace OpenTK.Platform.SDL2
#region INativeWindow Members
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<KeyboardKeyEventArgs> KeyDown = delegate { };
public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
public event EventHandler<KeyboardKeyEventArgs> KeyUp = delegate { };
public event EventHandler<EventArgs> MouseEnter = delegate { };
public event EventHandler<EventArgs> MouseLeave = delegate { };
public MouseCursor Cursor
public override MouseCursor Cursor
{
get
{
@ -540,7 +523,7 @@ namespace OpenTK.Platform.SDL2
}
}
public void Close()
public override void Close()
{
lock (sync)
{
@ -560,7 +543,7 @@ namespace OpenTK.Platform.SDL2
}
}
public void ProcessEvents()
public override void ProcessEvents()
{
lock (sync)
{
@ -581,21 +564,21 @@ namespace OpenTK.Platform.SDL2
}
}
public Point PointToClient(Point point)
public override Point PointToClient(Point point)
{
var origin = DisplayDevice.Default.Bounds.Location;
var client = Location;
return new Point(point.X + client.X - origin.X, point.Y + client.Y - origin.Y);
}
public Point PointToScreen(Point point)
public override Point PointToScreen(Point point)
{
var origin = DisplayDevice.Default.Bounds.Location;
var client = Location;
return new Point(point.X + origin.X - client.X, point.Y + origin.Y - client.Y);
}
public Icon Icon
public override Icon Icon
{
get
{
@ -639,13 +622,13 @@ namespace OpenTK.Platform.SDL2
}
icon = value;
IconChanged(this, EventArgs.Empty);
OnIconChanged(EventArgs.Empty);
}
}
}
}
public string Title
public override string Title
{
get
{
@ -671,7 +654,7 @@ namespace OpenTK.Platform.SDL2
}
}
public bool Focused
public override bool Focused
{
get
{
@ -679,7 +662,7 @@ namespace OpenTK.Platform.SDL2
}
}
public bool Visible
public override bool Visible
{
get
{
@ -700,7 +683,7 @@ namespace OpenTK.Platform.SDL2
}
}
public bool Exists
public override bool Exists
{
get
{
@ -708,7 +691,7 @@ namespace OpenTK.Platform.SDL2
}
}
public IWindowInfo WindowInfo
public override IWindowInfo WindowInfo
{
get
{
@ -716,7 +699,7 @@ namespace OpenTK.Platform.SDL2
}
}
public WindowState WindowState
public override WindowState WindowState
{
get
{
@ -774,7 +757,7 @@ namespace OpenTK.Platform.SDL2
}
}
public WindowBorder WindowBorder
public override WindowBorder WindowBorder
{
get
{
@ -810,13 +793,13 @@ namespace OpenTK.Platform.SDL2
if (Exists)
{
WindowBorderChanged(this, EventArgs.Empty);
OnWindowBorderChanged(EventArgs.Empty);
}
}
}
}
public Rectangle Bounds
public override Rectangle Bounds
{
get
{
@ -829,7 +812,7 @@ namespace OpenTK.Platform.SDL2
}
}
public Point Location
public override Point Location
{
get
{
@ -856,7 +839,7 @@ namespace OpenTK.Platform.SDL2
}
}
public Size Size
public override Size Size
{
get
{
@ -883,67 +866,7 @@ namespace OpenTK.Platform.SDL2
}
}
public int X
{
get
{
return Location.X;
}
set
{
Location = new Point(value, Y);
}
}
public int Y
{
get
{
return Location.Y;
}
set
{
Location = new Point(X, value);
}
}
public int Width
{
get
{
return ClientSize.Width;
}
set
{
ClientSize = new Size(value, Height);
}
}
public int Height
{
get
{
return ClientSize.Height;
}
set
{
ClientSize = new Size(Width, value);
}
}
public Rectangle ClientRectangle
{
get
{
return new Rectangle(new Point(), ClientSize);
}
set
{
ClientSize = value.Size;
}
}
public Size ClientSize
public override Size ClientSize
{
get
{
@ -967,7 +890,7 @@ namespace OpenTK.Platform.SDL2
}
}
public IInputDriver InputDriver
public override IInputDriver InputDriver
{
get
{
@ -975,7 +898,7 @@ namespace OpenTK.Platform.SDL2
}
}
public bool CursorVisible
public override bool CursorVisible
{
get
{
@ -1043,7 +966,7 @@ namespace OpenTK.Platform.SDL2
#region IDisposable implementation
void Dispose(bool manual)
protected override void Dispose(bool manual)
{
if (!disposed)
{
@ -1082,17 +1005,6 @@ namespace OpenTK.Platform.SDL2
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~Sdl2NativeWindow()
{
Dispose(true);
}
#endregion
}
}

View file

@ -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 : INativeWindow, IInputDriver
internal sealed class WinGLNative : NativeWindowBase, IInputDriver
{
#region Fields
@ -977,7 +977,7 @@ namespace OpenTK.Platform.Windows
#region Bounds
public Rectangle Bounds
public override Rectangle Bounds
{
get { return bounds; }
set
@ -1042,7 +1042,7 @@ namespace OpenTK.Platform.Windows
#region ClientSize
public Size ClientSize
public override Size ClientSize
{
get
{
@ -1101,7 +1101,7 @@ namespace OpenTK.Platform.Windows
#region Icon
public Icon Icon
public override Icon Icon
{
get
{
@ -1126,7 +1126,7 @@ namespace OpenTK.Platform.Windows
#region Focused
public bool Focused
public override bool Focused
{
get { return focused; }
}
@ -1136,7 +1136,7 @@ namespace OpenTK.Platform.Windows
#region Title
StringBuilder sb_title = new StringBuilder(256);
public string Title
public override string Title
{
get
{
@ -1160,7 +1160,7 @@ namespace OpenTK.Platform.Windows
#region Visible
public bool Visible
public override bool Visible
{
get
{
@ -1193,13 +1193,13 @@ namespace OpenTK.Platform.Windows
#region Exists
public bool Exists { get { return exists; } }
public override bool Exists { get { return exists; } }
#endregion
#region Cursor
public MouseCursor Cursor
public override MouseCursor Cursor
{
get
{
@ -1270,8 +1270,8 @@ namespace OpenTK.Platform.Windows
#endregion
#region CursorVisible
public bool CursorVisible
public override bool CursorVisible
{
get { return cursor_visible_count >= 0; } // Not used
set
@ -1303,7 +1303,7 @@ namespace OpenTK.Platform.Windows
#region Close
public void Close()
public override void Close()
{
Functions.PostMessage(window.Handle, WindowMessage.CLOSE, IntPtr.Zero, IntPtr.Zero);
}
@ -1312,7 +1312,7 @@ namespace OpenTK.Platform.Windows
#region public WindowState WindowState
public WindowState WindowState
public override WindowState WindowState
{
get
{
@ -1406,7 +1406,7 @@ namespace OpenTK.Platform.Windows
#region public WindowBorder WindowBorder
public WindowBorder WindowBorder
public override WindowBorder WindowBorder
{
get
{
@ -1500,7 +1500,7 @@ namespace OpenTK.Platform.Windows
#region PointToClient
public Point PointToClient(Point point)
public override Point PointToClient(Point point)
{
if (!Functions.ScreenToClient(window.Handle, ref point))
throw new InvalidOperationException(String.Format(
@ -1514,7 +1514,7 @@ namespace OpenTK.Platform.Windows
#region PointToScreen
public Point PointToScreen(Point point)
public override Point PointToScreen(Point point)
{
if (!Functions.ClientToScreen(window.Handle, ref point))
throw new InvalidOperationException(String.Format(
@ -1554,7 +1554,7 @@ namespace OpenTK.Platform.Windows
#region public void ProcessEvents()
MSG msg;
public void ProcessEvents()
public override void ProcessEvents()
{
while (Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, PeekMessageFlags.Remove))
{
@ -1576,7 +1576,7 @@ namespace OpenTK.Platform.Windows
#region public IWindowInfo WindowInfo
public IWindowInfo WindowInfo
public override IWindowInfo WindowInfo
{
get { return child_window; }
}
@ -1640,7 +1640,7 @@ namespace OpenTK.Platform.Windows
GC.SuppressFinalize(this);
}
void Dispose(bool calledManually)
protected override void Dispose(bool calledManually)
{
if (!disposed)
{
@ -1667,11 +1667,6 @@ namespace OpenTK.Platform.Windows
}
}
~WinGLNative()
{
Dispose(false);
}
#endregion
}
}

View file

@ -45,7 +45,7 @@ namespace OpenTK.Platform.X11
/// Drives GameWindow on X11.
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
/// </summary>
internal sealed class X11GLNative : INativeWindow, IDisposable
internal sealed class X11GLNative : NativeWindowBase
{
// TODO: Disable screensaver.
// TODO: What happens if we can't disable decorations through motif?
@ -785,7 +785,7 @@ namespace OpenTK.Platform.X11
#region ProcessEvents
public void ProcessEvents()
public override void ProcessEvents()
{
// Process all pending events
while (Exists && window != null)
@ -1015,7 +1015,7 @@ namespace OpenTK.Platform.X11
#region Bounds
public Rectangle Bounds
public override Rectangle Bounds
{
get
{
@ -1116,7 +1116,7 @@ namespace OpenTK.Platform.X11
#region ClientSize
public Size ClientSize
public override Size ClientSize
{
get
{
@ -1172,7 +1172,7 @@ namespace OpenTK.Platform.X11
#region Icon
public Icon Icon
public override Icon Icon
{
get
{
@ -1246,7 +1246,7 @@ namespace OpenTK.Platform.X11
#region Focused
public bool Focused
public override bool Focused
{
get
{
@ -1258,7 +1258,7 @@ namespace OpenTK.Platform.X11
#region WindowState
public OpenTK.WindowState WindowState
public override OpenTK.WindowState WindowState
{
get
{
@ -1395,7 +1395,7 @@ namespace OpenTK.Platform.X11
#region WindowBorder
public OpenTK.WindowBorder WindowBorder
public override OpenTK.WindowBorder WindowBorder
{
get
{
@ -1465,7 +1465,7 @@ namespace OpenTK.Platform.X11
#region Cursor
public MouseCursor Cursor
public override MouseCursor Cursor
{
get
{
@ -1505,7 +1505,7 @@ namespace OpenTK.Platform.X11
#region CursorVisible
public bool CursorVisible
public override bool CursorVisible
{
get { return cursor_visible; }
set
@ -1552,7 +1552,7 @@ namespace OpenTK.Platform.X11
/// <summary>
/// Returns true if a render window/context exists.
/// </summary>
public bool Exists
public override bool Exists
{
get { return exists; }
}
@ -1586,7 +1586,7 @@ namespace OpenTK.Platform.X11
/// TODO: Use atoms for this property.
/// Gets or sets the GameWindow title.
/// </summary>
public string Title
public override string Title
{
get
{
@ -1618,7 +1618,7 @@ namespace OpenTK.Platform.X11
#region public bool Visible
public bool Visible
public override bool Visible
{
get
{
@ -1647,14 +1647,14 @@ namespace OpenTK.Platform.X11
#region public IWindowInfo WindowInfo
public IWindowInfo WindowInfo
public override IWindowInfo WindowInfo
{
get { return window; }
}
#endregion
public void Close() { Exit(); }
public override void Close() { Exit(); }
#region public void Exit()
@ -1691,7 +1691,7 @@ namespace OpenTK.Platform.X11
#region PointToClient
public Point PointToClient(Point point)
public override Point PointToClient(Point point)
{
int ox, oy;
IntPtr child;
@ -1711,7 +1711,7 @@ namespace OpenTK.Platform.X11
#region PointToScreen
public Point PointToScreen(Point point)
public override Point PointToScreen(Point point)
{
int ox, oy;
IntPtr child;
@ -1733,13 +1733,7 @@ namespace OpenTK.Platform.X11
#region IDisposable Members
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool manuallyCalled)
protected override void Dispose(bool manuallyCalled)
{
if (!disposed)
{
@ -1775,11 +1769,6 @@ namespace OpenTK.Platform.X11
}
}
~X11GLNative()
{
this.Dispose(false);
}
#endregion
}
}