2007-08-10 09:27:13 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-08-03 00:14:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
using OpenTK.Input;
|
2007-08-05 13:42:31 +00:00
|
|
|
|
using OpenTK.Platform;
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
namespace OpenTK
|
|
|
|
|
{
|
2007-11-10 18:26:14 +00:00
|
|
|
|
internal class InputDriver : IInputDriver
|
2007-08-03 00:14:31 +00:00
|
|
|
|
{
|
2007-08-22 00:30:16 +00:00
|
|
|
|
private IInputDriver inputDriver;
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
2007-08-10 16:55:24 +00:00
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
2007-09-26 11:52:40 +00:00
|
|
|
|
public InputDriver(GameWindow parent)
|
2007-08-03 00:14:31 +00:00
|
|
|
|
{
|
2007-09-21 20:05:56 +00:00
|
|
|
|
if (parent == null)
|
|
|
|
|
throw new ArgumentException("A valid window (IWindowInfo) must be specified to construct an InputDriver");
|
|
|
|
|
|
2007-10-19 20:01:41 +00:00
|
|
|
|
switch (Environment.OSVersion.Platform)
|
2007-08-03 00:14:31 +00:00
|
|
|
|
{
|
2007-10-19 20:01:41 +00:00
|
|
|
|
case PlatformID.Win32Windows:
|
|
|
|
|
case PlatformID.Win32NT:
|
|
|
|
|
case PlatformID.Win32S:
|
|
|
|
|
case PlatformID.WinCE:
|
|
|
|
|
if (Environment.OSVersion.Version.Major > 5 ||
|
2007-11-10 18:26:14 +00:00
|
|
|
|
(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
|
2007-10-19 20:01:41 +00:00
|
|
|
|
{
|
2008-02-28 13:57:07 +00:00
|
|
|
|
inputDriver = new OpenTK.Platform.Windows.WinRawInput((OpenTK.Platform.Windows.WinWindowInfo)parent.WindowInfo);
|
2007-10-19 20:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Legacy or unknown windows version:
|
2008-02-28 13:57:07 +00:00
|
|
|
|
inputDriver = new OpenTK.Platform.Windows.WMInput((OpenTK.Platform.Windows.WinWindowInfo)parent.WindowInfo);
|
2007-10-19 20:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PlatformID.Unix:
|
2007-11-10 18:26:14 +00:00
|
|
|
|
// TODO: Input is currently handled asychronously by the driver in X11GLNative.
|
|
|
|
|
//inputDriver = new OpenTK.Platform.X11.X11Input(parent.WindowInfo);
|
|
|
|
|
|
2007-10-19 20:01:41 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new PlatformNotSupportedException(
|
|
|
|
|
"Input handling is not supported on the current platform. Please report the problem to http://opentk.sourceforge.net");
|
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-10 16:55:24 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
#region --- IInputDriver Members ---
|
|
|
|
|
|
2007-09-26 11:52:40 +00:00
|
|
|
|
public IList<KeyboardDevice> Keyboard
|
2007-08-03 00:14:31 +00:00
|
|
|
|
{
|
2007-08-04 13:28:16 +00:00
|
|
|
|
get { return inputDriver.Keyboard; }
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:52:40 +00:00
|
|
|
|
public IList<MouseDevice> Mouse
|
2007-08-04 13:28:16 +00:00
|
|
|
|
{
|
2007-08-05 09:03:22 +00:00
|
|
|
|
get { return inputDriver.Mouse; }
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-22 13:13:17 +00:00
|
|
|
|
public void Poll()
|
2007-08-05 18:26:14 +00:00
|
|
|
|
{
|
2007-09-22 13:13:17 +00:00
|
|
|
|
inputDriver.Poll();
|
2007-08-05 18:26:14 +00:00
|
|
|
|
}
|
2007-09-21 20:05:56 +00:00
|
|
|
|
/*
|
|
|
|
|
int IMouseDriver.RegisterDevices()
|
|
|
|
|
{
|
|
|
|
|
return inputDriver.RegisterDevices();
|
|
|
|
|
}
|
|
|
|
|
*/
|
2007-08-03 00:14:31 +00:00
|
|
|
|
#endregion
|
2007-08-22 00:30:16 +00:00
|
|
|
|
|
|
|
|
|
#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
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|