1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef __Input_H__
|
---|
26 | #define __Input_H__
|
---|
27 |
|
---|
28 | #include "OgrePrerequisites.h"
|
---|
29 |
|
---|
30 | namespace Ogre {
|
---|
31 |
|
---|
32 | /** Keyboard scan codes - copied from DirectInput for now for speed.
|
---|
33 | */
|
---|
34 | enum KeyCode
|
---|
35 | {
|
---|
36 | KC_ESCAPE =0x01,
|
---|
37 | KC_1 =0x02,
|
---|
38 | KC_2 =0x03,
|
---|
39 | KC_3 =0x04,
|
---|
40 | KC_4 =0x05,
|
---|
41 | KC_5 =0x06,
|
---|
42 | KC_6 =0x07,
|
---|
43 | KC_7 =0x08,
|
---|
44 | KC_8 =0x09,
|
---|
45 | KC_9 =0x0A,
|
---|
46 | KC_0 =0x0B,
|
---|
47 | KC_MINUS =0x0C, /* - on main keyboard */
|
---|
48 | KC_EQUALS =0x0D,
|
---|
49 | KC_BACK =0x0E, /* backspace */
|
---|
50 | KC_TAB =0x0F,
|
---|
51 | KC_Q =0x10,
|
---|
52 | KC_W =0x11,
|
---|
53 | KC_E =0x12,
|
---|
54 | KC_R =0x13,
|
---|
55 | KC_T =0x14,
|
---|
56 | KC_Y =0x15,
|
---|
57 | KC_U =0x16,
|
---|
58 | KC_I =0x17,
|
---|
59 | KC_O =0x18,
|
---|
60 | KC_P =0x19,
|
---|
61 | KC_LBRACKET =0x1A,
|
---|
62 | KC_RBRACKET =0x1B,
|
---|
63 | KC_RETURN =0x1C, /* Enter on main keyboard */
|
---|
64 | KC_LCONTROL =0x1D,
|
---|
65 | KC_A =0x1E,
|
---|
66 | KC_S =0x1F,
|
---|
67 | KC_D =0x20,
|
---|
68 | KC_F =0x21,
|
---|
69 | KC_G =0x22,
|
---|
70 | KC_H =0x23,
|
---|
71 | KC_J =0x24,
|
---|
72 | KC_K =0x25,
|
---|
73 | KC_L =0x26,
|
---|
74 | KC_SEMICOLON =0x27,
|
---|
75 | KC_APOSTROPHE =0x28,
|
---|
76 | KC_GRAVE =0x29, /* accent grave */
|
---|
77 | KC_LSHIFT =0x2A,
|
---|
78 | KC_BACKSLASH =0x2B,
|
---|
79 | KC_Z =0x2C,
|
---|
80 | KC_X =0x2D,
|
---|
81 | KC_C =0x2E,
|
---|
82 | KC_V =0x2F,
|
---|
83 | KC_B =0x30,
|
---|
84 | KC_N =0x31,
|
---|
85 | KC_M =0x32,
|
---|
86 | KC_COMMA =0x33,
|
---|
87 | KC_PERIOD =0x34, /* . on main keyboard */
|
---|
88 | KC_SLASH =0x35, /* '/' on main keyboard */
|
---|
89 | KC_RSHIFT =0x36,
|
---|
90 | KC_MULTIPLY =0x37, /* * on numeric keypad */
|
---|
91 | KC_LMENU =0x38, /* left Alt */
|
---|
92 | KC_SPACE =0x39,
|
---|
93 | KC_CAPITAL =0x3A,
|
---|
94 | KC_F1 =0x3B,
|
---|
95 | KC_F2 =0x3C,
|
---|
96 | KC_F3 =0x3D,
|
---|
97 | KC_F4 =0x3E,
|
---|
98 | KC_F5 =0x3F,
|
---|
99 | KC_F6 =0x40,
|
---|
100 | KC_F7 =0x41,
|
---|
101 | KC_F8 =0x42,
|
---|
102 | KC_F9 =0x43,
|
---|
103 | KC_F10 =0x44,
|
---|
104 | KC_NUMLOCK =0x45,
|
---|
105 | KC_SCROLL =0x46, /* Scroll Lock */
|
---|
106 | KC_NUMPAD7 =0x47,
|
---|
107 | KC_NUMPAD8 =0x48,
|
---|
108 | KC_NUMPAD9 =0x49,
|
---|
109 | KC_SUBTRACT =0x4A, /* - on numeric keypad */
|
---|
110 | KC_NUMPAD4 =0x4B,
|
---|
111 | KC_NUMPAD5 =0x4C,
|
---|
112 | KC_NUMPAD6 =0x4D,
|
---|
113 | KC_ADD =0x4E, /* + on numeric keypad */
|
---|
114 | KC_NUMPAD1 =0x4F,
|
---|
115 | KC_NUMPAD2 =0x50,
|
---|
116 | KC_NUMPAD3 =0x51,
|
---|
117 | KC_NUMPAD0 =0x52,
|
---|
118 | KC_DECIMAL =0x53, /* . on numeric keypad */
|
---|
119 | KC_OEM_102 =0x56, /* < > | on UK/Germany keyboards */
|
---|
120 | KC_F11 =0x57,
|
---|
121 | KC_F12 =0x58,
|
---|
122 | KC_F13 =0x64, /* (NEC PC98) */
|
---|
123 | KC_F14 =0x65, /* (NEC PC98) */
|
---|
124 | KC_F15 =0x66, /* (NEC PC98) */
|
---|
125 | KC_KANA =0x70, /* (Japanese keyboard) */
|
---|
126 | KC_ABNT_C1 =0x73, /* / ? on Portugese (Brazilian) keyboards */
|
---|
127 | KC_CONVERT =0x79, /* (Japanese keyboard) */
|
---|
128 | KC_NOCONVERT =0x7B, /* (Japanese keyboard) */
|
---|
129 | KC_YEN =0x7D, /* (Japanese keyboard) */
|
---|
130 | KC_ABNT_C2 =0x7E, /* Numpad . on Portugese (Brazilian) keyboards */
|
---|
131 | KC_NUMPADEQUALS =0x8D, /* = on numeric keypad (NEC PC98) */
|
---|
132 | KC_PREVTRACK =0x90, /* Previous Track (KC_CIRCUMFLEX on Japanese keyboard) */
|
---|
133 | KC_AT =0x91, /* (NEC PC98) */
|
---|
134 | KC_COLON =0x92, /* (NEC PC98) */
|
---|
135 | KC_UNDERLINE =0x93, /* (NEC PC98) */
|
---|
136 | KC_KANJI =0x94, /* (Japanese keyboard) */
|
---|
137 | KC_STOP =0x95, /* (NEC PC98) */
|
---|
138 | KC_AX =0x96, /* (Japan AX) */
|
---|
139 | KC_UNLABELED =0x97, /* (J3100) */
|
---|
140 | KC_NEXTTRACK =0x99, /* Next Track */
|
---|
141 | KC_NUMPADENTER =0x9C, /* Enter on numeric keypad */
|
---|
142 | KC_RCONTROL =0x9D,
|
---|
143 | KC_MUTE =0xA0, /* Mute */
|
---|
144 | KC_CALCULATOR =0xA1, /* Calculator */
|
---|
145 | KC_PLAYPAUSE =0xA2, /* Play / Pause */
|
---|
146 | KC_MEDIASTOP =0xA4, /* Media Stop */
|
---|
147 | KC_VOLUMEDOWN =0xAE, /* Volume - */
|
---|
148 | KC_VOLUMEUP =0xB0, /* Volume + */
|
---|
149 | KC_WEBHOME =0xB2, /* Web home */
|
---|
150 | KC_NUMPADCOMMA =0xB3, /* , on numeric keypad (NEC PC98) */
|
---|
151 | KC_DIVIDE =0xB5, /* / on numeric keypad */
|
---|
152 | KC_SYSRQ =0xB7,
|
---|
153 | KC_RMENU =0xB8, /* right Alt */
|
---|
154 | KC_PAUSE =0xC5, /* Pause */
|
---|
155 | KC_HOME =0xC7, /* Home on arrow keypad */
|
---|
156 | KC_UP =0xC8, /* UpArrow on arrow keypad */
|
---|
157 | KC_PGUP =0xC9, /* PgUp on arrow keypad */
|
---|
158 | KC_LEFT =0xCB, /* LeftArrow on arrow keypad */
|
---|
159 | KC_RIGHT =0xCD, /* RightArrow on arrow keypad */
|
---|
160 | KC_END =0xCF, /* End on arrow keypad */
|
---|
161 | KC_DOWN =0xD0, /* DownArrow on arrow keypad */
|
---|
162 | KC_PGDOWN =0xD1, /* PgDn on arrow keypad */
|
---|
163 | KC_INSERT =0xD2, /* Insert on arrow keypad */
|
---|
164 | KC_DELETE =0xD3, /* Delete on arrow keypad */
|
---|
165 | KC_LWIN =0xDB, /* Left Windows key */
|
---|
166 | KC_RWIN =0xDC, /* Right Windows key */
|
---|
167 | KC_APPS =0xDD, /* AppMenu key */
|
---|
168 | KC_POWER =0xDE, /* System Power */
|
---|
169 | KC_SLEEP =0xDF, /* System Sleep */
|
---|
170 | KC_WAKE =0xE3, /* System Wake */
|
---|
171 | KC_WEBSEARCH =0xE5, /* Web Search */
|
---|
172 | KC_WEBFAVORITES =0xE6, /* Web Favorites */
|
---|
173 | KC_WEBREFRESH =0xE7, /* Web Refresh */
|
---|
174 | KC_WEBSTOP =0xE8, /* Web Stop */
|
---|
175 | KC_WEBFORWARD =0xE9, /* Web Forward */
|
---|
176 | KC_WEBBACK =0xEA, /* Web Back */
|
---|
177 | KC_MYCOMPUTER =0xEB, /* My Computer */
|
---|
178 | KC_MAIL =0xEC, /* Mail */
|
---|
179 | KC_MEDIASELECT =0xED /* Media Select */
|
---|
180 | };
|
---|
181 |
|
---|
182 | /** Structure representing a snapshot of the state of the mouse
|
---|
183 | input controller. */
|
---|
184 | struct _OgreExport MouseState
|
---|
185 | {
|
---|
186 | /** Absolute position of the mouse pointer. */
|
---|
187 | long Xabs, Yabs, Zabs;
|
---|
188 | /** Relative position of the mouse pointer. */
|
---|
189 | long Xrel, Yrel, Zrel;
|
---|
190 | /** The buttons that have been pressed. Each bit maps to a mouse
|
---|
191 | button. */
|
---|
192 | long Buttons;
|
---|
193 |
|
---|
194 | /** Retrieves the pressed state of a mouse button. */
|
---|
195 | inline long isButtonDown( uchar button ) const
|
---|
196 | {
|
---|
197 | return Buttons & ( 1 << button );
|
---|
198 | }
|
---|
199 | };
|
---|
200 |
|
---|
201 | /** Abstract class which allows input to be read from various
|
---|
202 | controllers.
|
---|
203 | @remarks
|
---|
204 | You can access an appropriate concrete subclass of this interface by
|
---|
205 | calling PlatformManager::createInputReader.
|
---|
206 | @warning Temporary implementation only. This class is likely to be
|
---|
207 | refactored into a better design when I get time to look at it
|
---|
208 | properly. For now it's a quick-and-dirty way to get what I need.
|
---|
209 | @see
|
---|
210 | PlatformManager::createInputReader
|
---|
211 | */
|
---|
212 | class _OgreExport InputReader
|
---|
213 | {
|
---|
214 | public:
|
---|
215 | InputReader();
|
---|
216 | virtual ~InputReader();
|
---|
217 |
|
---|
218 | /** Tells the reader to use buffered input and update the passed in queue.
|
---|
219 | @remarks
|
---|
220 | The default behaviour of the input reader is simply to capture the
|
---|
221 | current state of the mouse / keyboard on demand. An alternative is to use
|
---|
222 | buffered input where all events are registered on a queue.
|
---|
223 | */
|
---|
224 | void useBufferedInput(EventQueue* pEventQueue, bool keys = true, bool mouse = true) ;
|
---|
225 |
|
---|
226 | virtual void setBufferedInput(bool keys, bool mouse) ;
|
---|
227 |
|
---|
228 |
|
---|
229 | /** Initialise the input system.
|
---|
230 | @note
|
---|
231 | Only keyboard and mouse currently implemented.
|
---|
232 | @param
|
---|
233 | pWindow The window to capture input for
|
---|
234 | @param
|
---|
235 | useKeyboard If true, keyboard input will be supported.
|
---|
236 | @param
|
---|
237 | useMouse If true, mouse input will be supported.
|
---|
238 | @param
|
---|
239 | useGameController If true, joysticks/gamepads will be supported.
|
---|
240 | */
|
---|
241 | virtual void initialise(
|
---|
242 | RenderWindow* pWindow,
|
---|
243 | bool useKeyboard = true,
|
---|
244 | bool useMouse = true,
|
---|
245 | bool useGameController = false ) = 0;
|
---|
246 |
|
---|
247 | /** Captures the state of all the input devices.
|
---|
248 | @remarks
|
---|
249 | This method captures the state of all input devices and
|
---|
250 | stores it internally for use when the enquiry methods are
|
---|
251 | next called. This is done to ensure that all input is
|
---|
252 | captured at once and therefore combinations of input are not
|
---|
253 | subject to time differences when methods are called.
|
---|
254 |
|
---|
255 | */
|
---|
256 | virtual void capture() = 0;
|
---|
257 |
|
---|
258 | /** Determines if the specified key is currently depressed.
|
---|
259 | @note In immediate mode, this enquiry method uses the state of the
|
---|
260 | keyboard at the last 'capture' call.
|
---|
261 | */
|
---|
262 | virtual bool isKeyDown( KeyCode kc ) const;
|
---|
263 |
|
---|
264 | /** Retrieves the relative position of the mouse when capture was
|
---|
265 | called relative to the last time. */
|
---|
266 | virtual long getMouseRelativeX() const { return getMouseRelX(); }
|
---|
267 |
|
---|
268 | /** Retrieves the relative position of the mouse when capture was
|
---|
269 | called relative to the last time. */
|
---|
270 | virtual long getMouseRelativeY() const { return getMouseRelY(); }
|
---|
271 |
|
---|
272 | /** Retrieves the relative position of the mouse when capture was
|
---|
273 | called relative to the last time. */
|
---|
274 | virtual long getMouseRelativeZ() const { return getMouseRelZ(); }
|
---|
275 |
|
---|
276 | /** Retrieves the relative (compared to the last input poll) mouse movement
|
---|
277 | on the X (horizontal) axis. */
|
---|
278 | virtual long getMouseRelX() const = 0;
|
---|
279 |
|
---|
280 | /** Retrieves the relative (compared to the last input poll) mouse movement
|
---|
281 | on the Y (vertical) axis. */
|
---|
282 | virtual long getMouseRelY() const = 0;
|
---|
283 |
|
---|
284 | /** Retrieves the relative (compared to the last input poll) mouse movement
|
---|
285 | on the Z (mouse wheel) axis. */
|
---|
286 | virtual long getMouseRelZ() const = 0;
|
---|
287 |
|
---|
288 | /** Retrieves the absolute mouse position on the X (horizontal) axis. */
|
---|
289 | virtual long getMouseAbsX() const = 0;
|
---|
290 | /** Retrieves the absolute mouse position on the Y (vertical) axis. */
|
---|
291 | virtual long getMouseAbsY() const = 0;
|
---|
292 | /** Retrieves the absolute mouse position on the Z (mouse wheel) axis. */
|
---|
293 | virtual long getMouseAbsZ() const = 0;
|
---|
294 |
|
---|
295 | /** Retrieves the current state of the mouse. */
|
---|
296 | virtual void getMouseState( MouseState& state ) const = 0;
|
---|
297 |
|
---|
298 | /** Retrieves the state of a mouse button. */
|
---|
299 | virtual bool getMouseButton( uchar button ) const = 0;
|
---|
300 |
|
---|
301 | /** Adds a mouse motion listener to the cursor object.
|
---|
302 | This keeps the Cursor object hidden. */
|
---|
303 | void addCursorMoveListener( MouseMotionListener* c );
|
---|
304 |
|
---|
305 | /** Remove a mouse motion listener to the cursor object.
|
---|
306 | This keeps the Cursor object hidden. */
|
---|
307 | void removeCursorMoveListener( MouseMotionListener* c );
|
---|
308 | static char getKeyChar(int keyCode, long modifiers = 0);
|
---|
309 |
|
---|
310 | /** Set mouse scale factor.
|
---|
311 | @param scale The new mouse scale (The default on is around 0.001/0.002).
|
---|
312 | */
|
---|
313 | virtual void setMouseScale( Real scale ) { mMouseScale = scale; }
|
---|
314 |
|
---|
315 | /** Get mouse scale factor.
|
---|
316 | */
|
---|
317 | virtual Real getMouseScale( void ) const { return mMouseScale; }
|
---|
318 |
|
---|
319 |
|
---|
320 |
|
---|
321 | protected:
|
---|
322 |
|
---|
323 | /** The modifiers are a binary flags that represent what buttons are pressed,
|
---|
324 | and what key modifiers are down (e.g. shift/alt). */
|
---|
325 | long mModifiers;
|
---|
326 |
|
---|
327 | /// Speed of mouse
|
---|
328 | Real mMouseScale;
|
---|
329 |
|
---|
330 | /** Internal Cursor object.
|
---|
331 | @remarks
|
---|
332 | This is a mathematical representation of where the cursor is, it does
|
---|
333 | not draw a cursor.
|
---|
334 | @see CursorGuiElement. */
|
---|
335 |
|
---|
336 | Cursor* mCursor;
|
---|
337 |
|
---|
338 | /** EventQueue is used for buffered input support. */
|
---|
339 | EventQueue* mEventQueue;
|
---|
340 |
|
---|
341 | /** Wether to use buffering input support - buffering support relies on using
|
---|
342 | an EventQueue.
|
---|
343 | @see class EventQueue */
|
---|
344 | bool mUseBufferedKeys, mUseBufferedMouse;
|
---|
345 |
|
---|
346 | /** The mouse state in immediate mode. */
|
---|
347 | MouseState mMouseState;
|
---|
348 |
|
---|
349 | /// Set of all the keys currently depressed based on buffered input events
|
---|
350 | typedef std::set<KeyCode> BufferedKeysDownSet;
|
---|
351 | BufferedKeysDownSet mBufferedKeysDown;
|
---|
352 |
|
---|
353 | /** Creates mouse moved or dragged events depending if any button is pressed. */
|
---|
354 | void mouseMoved();
|
---|
355 |
|
---|
356 | /** Creates a MouseEvent that first gets processed by the cursor, then gets
|
---|
357 | pushed on the queue. */
|
---|
358 | void createMouseEvent(int id, int button);
|
---|
359 |
|
---|
360 | /** Creates mouse pressed, released, and clicked events. */
|
---|
361 | void triggerMouseButton(int nMouseCode, bool mousePressed);
|
---|
362 |
|
---|
363 | void createKeyEvent(int id, int key);
|
---|
364 | void keyChanged(int key, bool down);
|
---|
365 |
|
---|
366 | /** Return whether a key is down in immediate mode. */
|
---|
367 | virtual bool isKeyDownImmediate( KeyCode kc ) const = 0;
|
---|
368 | };
|
---|
369 |
|
---|
370 |
|
---|
371 | /** Defines the interface a platform-specific library must implement.
|
---|
372 | @remarks
|
---|
373 | Any library (.dll, .so) wishing to implement a
|
---|
374 | platform-specific version of this input reader must export the
|
---|
375 | symbol 'createInputReader' with the signature void
|
---|
376 | createPlatformInputReader(InputReader** ppReader).
|
---|
377 | */
|
---|
378 | typedef void (*DLL_CREATEINPUTREADER)(InputReader** ppReader);
|
---|
379 |
|
---|
380 | }
|
---|
381 |
|
---|
382 | #endif
|
---|