Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region --- License ---
2
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
3
 * See license.txt for license info
4
 */
5
#endregion
6
 
7
using System;
8
using System.Collections.Generic;
9
using System.Text;
10
 
11
using OpenTK.Input;
12
using OpenTK.Platform;
13
 
14
namespace OpenTK
15
{
16
    internal class InputDriver : IInputDriver
17
    {
18
        private IInputDriver inputDriver;
19
 
20
        #region --- Constructors ---
21
 
22
        public InputDriver(GameWindow parent)
23
        {
24
            if (parent == null)
25
                throw new ArgumentException("A valid window (IWindowInfo) must be specified to construct an InputDriver");
26
 
27
            switch (Environment.OSVersion.Platform)
28
            {
29
                case PlatformID.Win32Windows:
30
                case PlatformID.Win32NT:
31
                case PlatformID.Win32S:
32
                case PlatformID.WinCE:
33
                    if (Environment.OSVersion.Version.Major > 5 ||
34
                        (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
35
                    {
36
                        inputDriver = new OpenTK.Platform.Windows.WinRawInput((OpenTK.Platform.Windows.WinWindowInfo)parent.WindowInfo);
37
                    }
38
                    else
39
                    {
40
                        // Legacy or unknown windows version:
41
                        inputDriver = new OpenTK.Platform.Windows.WMInput((OpenTK.Platform.Windows.WinWindowInfo)parent.WindowInfo);
42
                    }
43
                    break;
44
 
45
                case PlatformID.Unix:
46
                    // TODO: Input is currently handled asychronously by the driver in X11GLNative.
47
                    //inputDriver = new OpenTK.Platform.X11.X11Input(parent.WindowInfo);
48
 
49
                    break;
50
 
51
                default:
52
                    throw new PlatformNotSupportedException(
53
    "Input handling is not supported on the current platform. Please report the problem to http://opentk.sourceforge.net");
54
 
55
            }
56
        }
57
 
58
        #endregion
59
 
60
        #region --- IInputDriver Members ---
61
 
62
        public void Poll()
63
        {
64
            inputDriver.Poll();
65
        }
66
 
67
        #endregion
68
 
69
        #region --- IKeyboardDriver Members ---
70
 
71
        public IList<KeyboardDevice> Keyboard
72
        {
73
            get { return inputDriver.Keyboard; }
74
        }
75
 
76
        #endregion
77
 
78
        #region --- IMouseDriver Members ---
79
 
80
        public IList<MouseDevice> Mouse
81
        {
82
            get { return inputDriver.Mouse; }
83
        }
84
 
85
        #endregion
86
 
87
        #region --- IJoystickDriver Members ---
88
 
89
        public IList<JoystickDevice> Joysticks
90
        {
91
            get { return inputDriver.Joysticks; }
92
        }
93
 
94
        #endregion
95
 
96
        #region --- IDisposable Members ---
97
 
98
        private bool disposed;
99
 
100
        public void Dispose()
101
        {
102
            this.Dispose(true);
103
            GC.SuppressFinalize(this);
104
        }
105
 
106
        private void Dispose(bool manual)
107
        {
108
            if (!disposed)
109
            {
110
                if (manual)
111
                {
112
                    inputDriver.Dispose();
113
                }
114
 
115
                disposed = true;
116
            }
117
        }
118
 
119
        ~InputDriver()
120
        {
121
            this.Dispose(false);
122
        }
123
 
124
        #endregion
125
    }
126
}