Applied kvark's latest NativeWindow/GameWindow patch, which improves event handling, the shutdown sequence and documentation, while removing stale code.
This commit is contained in:
parent
6b03992812
commit
c730a706a6
2 changed files with 218 additions and 281 deletions
|
@ -79,11 +79,8 @@ namespace OpenTK
|
|||
|
||||
IGraphicsContext glContext;
|
||||
|
||||
bool hasMainLoop;
|
||||
bool isExiting = false;
|
||||
|
||||
int main_loop_thread_id;
|
||||
|
||||
double update_period, render_period;
|
||||
double target_update_period, target_render_period;
|
||||
// TODO: Implement these:
|
||||
|
@ -213,7 +210,6 @@ namespace OpenTK
|
|||
VSync = VSyncMode.On;
|
||||
|
||||
//glWindow.WindowInfoChanged += delegate(object sender, EventArgs e) { OnWindowInfoChangedInternal(e); };
|
||||
EnableEvents();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -236,7 +232,7 @@ namespace OpenTK
|
|||
/// <summary>
|
||||
/// Disposes of the GameWindow, releasing all resources consumed by it.
|
||||
/// </summary>
|
||||
public new void Dispose()
|
||||
public override void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -244,14 +240,16 @@ namespace OpenTK
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (!IsDisposed())
|
||||
try
|
||||
{
|
||||
if (glContext != null)
|
||||
{
|
||||
glContext.Dispose();
|
||||
glContext = null;
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
@ -271,6 +269,7 @@ namespace OpenTK
|
|||
/// </remarks>
|
||||
public virtual void Exit()
|
||||
{
|
||||
isExiting = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
@ -292,13 +291,12 @@ namespace OpenTK
|
|||
#region OnLoad
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after establishing an OpenGL context, but before entering the main loop.
|
||||
/// Override to load resources that should be maintained for the lifetime of the application.
|
||||
/// Called after an OpenGL context has been established, but before entering the main loop.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
public virtual void OnLoad(EventArgs e)
|
||||
{
|
||||
EnsureUndisposed(); //if (disposed) throw new ObjectDisposedException("GameWindow"); // What is the exact purpose?
|
||||
if (Load != null) Load(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -306,13 +304,12 @@ namespace OpenTK
|
|||
#region OnUnload
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after after calling GameWindow.Exit, but before destroying the OpenGL context.
|
||||
/// Override to unload application resources.
|
||||
/// Called after GameWindow.Exit was called, but before destroying the OpenGL context.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
public virtual void OnUnload(EventArgs e)
|
||||
{
|
||||
EnsureUndisposed(); //if (disposed) throw new ObjectDisposedException("GameWindow"); // What is the exact purpose?
|
||||
if (Unload != null) Unload(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -363,10 +360,6 @@ namespace OpenTK
|
|||
|
||||
try
|
||||
{
|
||||
// Necessary to be here, otherwise Exit() wouldn't work correctly when called inside OnLoad().
|
||||
hasMainLoop = true;
|
||||
main_loop_thread_id = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
if (updates_per_second < 0.0 || updates_per_second > 200.0)
|
||||
throw new ArgumentOutOfRangeException("updates_per_second", updates_per_second,
|
||||
"Parameter should be inside the range [0.0, 200.0]");
|
||||
|
@ -389,7 +382,7 @@ namespace OpenTK
|
|||
OnLoadInternal(EventArgs.Empty);
|
||||
|
||||
Debug.Print("Entering main loop.");
|
||||
while (!IsExiting && Exists && HasMainLoop)
|
||||
while (!IsExiting && Exists)
|
||||
{
|
||||
ProcessEvents();
|
||||
|
||||
|
@ -897,26 +890,32 @@ namespace OpenTK
|
|||
#region OnRenderFrame
|
||||
|
||||
/// <summary>
|
||||
/// Override in derived classes to render a frame.
|
||||
/// Called when the frame is rendered.
|
||||
/// </summary>
|
||||
/// <param name="e">Contains information necessary for frame rendering.</param>
|
||||
/// <remarks>
|
||||
/// The base implementation (base.OnRenderFrame) is empty, there is no need to call it.
|
||||
/// Subscribe to the <see cref="RenderFrame"/> event instead of overriding this method.
|
||||
/// </remarks>
|
||||
protected virtual void OnRenderFrame(FrameEventArgs e) { }
|
||||
protected virtual void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
if (RenderFrame != null) RenderFrame(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUpdateFrame
|
||||
|
||||
/// <summary>
|
||||
/// Override in derived classes to update a frame.
|
||||
/// Called when the frame is updated.
|
||||
/// </summary>
|
||||
/// <param name="e">Contains information necessary for frame updating.</param>
|
||||
/// <remarks>
|
||||
/// The base implementation (base.OnUpdateFrame) is empty, there is no need to call it.
|
||||
/// Subscribe to the <see cref="UpdateFrame"/> event instead of overriding this method.
|
||||
/// </remarks>
|
||||
protected virtual void OnUpdateFrame(FrameEventArgs e) { }
|
||||
protected virtual void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (UpdateFrame != null) UpdateFrame(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -932,57 +931,13 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- Assembly Members ---
|
||||
|
||||
#region Methods
|
||||
|
||||
#region ExitAsync
|
||||
|
||||
// Gracefully exits the GameWindow. May be called from any thread.
|
||||
void ExitAsync()
|
||||
{
|
||||
HasMainLoop = false;
|
||||
isExiting = true;
|
||||
//UpdateFrame += delegate
|
||||
//{
|
||||
// ExitInternal();
|
||||
//};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#region HasMainLoop
|
||||
|
||||
bool HasMainLoop
|
||||
{
|
||||
get { return hasMainLoop; }
|
||||
set { hasMainLoop = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Private Members ---
|
||||
|
||||
#region OnLoadInternal
|
||||
|
||||
/// <summary>
|
||||
/// Raises the Load event, and calls the user's OnLoad override.
|
||||
/// </summary>
|
||||
/// <param name="e">The event data.</param>
|
||||
private void OnLoadInternal(EventArgs e)
|
||||
{
|
||||
OnResize(EventArgs.Empty);
|
||||
|
||||
if (Load != null) Load(this, e);
|
||||
|
||||
OnLoad(e);
|
||||
}
|
||||
|
||||
|
@ -990,46 +945,19 @@ namespace OpenTK
|
|||
|
||||
#region OnRenderFrameInternal
|
||||
|
||||
private void OnRenderFrameInternal(FrameEventArgs e)
|
||||
{
|
||||
EnsureUndisposed();
|
||||
|
||||
if (!this.Exists || this.IsExiting) return; // TODO: Redundant because of EnsureUndisposed.
|
||||
|
||||
if (RenderFrame != null) RenderFrame(this, e);
|
||||
|
||||
OnRenderFrame(e);
|
||||
}
|
||||
private void OnRenderFrameInternal(FrameEventArgs e) { if (Exists && !isExiting) OnRenderFrame(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUnloadInternal
|
||||
|
||||
/// <summary>
|
||||
/// Raises the Unload event, and calls the user's OnUnload override.
|
||||
/// </summary>
|
||||
/// <param name="e">The event data.</param>
|
||||
private void OnUnloadInternal(EventArgs e)
|
||||
{
|
||||
if (Unload != null) Unload(this, e);
|
||||
|
||||
OnUnload(e);
|
||||
}
|
||||
private void OnUnloadInternal(EventArgs e) { OnUnload(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUpdateFrameInternal
|
||||
|
||||
private void OnUpdateFrameInternal(FrameEventArgs e)
|
||||
{
|
||||
EnsureUndisposed();
|
||||
|
||||
if (!this.Exists || this.IsExiting) return; // TODO: Redundant because of EnsureUndisposed.
|
||||
|
||||
if (UpdateFrame != null) UpdateFrame(this, e);
|
||||
|
||||
OnUpdateFrame(e);
|
||||
}
|
||||
private void OnUpdateFrameInternal(FrameEventArgs e) { if (Exists && !isExiting) OnUpdateFrame(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -1045,14 +973,6 @@ namespace OpenTK
|
|||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
///// <summary>Finalizes unmanaged resources consumed by the GameWindow.</summary>
|
||||
//~GameWindow()
|
||||
//{
|
||||
// Dispose(false);
|
||||
// DisposeInternal(false);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
#region public enum VSyncMode
|
||||
|
|
|
@ -15,10 +15,14 @@ namespace OpenTK
|
|||
{
|
||||
#region --- Fields ---
|
||||
|
||||
private bool disposed;
|
||||
private readonly GameWindowFlags options;
|
||||
|
||||
private readonly DisplayDevice device;
|
||||
|
||||
private readonly INativeWindow implementation;
|
||||
|
||||
private bool disposed, events;
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Contructors ---
|
||||
|
@ -27,16 +31,7 @@ namespace OpenTK
|
|||
|
||||
/// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary>
|
||||
public NativeWindow()
|
||||
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default, false) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region
|
||||
|
||||
/// <summary>Constructs a new NativeWindow with default attributes.</summary>
|
||||
/// <param name="enableEvents">Indicates to enable event processing as part of the NativeWindow construction.</param>
|
||||
public NativeWindow(bool enableEvents)
|
||||
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default, enableEvents) { }
|
||||
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default) { }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -44,7 +39,7 @@ namespace OpenTK
|
|||
|
||||
#region NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
|
||||
|
||||
/// <summary>Constructs a new centered NativeWindow with the specified attributes without enabling events.</summary>
|
||||
/// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the NativeWindow in pixels.</param>
|
||||
/// <param name="height">The height of the NativeWindow in pixels.</param>
|
||||
/// <param name="title">The title of the NativeWindow.</param>
|
||||
|
@ -54,32 +49,15 @@ namespace OpenTK
|
|||
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
|
||||
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
|
||||
public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
|
||||
: this(width, height, title, options, mode, device, false) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
|
||||
|
||||
/// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
|
||||
/// <param name="width">The width of the NativeWindow in pixels.</param>
|
||||
/// <param name="height">The height of the NativeWindow in pixels.</param>
|
||||
/// <param name="title">The title of the NativeWindow.</param>
|
||||
/// <param name="options">GameWindow options specifying window appearance and behavior.</param>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
|
||||
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
|
||||
/// <param name="enableEvents">Indicates to enable event processing as part of the NativeWindow construction.</param>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
|
||||
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
|
||||
public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
|
||||
: this(device.Bounds.Left + (device.Bounds.Width - width) / 2,
|
||||
device.Bounds.Top + (device.Bounds.Height - height) / 2,
|
||||
width, height, title, options, mode, device, enableEvents) { }
|
||||
width, height, title, options, mode, device) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region NativeWindow0(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
|
||||
#region NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
|
||||
|
||||
/// <summary>Constructs a new NativeWindow with the specified attributes without enabling events.</summary>
|
||||
/// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
|
||||
/// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
|
||||
/// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
|
||||
/// <param name="width">The width of the NativeWindow in pixels.</param>
|
||||
|
@ -91,25 +69,6 @@ namespace OpenTK
|
|||
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
|
||||
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
|
||||
public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
|
||||
: this(x, y, width, height, title, options, mode, device, false) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region NativeWindow0(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
|
||||
|
||||
/// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
|
||||
/// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
|
||||
/// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
|
||||
/// <param name="width">The width of the NativeWindow in pixels.</param>
|
||||
/// <param name="height">The height of the NativeWindow in pixels.</param>
|
||||
/// <param name="title">The title of the NativeWindow.</param>
|
||||
/// <param name="options">GameWindow options specifying window appearance and behavior.</param>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
|
||||
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
|
||||
/// <param name="enableEvents">Indicates to enable event processing as part of the NativeWindow construction.</param>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
|
||||
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
|
||||
public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device, bool enableEvents)
|
||||
{
|
||||
// TODO: Should a constraint be added for the position?
|
||||
if (width < 1)
|
||||
|
@ -121,15 +80,16 @@ namespace OpenTK
|
|||
if (device == null)
|
||||
throw new ArgumentNullException("device");
|
||||
|
||||
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, device);
|
||||
this.options = options;
|
||||
this.device = device;
|
||||
|
||||
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
|
||||
|
||||
if ((options & GameWindowFlags.Fullscreen) != 0)
|
||||
{
|
||||
device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
|
||||
this.device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
|
||||
WindowState = WindowState.Fullscreen;
|
||||
}
|
||||
|
||||
if (enableEvents) EnableEvents();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -201,8 +161,7 @@ namespace OpenTK
|
|||
/// </summary>
|
||||
public void ProcessEvents()
|
||||
{
|
||||
EnsureUndisposed();
|
||||
implementation.ProcessEvents();
|
||||
ProcessEvents(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -616,10 +575,15 @@ namespace OpenTK
|
|||
/// <summary>
|
||||
/// Releases all non-managed resources belonging to this NativeWindow.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if ((options & GameWindowFlags.Fullscreen) != 0)
|
||||
{
|
||||
//if (WindowState == WindowState.Fullscreen) WindowState = WindowState.Normal; // TODO: Revise.
|
||||
device.RestoreResolution();
|
||||
}
|
||||
implementation.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
|
@ -635,52 +599,6 @@ namespace OpenTK
|
|||
|
||||
#region Methods
|
||||
|
||||
#region DisableEvents
|
||||
|
||||
/// <summary>
|
||||
/// Disables the propagation of OS events.
|
||||
/// </summary>
|
||||
protected void DisableEvents()
|
||||
{
|
||||
EnsureUndisposed();
|
||||
implementation.Closed -= OnClosedInternal;
|
||||
implementation.Closing -= OnClosingInternal;
|
||||
implementation.Disposed -= OnDisposedInternal;
|
||||
implementation.FocusedChanged -= OnFocusedChangedInternal;
|
||||
implementation.KeyPress -= OnKeyPressInternal;
|
||||
implementation.Move -= OnMoveInternal;
|
||||
implementation.Resize -= OnResizeInternal;
|
||||
implementation.TitleChanged -= OnTitleChangedInternal;
|
||||
implementation.VisibleChanged -= OnVisibleChangedInternal;
|
||||
implementation.WindowBorderChanged -= OnWindowBorderChangedInternal;
|
||||
implementation.WindowStateChanged -= OnWindowStateChangedInternal;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region EnableEvents
|
||||
|
||||
/// <summary>
|
||||
/// Enables the propagation of OS events.
|
||||
/// </summary>
|
||||
protected void EnableEvents()
|
||||
{
|
||||
EnsureUndisposed();
|
||||
implementation.Closed += OnClosedInternal;
|
||||
implementation.Closing += OnClosingInternal;
|
||||
implementation.Disposed += OnDisposedInternal;
|
||||
implementation.FocusedChanged += OnFocusedChangedInternal;
|
||||
implementation.KeyPress += OnKeyPressInternal;
|
||||
implementation.Move += OnMoveInternal;
|
||||
implementation.Resize += OnResizeInternal;
|
||||
implementation.TitleChanged += OnTitleChangedInternal;
|
||||
implementation.VisibleChanged += OnVisibleChangedInternal;
|
||||
implementation.WindowBorderChanged += OnWindowBorderChangedInternal;
|
||||
implementation.WindowStateChanged += OnWindowStateChangedInternal;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region EnsureUndisposed
|
||||
|
||||
/// <summary>
|
||||
|
@ -711,7 +629,10 @@ namespace OpenTK
|
|||
/// Called when the NativeWindow has closed.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnClosed(EventArgs e) { }
|
||||
protected virtual void OnClosed(EventArgs e)
|
||||
{
|
||||
if (Closed != null) Closed(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -723,7 +644,49 @@ namespace OpenTK
|
|||
/// <param name="e">
|
||||
/// The <see cref="System.ComponentModel.CancelEventArgs" /> for this event.
|
||||
/// Set e.Cancel to true in order to stop the NativeWindow from closing.</param>
|
||||
protected virtual void OnClosing(CancelEventArgs e) { }
|
||||
protected virtual void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
if (Closing != null) Closing(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnDisposed
|
||||
|
||||
/// <summary>
|
||||
/// Called when the NativeWindow is disposed.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnDisposed(EventArgs e)
|
||||
{
|
||||
if (Disposed != null) Disposed(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnFocusedChanged
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="OpenTK.INativeWindow.Focused"/> property of the NativeWindow has changed.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnFocusedChanged(EventArgs e)
|
||||
{
|
||||
if (FocusedChanged != null) FocusedChanged(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnKeyPress
|
||||
|
||||
/// <summary>
|
||||
/// Called when a character is typed.
|
||||
/// </summary>
|
||||
/// <param name="e">The <see cref="OpenTK.KeyPressEventArgs"/> for this event.</param>
|
||||
protected virtual void OnKeyPress(KeyPressEventArgs e)
|
||||
{
|
||||
if (KeyPress != null) KeyPress(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -733,7 +696,10 @@ namespace OpenTK
|
|||
/// Called when the NativeWindow is moved.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnMove(EventArgs e) { }
|
||||
protected virtual void OnMove(EventArgs e)
|
||||
{
|
||||
if (Move != null) Move(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -743,7 +709,36 @@ namespace OpenTK
|
|||
/// Called when the NativeWindow is resized.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnResize(EventArgs e) { }
|
||||
protected virtual void OnResize(EventArgs e)
|
||||
{
|
||||
if (Resize != null) Resize(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnTitleChanged
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="OpenTK.INativeWindow.Title"/> property of the NativeWindow has changed.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnTitleChanged(EventArgs e)
|
||||
{
|
||||
if (TitleChanged != null) TitleChanged(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnVisibleChanged
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="OpenTK.INativeWindow.Visible"/> property of the NativeWindow has changed.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnVisibleChanged(EventArgs e)
|
||||
{
|
||||
if (VisibleChanged != null) VisibleChanged(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -753,7 +748,10 @@ namespace OpenTK
|
|||
/// Called when the WindowBorder of this NativeWindow has changed.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnWindowBorderChanged(EventArgs e) { }
|
||||
protected virtual void OnWindowBorderChanged(EventArgs e)
|
||||
{
|
||||
if (WindowBorderChanged != null) WindowBorderChanged(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -763,7 +761,25 @@ namespace OpenTK
|
|||
/// Called when the WindowState of this NativeWindow has changed.
|
||||
/// </summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected virtual void OnWindowStateChanged(EventArgs e) { }
|
||||
protected virtual void OnWindowStateChanged(EventArgs e)
|
||||
{
|
||||
if (WindowStateChanged != null) WindowStateChanged(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ProcessEvents
|
||||
|
||||
/// <summary>
|
||||
/// Processes operating system events until the NativeWindow becomes idle.
|
||||
/// </summary>
|
||||
/// <param name="retainEvents">If true, the state of underlying system event propagation will be preserved, otherwise event propagation will be enabled if it has not been already.</param>
|
||||
protected void ProcessEvents(bool retainEvents)
|
||||
{
|
||||
EnsureUndisposed();
|
||||
if (!events) Events = true;
|
||||
implementation.ProcessEvents();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -773,133 +789,134 @@ namespace OpenTK
|
|||
|
||||
#region --- Private Members ---
|
||||
|
||||
#region Methods
|
||||
|
||||
#region OnClosedInternal
|
||||
|
||||
private void OnClosedInternal(object sender, EventArgs e)
|
||||
{
|
||||
OnClosed(e);
|
||||
|
||||
if (Closed != null) Closed(this, e);
|
||||
Events = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnClosingInternal
|
||||
|
||||
private void OnClosingInternal(object sender, CancelEventArgs e)
|
||||
{
|
||||
OnClosing(e);
|
||||
|
||||
if (Closing != null) Closing(this, e);
|
||||
|
||||
//if (!e.Cancel) Close();
|
||||
}
|
||||
private void OnClosingInternal(object sender, CancelEventArgs e) { OnClosing(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnDisposedInternal
|
||||
|
||||
private void OnDisposedInternal(object sender, EventArgs e)
|
||||
{
|
||||
// TODO: OnDisposed?
|
||||
if (Disposed != null) Disposed(this, e);
|
||||
}
|
||||
private void OnDisposedInternal(object sender, EventArgs e) { OnDisposed(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnFocusedChangedInternal
|
||||
|
||||
private void OnFocusedChangedInternal(object sender, EventArgs e)
|
||||
{
|
||||
// TODO: OnFocusedChanged?
|
||||
if (FocusedChanged != null) FocusedChanged(this, e);
|
||||
}
|
||||
private void OnFocusedChangedInternal(object sender, EventArgs e) { OnFocusedChanged(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnKeyPressInternal
|
||||
|
||||
private void OnKeyPressInternal(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
// TODO: OnKeyPress?
|
||||
if (KeyPress != null) KeyPress(this, e);
|
||||
}
|
||||
private void OnKeyPressInternal(object sender, KeyPressEventArgs e) { OnKeyPress(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnMoveInternal
|
||||
|
||||
private void OnMoveInternal(object sender, EventArgs e)
|
||||
{
|
||||
EnsureUndisposed();
|
||||
|
||||
//if (!this.Exists || this.IsExiting) return; // TODO: See EnableEvents and DisableEvents.
|
||||
|
||||
OnMove(e);
|
||||
|
||||
if (Move != null) Move(this, e);
|
||||
}
|
||||
private void OnMoveInternal(object sender, EventArgs e) { OnMove(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnResizeInternal
|
||||
|
||||
private void OnResizeInternal(object sender, EventArgs e)
|
||||
{
|
||||
EnsureUndisposed();
|
||||
|
||||
//if (!this.Exists || this.IsExiting) return; // TODO: See EnableEvents and DisableEvents.
|
||||
|
||||
OnResize(e);
|
||||
|
||||
if (Resize != null) Resize(this, e);
|
||||
}
|
||||
private void OnResizeInternal(object sender, EventArgs e) { OnResize(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnTitleChangedInternal
|
||||
|
||||
private void OnTitleChangedInternal(object sender, EventArgs e)
|
||||
{
|
||||
// TODO: OnTitleChanged?
|
||||
if (TitleChanged != null) TitleChanged(this, e);
|
||||
}
|
||||
private void OnTitleChangedInternal(object sender, EventArgs e) { OnTitleChanged(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnVisibleChangedInternal
|
||||
|
||||
private void OnVisibleChangedInternal(object sender, EventArgs e)
|
||||
{
|
||||
// TODO: OnVisibleChanged?
|
||||
if (VisibleChanged != null) VisibleChanged(this, e);
|
||||
}
|
||||
private void OnVisibleChangedInternal(object sender, EventArgs e) { OnVisibleChanged(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnWindowBorderChangedInternal
|
||||
|
||||
private void OnWindowBorderChangedInternal(object sender, EventArgs e)
|
||||
{
|
||||
OnWindowBorderChanged(e);
|
||||
|
||||
if (WindowBorderChanged != null) WindowBorderChanged(this, e); // TODO: This was closed with EventArgs.Empty. Special reason?
|
||||
}
|
||||
private void OnWindowBorderChangedInternal(object sender, EventArgs e) { OnWindowBorderChanged(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnWindowStateChangedInternal
|
||||
|
||||
private void OnWindowStateChangedInternal(object sender, EventArgs e)
|
||||
{
|
||||
OnWindowStateChanged(e);
|
||||
private void OnWindowStateChangedInternal(object sender, EventArgs e) { OnWindowStateChanged(e); }
|
||||
|
||||
if (WindowStateChanged != null) WindowStateChanged(this, e);
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#region Events
|
||||
|
||||
private bool Events
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (events)
|
||||
{
|
||||
throw new InvalidOperationException("Event propagation is already enabled.");
|
||||
}
|
||||
implementation.Closed += OnClosedInternal;
|
||||
implementation.Closing += OnClosingInternal;
|
||||
implementation.Disposed += OnDisposedInternal;
|
||||
implementation.FocusedChanged += OnFocusedChangedInternal;
|
||||
implementation.KeyPress += OnKeyPressInternal;
|
||||
implementation.Move += OnMoveInternal;
|
||||
implementation.Resize += OnResizeInternal;
|
||||
implementation.TitleChanged += OnTitleChangedInternal;
|
||||
implementation.VisibleChanged += OnVisibleChangedInternal;
|
||||
implementation.WindowBorderChanged += OnWindowBorderChangedInternal;
|
||||
implementation.WindowStateChanged += OnWindowStateChangedInternal;
|
||||
events = true;
|
||||
}
|
||||
else if (events)
|
||||
{
|
||||
implementation.Closed -= OnClosedInternal;
|
||||
implementation.Closing -= OnClosingInternal;
|
||||
implementation.Disposed -= OnDisposedInternal;
|
||||
implementation.FocusedChanged -= OnFocusedChangedInternal;
|
||||
implementation.KeyPress -= OnKeyPressInternal;
|
||||
implementation.Move -= OnMoveInternal;
|
||||
implementation.Resize -= OnResizeInternal;
|
||||
implementation.TitleChanged -= OnTitleChangedInternal;
|
||||
implementation.VisibleChanged -= OnVisibleChangedInternal;
|
||||
implementation.WindowBorderChanged -= OnWindowBorderChangedInternal;
|
||||
implementation.WindowStateChanged -= OnWindowStateChangedInternal;
|
||||
events = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Event propagation is already disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue