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