Added IDisposable to all input drivers.

Updated Cube.cs to use System.Drawing.Colors.
Improved DefRawInputProc in windows API.cs
This commit is contained in:
the_fiddler 2007-08-22 00:30:16 +00:00
parent 3b6b8853c4
commit 0dbf3c04b2
9 changed files with 174 additions and 77 deletions

View file

@ -167,38 +167,38 @@ namespace Examples.WinForms
{
GL.Begin(GL.Enums.BeginMode.QUADS);
GL.Color3((byte)Color.Silver.R, (byte)Color.Silver.G, (byte)Color.Silver.B);
GL.Color3(Color.Silver);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Color3((byte)Color.Honeydew.R, (byte)Color.Honeydew.G, (byte)Color.Honeydew.B);
GL.Color3(Color.Honeydew);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Color3((byte)Color.Moccasin.R, (byte)Color.Moccasin.G, (byte)Color.Moccasin.B);
GL.Color3(Color.Moccasin);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Color3((byte)Color.IndianRed.R, (byte)Color.IndianRed.G, (byte)Color.IndianRed.B);
GL.Color3(Color.IndianRed);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Color3((byte)Color.PaleVioletRed.R, (byte)Color.PaleVioletRed.G, (byte)Color.PaleVioletRed.B);
GL.Color3(Color.PaleVioletRed);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Color3((byte)Color.ForestGreen.R, (byte)Color.ForestGreen.G, (byte)Color.ForestGreen.B);
GL.Color3(Color.ForestGreen);
GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3(1.0f, 1.0f, 1.0f);

View file

@ -10,11 +10,9 @@ using System.Text;
namespace OpenTK.Input
{
public interface IInputDriver : IKeyboardDriver, IMouseDriver
public interface IInputDriver : IKeyboardDriver, IMouseDriver, IDisposable
{
IList<IInputDevice> InputDevices { get; }
void ProcessEvents();
//IEnumerable<IMouse> Mice { get; }
//IEnumerable<IHid> Hids { get; }
}
}

View file

@ -15,7 +15,7 @@ namespace OpenTK
{
public class InputDriver : IInputDriver
{
IInputDriver inputDriver;
private IInputDriver inputDriver;
#region --- Constructors ---
@ -63,5 +63,35 @@ namespace OpenTK
}
#endregion
#region --- IDisposable Members ---
private bool disposed;
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool manual)
{
if (!disposed)
{
if (manual)
{
inputDriver.Dispose();
}
disposed = true;
}
}
~InputDriver()
{
this.Dispose(false);
}
#endregion
}
}

View file

@ -768,19 +768,28 @@ namespace OpenTK.Platform.Windows
[CLSCompliant(false)]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern LRESULT DefRawInputProc(
RawInput[] RawInput,
INT Input,
UINT SizeHeader
);
public static extern LRESULT DefRawInputProc(RawInput[] RawInput, INT Input, UINT SizeHeader);
/*
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern LRESULT DefRawInputProc(
RawInput[] RawInput,
INT Input,
INT SizeHeader
);
public static extern LRESULT DefRawInputProc(RawInput[] RawInput, INT Input, INT SizeHeader);
*/
/// <summary>
/// calls the default raw input procedure to provide default processing for
/// any raw input messages that an application does not process.
/// This function ensures that every message is processed.
/// DefRawInputProc is called with the same parameters received by the window procedure.
/// </summary>
/// <param name="RawInput">Pointer to an array of RawInput structures.</param>
/// <param name="Input">Number of RawInput structures pointed to by paRawInput.</param>
/// <param name="SizeHeader">Size, in bytes, of the RawInputHeader structure.</param>
/// <returns>If successful, the function returns S_OK. Otherwise it returns an error value.</returns>
[CLSCompliant(false)]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
unsafe public static extern LRESULT DefRawInputProc(ref RawInput RawInput, INT Input, UINT SizeHeader);
#endregion

View file

@ -281,7 +281,7 @@ namespace OpenTK.Platform.Windows
Dispose(false);
}
#region public void ReleaseResources()
#region private void ReleaseResources()
private void ReleaseResources()
{

View file

@ -333,9 +333,10 @@ namespace OpenTK.Platform.Windows
{
Debug.Print("Window handle {0} destroyed.", this.Handle);
//this.DestroyHandle(); // Destroyed automatically by DefWndProc
//this.Dispose();
exists = false;
}
API.PostQuitMessage(0);
//API.PostQuitMessage(0);
}
public event DestroyEvent Destroy;
@ -344,38 +345,6 @@ namespace OpenTK.Platform.Windows
#endregion
#region --- IDisposable Members ---
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool calledManually)
{
if (!disposed)
{
// Clean unmanaged resources here:
if (calledManually)
{
// Safe to clean managed resources
glContext.Dispose();
base.DestroyHandle();
}
disposed = true;
}
}
~WinGLNative()
{
Dispose(false);
}
#endregion
#region --- IResizable Members ---
#region public int Width
@ -453,6 +422,37 @@ namespace OpenTK.Platform.Windows
}
#endregion
#region --- IDisposable Members ---
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool calledManually)
{
if (!disposed)
{
// Clean unmanaged resources here:
if (calledManually)
{
// Safe to clean managed resources
glContext.Dispose();
base.DestroyHandle();
}
disposed = true;
}
}
~WinGLNative()
{
Dispose(false);
}
#endregion
}
#region class WindowHandle : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid

