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