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