View file

@ -89,16 +89,17 @@ namespace OpenTK.Platform.Windows
switch (data.Header.Type)
{
case API.RawInputDeviceType.KEYBOARD:
keyboardDriver.ProcessKeyboardEvent(data);
break;
if (!keyboardDriver.ProcessKeyboardEvent(data))
API.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
return;
case API.RawInputDeviceType.MOUSE:
//throw new NotImplementedException();
break;
API.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
return;
case API.RawInputDeviceType.HID:
//throw new NotImplementedException();
break;
API.DefRawInputProc(ref data, 1, (uint)API.RawInputHeaderSize);
return;
}
}
else
@ -117,6 +118,7 @@ namespace OpenTK.Platform.Windows
case API.Constants.WM_QUIT:
Debug.WriteLine("Input window quit.");
this.Dispose();
break;
}
@ -137,7 +139,7 @@ namespace OpenTK.Platform.Windows
get { return keyboardDriver.Keyboard; }
}
public IList<Keyboard> Mouse
public IList<Mouse> Mouse
{
get { throw new Exception("The method or operation is not implemented."); }
}
@ -149,11 +151,32 @@ namespace OpenTK.Platform.Windows
#endregion
#region IMouseDriver Members
#region --- IDisposable Members ---
IList<Mouse> IMouseDriver.Mouse
private bool disposed;
public void Dispose()
{
get { throw new Exception("The method or operation is not implemented."); }
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool manual)
{
if (!disposed)
{
if (manual)
{
keyboardDriver.Dispose();
}
disposed = true;
}
}
~WinRawInput()
{
Dispose(false);
}
#endregion

View file

@ -18,7 +18,7 @@ using OpenTK.Input;
namespace OpenTK.Platform.Windows
{
internal class WinRawKeyboard : IKeyboardDriver
internal class WinRawKeyboard : IKeyboardDriver, IDisposable
{
private List<Keyboard> keyboards = new List<Keyboard>();
private IntPtr windowHandle;
@ -175,9 +175,7 @@ namespace OpenTK.Platform.Windows
// This is a terminal services devices, skip it.
continue;
}
else if (
ridl[i].Type == API.RawInputDeviceType.KEYBOARD ||
ridl[i].Type == API.RawInputDeviceType.HID)
else if (ridl[i].Type == API.RawInputDeviceType.KEYBOARD || ridl[i].Type == API.RawInputDeviceType.HID)
{
//It's a keyboard or a USB device that could be a keyboard
@ -283,15 +281,15 @@ namespace OpenTK.Platform.Windows
{
case API.VirtualKeys.SHIFT:
keyboards[0][Input.Key.ShiftLeft] = keyboards[0][Input.Key.ShiftRight] = pressed;
return false;
return true;
case API.VirtualKeys.CONTROL:
keyboards[0][Input.Key.ControlLeft] = keyboards[0][Input.Key.ControlRight] = pressed;
return false;
return true;
case API.VirtualKeys.MENU:
keyboards[0][Input.Key.AltLeft] = keyboards[0][Input.Key.AltRight] = pressed;
return false;
return true;
default:
if (!WinRawKeyboard.KeyMap.ContainsKey(rin.Data.Keyboard.VKey))
@ -302,7 +300,7 @@ namespace OpenTK.Platform.Windows
{
keyboards[0][WinRawKeyboard.KeyMap[rin.Data.Keyboard.VKey]] = pressed;
}
break;
return false;
}
break;
@ -336,5 +334,35 @@ namespace OpenTK.Platform.Windows
}
#endregion
#region --- IDisposable Members ---
private bool disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool manual)
{
if (!disposed)
{
if (manual)
{
//keyboards.Clear();
}
disposed = true;
}
}
~WinRawKeyboard()
{
Dispose(false);
}
#endregion
}
}

View file

@ -146,5 +146,14 @@ namespace OpenTK.Platform.X11
}
#endregion
#region --- IDisposable Members ---
public void Dispose()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
}