a13efee1316eb7b81ba06dd62e144b1b75ddf8cd
[blender-staging.git] / source / gameengine / GameLogic / SCA_IInputDevice.h
1 /**
2  * Interface for input devices. The defines for keyboard/system/mouse events
3  * here are for internal use in the KX module.
4  *
5  * $Id$
6  *
7  * ***** BEGIN GPL LICENSE BLOCK *****
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL LICENSE BLOCK *****
31  */
32
33 #ifndef KX_INPUTDEVICE_H
34 #define KX_INPUTDEVICE_H
35
36 #ifdef WITH_CXX_GUARDEDALLOC
37 #include "MEM_guardedalloc.h"
38 #endif
39
40 class SCA_InputEvent 
41 {
42         
43 public:
44         enum SCA_EnumInputs {
45         
46                 KX_NO_INPUTSTATUS = 0,
47                 KX_JUSTACTIVATED,
48                 KX_ACTIVE,
49                 KX_JUSTRELEASED,
50                 KX_MAX_INPUTSTATUS
51         };
52
53         SCA_InputEvent(SCA_EnumInputs status=KX_NO_INPUTSTATUS,int eventval=0)
54                 :       m_status(status),
55                 m_eventval(eventval)
56         {
57
58         }
59
60         SCA_EnumInputs m_status;
61         int             m_eventval;
62 };
63
64 class SCA_IInputDevice 
65 {
66
67         
68 public:
69
70         SCA_IInputDevice();
71         virtual ~SCA_IInputDevice();    
72
73         enum KX_EnumInputs {
74         
75                 KX_NOKEY = 0,
76         
77                 // TIMERS 
78         
79                 KX_TIMER0,
80                 KX_TIMER1,
81                 KX_TIMER2,
82         
83                 // SYSTEM
84
85                 /* Moved to avoid clashes with KX_RETKEY */
86                 KX_KEYBD,
87                 KX_RAWKEYBD,
88                 KX_REDRAW,
89                 KX_INPUTCHANGE,
90                 KX_QFULL,
91                 KX_WINFREEZE,
92                 KX_WINTHAW,
93                 /* thaw is 11 */
94
95                 /* move past retkey*/
96                 KX_WINCLOSE = 14,
97                 KX_WINQUIT,
98                 KX_Q_FIRSTTIME,
99                 /* sequence ends on 16 */
100         
101                 // standard keyboard 
102
103                 /* Because of the above preamble, KX_BEGINKEY is 15 ! This
104                  * means that KX_RETKEY on 13d (0Dh)) will double up with
105                  * KX_WINQUIT!  Why is it 13? Because ascii 13d is Ctrl-M aka
106                  * CR! Its little brother, LF has 10d (0Ah). This is
107                  * dangerous, since the keyboards start scanning at
108                  * KX_BEGINKEY. I think the keyboard system should push its
109                  * key events instead of demanding the user to poll the
110                  * table... But that's for another time... The fix for now is
111                  * to move the above system events into a 'safe' (ie. unused)
112                  * range. I am loathe to move it away from this 'magical'
113                  * coincidence.. it's probably exploited somewhere. I hope the
114                  * close and quit events don't mess up 'normal' kb code
115                  * scanning.
116                  * */
117                 KX_BEGINKEY = 12,
118
119                 KX_RETKEY = 13,
120                 KX_SPACEKEY = 32,
121                 KX_PADASTERKEY = 42,
122                 KX_COMMAKEY = 44,               
123                 KX_MINUSKEY = 45,               
124                 KX_PERIODKEY = 46,
125                 KX_ZEROKEY = 48,
126                 
127                 KX_ONEKEY,              // =49
128                 KX_TWOKEY,              
129                 KX_THREEKEY,
130                 KX_FOURKEY,             
131                 KX_FIVEKEY,             
132                 KX_SIXKEY,              
133                 KX_SEVENKEY,
134                 KX_EIGHTKEY,
135                 KX_NINEKEY,             // = 57
136
137                 KX_AKEY = 97,
138                 KX_BKEY,
139                 KX_CKEY,
140                 KX_DKEY,
141                 KX_EKEY,
142                 KX_FKEY,
143                 KX_GKEY,
144                 KX_HKEY,
145                 KX_IKEY,
146                 KX_JKEY,
147                 KX_KKEY,
148                 KX_LKEY,
149                 KX_MKEY,
150                 KX_NKEY, // =110
151                 KX_OKEY,
152                 KX_PKEY,
153                 KX_QKEY,
154                 KX_RKEY,
155                 KX_SKEY,
156                 KX_TKEY,
157                 KX_UKEY,
158                 KX_VKEY,
159                 KX_WKEY,
160                 KX_XKEY, // =120
161                 KX_YKEY,
162                 KX_ZKEY, // =122
163         
164                 
165                 
166                 KX_CAPSLOCKKEY, // 123
167                 
168                 KX_LEFTCTRLKEY, // 124
169                 KX_LEFTALTKEY,          
170                 KX_RIGHTALTKEY,         
171                 KX_RIGHTCTRLKEY,        
172                 KX_RIGHTSHIFTKEY,       
173                 KX_LEFTSHIFTKEY,// 129
174                 
175                 KX_ESCKEY, // 130
176                 KX_TABKEY, //131
177                 
178                 
179                 KX_LINEFEEDKEY,  // 132 
180                 KX_BACKSPACEKEY,
181                 KX_DELKEY,
182                 KX_SEMICOLONKEY, // 135
183                 
184                 
185                 KX_QUOTEKEY,            //136
186                 KX_ACCENTGRAVEKEY,      //137
187                 
188                 KX_SLASHKEY,            //138
189                 KX_BACKSLASHKEY,
190                 KX_EQUALKEY,            
191                 KX_LEFTBRACKETKEY,      
192                 KX_RIGHTBRACKETKEY,     // 142
193                 
194                 KX_LEFTARROWKEY, // 145
195                 KX_DOWNARROWKEY,
196                 KX_RIGHTARROWKEY,       
197                 KX_UPARROWKEY,          // 148
198         
199                 KX_PAD2 ,
200                 KX_PAD4 ,
201                 KX_PAD6 ,
202                 KX_PAD8 ,
203                 
204                 KX_PAD1 ,
205                 KX_PAD3 ,
206                 KX_PAD5 ,
207                 KX_PAD7 ,
208                 KX_PAD9 ,
209                 
210                 KX_PADPERIOD,
211                 KX_PADSLASHKEY,
212                 
213                 
214                 
215                 KX_PAD0 ,
216                 KX_PADMINUS,
217                 KX_PADENTER,
218                 KX_PADPLUSKEY,
219                 
220                 
221                 KX_F1KEY ,
222                 KX_F2KEY ,
223                 KX_F3KEY ,
224                 KX_F4KEY ,
225                 KX_F5KEY ,
226                 KX_F6KEY ,
227                 KX_F7KEY ,
228                 KX_F8KEY ,
229                 KX_F9KEY ,
230                 KX_F10KEY,
231                 KX_F11KEY,
232                 KX_F12KEY,
233                 KX_F13KEY,
234                 KX_F14KEY,
235                 KX_F15KEY,
236                 KX_F16KEY,
237                 KX_F17KEY,
238                 KX_F18KEY,
239                 KX_F19KEY,
240                 
241                 KX_PAUSEKEY,
242                 KX_INSERTKEY,
243                 KX_HOMEKEY ,
244                 KX_PAGEUPKEY,
245                 KX_PAGEDOWNKEY,
246                 KX_ENDKEY,
247
248                 // MOUSE
249                 KX_BEGINMOUSE,
250                 
251                 KX_BEGINMOUSEBUTTONS,
252
253                 KX_LEFTMOUSE,
254                 KX_MIDDLEMOUSE,
255                 KX_RIGHTMOUSE,
256                 
257                 KX_ENDMOUSEBUTTONS,
258                 
259                 KX_WHEELUPMOUSE,
260                 KX_WHEELDOWNMOUSE,
261
262                 KX_MOUSEX,
263                 KX_MOUSEY,
264         
265                 KX_ENDMOUSE,
266
267
268
269                 KX_MAX_KEYS
270                 
271         } ; // enum  
272
273
274 protected:
275         /**  
276                 m_eventStatusTables are two tables that contain current and previous
277                 status of all events
278         */
279
280         SCA_InputEvent  m_eventStatusTables[2][SCA_IInputDevice::KX_MAX_KEYS];
281         /**  
282                 m_currentTable is index for m_keyStatusTable that toggle between 0 or 1 
283         */
284         int                             m_currentTable; 
285         void                    ClearStatusTable(int tableid);
286
287 public:
288         virtual bool    IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
289         virtual const SCA_InputEvent&   GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode);
290
291         /**
292          * Count active events(active and just_activated)
293          */
294         virtual int             GetNumActiveEvents();
295
296         /**
297          * Get the number of ramping events (just_activated, just_released)
298          */
299         virtual int             GetNumJustEvents();
300         
301         virtual void            HookEscape();
302         
303         /* Next frame: we calculate the new key states. This goes as follows:
304         *
305         * KX_NO_INPUTSTATUS -> KX_NO_INPUTSTATUS
306         * KX_JUSTACTIVATED  -> KX_ACTIVE
307         * KX_ACTIVE         -> KX_ACTIVE
308         * KX_JUSTRELEASED   -> KX_NO_INPUTSTATUS
309         *
310         * Getting new events provides the
311         * KX_NO_INPUTSTATUS->KX_JUSTACTIVATED and
312         * KX_ACTIVE->KX_JUSTRELEASED transitions.
313         */
314         virtual void    NextFrame();
315
316
317 #ifdef WITH_CXX_GUARDEDALLOC
318 public:
319         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SCA_InputEvent"); }
320         void operator delete(void *mem) { MEM_freeN(mem); }
321 #endif
322 };
323
324 #endif  //KX_INPUTDEVICE_H
325