* Add "less" target to view make output through less.
[matthijs/ABM2.git] / ABM2 / Amaltheia / Input.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dimitris Saougos & Filippos Papadopoulos   *
3  *   <psybases@gmail.com>                                                             *
4  *                                                                                                       *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU Library General Public License as       *
7  *   published by the Free Software Foundation; either version 2 of the    *
8  *   License, or (at your option) any later version.                                    *
9  *                                                                                                           *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU Library General Public     *
16  *   License along with this program; if not, write to the                 *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place*  Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _INPUT
22 #define _INPUT
23
24 #include "System.h"
25 /*group: KEY codes
26
27 + *LEFT_BUTTON* the left mouse button
28 + *MIDDLE_BUTTON* the middle mouse button
29 + *RIGHT_BUTTON* the right mouse button
30
31 + *KEY_ESC* the escape key
32 + *KEY_ESCAPE*
33
34 + *KEY_MINUS*
35 + *KEY_EQUALS*
36 + *KEY_BACKSPACE*
37 + *KEY_TAB*
38
39 + *KEY_LBRACKET*
40 + *KEY_RBRACKET*
41
42 + *KEY_ENTER*
43 + *KEY_RETURN*
44
45 + *KEY_CTRL*
46 + *KEY_LCTRL*
47 + *KEY_RCTRL*
48
49 + *KEY_SHIFT*
50 + *KEY_LSHIFT*
51 + *KEY_RSHIFT*
52
53 + *KEY_ALT*
54 + *KEY_LALT*
55 + *KEY_RALT*
56
57 + *KEY_0*
58 + *KEY_1*
59 + *KEY_2*
60 + *KEY_3*
61 + *KEY_4*
62 + *KEY_5*
63 + *KEY_6*
64 + *KEY_7*
65 + *KEY_8*
66 + *KEY_9*
67
68 + *KEY_A*
69 + *KEY_B*
70 + *KEY_C*
71 + *KEY_D*
72 + *KEY_E*
73 + *KEY_F*
74 + *KEY_G*
75 + *KEY_H*
76 + *KEY_I*
77 + *KEY_J*
78 + *KEY_K*
79 + *KEY_L*
80 + *KEY_M*
81 + *KEY_N*
82 + *KEY_O*
83 + *KEY_P*
84 + *KEY_Q*
85 + *KEY_R*
86 + *KEY_S*
87 + *KEY_T*
88 + *KEY_U*
89 + *KEY_V*
90 + *KEY_W*
91 + *KEY_X*
92 + *KEY_Y*
93 + *KEY_Z*
94
95 + *KEY_SEMICOLON*
96 + *KEY_APOSTROPHE*
97
98 + *KEY_TILDE*
99 + *KEY_GRAVE*
100
101 + *KEY_BACKSLASH*
102
103 + *KEY_COMMA*
104 + *KEY_PERIOD*
105 + *KEY_FORWARDSLASH*
106 + *KEY_SLASH*
107
108 + *KEY_SPACE*
109
110 + *KEY_CAPSLOCK*
111 + *KEY_CAPITAL*
112
113 + *KEY_F1*
114 + *KEY_F2*
115 + *KEY_F3*
116 + *KEY_F4*
117 + *KEY_F5*
118 + *KEY_F6*
119 + *KEY_F7*
120 + *KEY_F8*
121 + *KEY_F9*
122 + *KEY_F10*
123 + *KEY_F11*
124 + *KEY_F12*
125
126 + *KEY_SYSRQ*
127 + *KEY_SCROLLLOCK*
128 + *KEY_PAUSE*
129
130 + *KEY_NUMLOCK*
131 + *KEY_NUMPAD0*
132 + *KEY_NUMPAD1*
133 + *KEY_NUMPAD2*
134 + *KEY_NUMPAD3*
135 + *KEY_NUMPAD4*
136 + *KEY_NUMPAD5*
137 + *KEY_NUMPAD6*
138 + *KEY_NUMPAD7*
139 + *KEY_NUMPAD8*
140 + *KEY_NUMPAD9*
141 + *KEY_ADD*
142 + *KEY_SUBTRACT*
143 + *KEY_DIVIDE*
144 + *KEY_MULTIPLY*
145 + *KEY_DECIMAL*
146 + *KEY_NUMPADENTER*
147
148 + *KEY_INSERT*
149 + *KEY_DELETE*
150 + *KEY_HOME*
151 + *KEY_END*
152 + *KEY_PAGEUP*
153 + *KEY_PAGEDOWN*
154
155 + *KEY_UP*
156 + *KEY_DOWN*
157 + *KEY_LEFT*
158 + *KEY_RIGHT*
159
160 + *KEY_LWIN*
161 + *KEY_RWIN*
162 + *KEY_APPS*
163
164         */
165
166 extern const int LEFT_BUTTON;
167 extern const int MIDDLE_BUTTON;
168 extern const int RIGHT_BUTTON;
169
170 extern const int KEY_ESC;
171 extern const int KEY_ESCAPE;
172
173 extern const int KEY_MINUS;           
174 extern const int KEY_EQUALS;   
175 extern const int KEY_BACKSPACE;
176 extern const int KEY_TAB;
177
178 extern const int KEY_LBRACKET;      
179 extern const int KEY_RBRACKET;
180
181 extern const int KEY_ENTER;           
182 extern const int KEY_RETURN;         
183
184 extern const int KEY_CTRL;      
185 extern const int KEY_LCTRL;    
186 extern const int KEY_RCTRL;    
187
188 extern const int KEY_SHIFT;     
189 extern const int KEY_LSHIFT;   
190 extern const int KEY_RSHIFT;   
191
192 extern const int KEY_ALT;        
193 extern const int KEY_LALT;      
194 extern const int KEY_RALT;      
195
196 extern const int KEY_0;            
197 extern const int KEY_1;            
198 extern const int KEY_2;            
199 extern const int KEY_3;            
200 extern const int KEY_4;            
201 extern const int KEY_5;            
202 extern const int KEY_6;            
203 extern const int KEY_7;            
204 extern const int KEY_8;            
205 extern const int KEY_9;            
206
207 extern const int KEY_A;            
208 extern const int KEY_B;            
209 extern const int KEY_C;            
210 extern const int KEY_D;            
211 extern const int KEY_E;            
212 extern const int KEY_F;            
213 extern const int KEY_G;            
214 extern const int KEY_H;            
215 extern const int KEY_I;            
216 extern const int KEY_J;             
217 extern const int KEY_K;             
218 extern const int KEY_L;             
219 extern const int KEY_M;            
220 extern const int KEY_N;            
221 extern const int KEY_O;            
222 extern const int KEY_P;            
223 extern const int KEY_Q;            
224 extern const int KEY_R;            
225 extern const int KEY_S;            
226 extern const int KEY_T;            
227 extern const int KEY_U;            
228 extern const int KEY_V;            
229 extern const int KEY_W;           
230 extern const int KEY_X;           
231 extern const int KEY_Y;            
232 extern const int KEY_Z;            
233
234 extern const int KEY_SEMICOLON; 
235 extern const int KEY_APOSTROPHE;
236
237 extern const int KEY_TILDE;           
238 extern const int KEY_GRAVE;          
239
240 extern const int KEY_BACKSLASH;
241
242 extern const int KEY_COMMA;        
243 extern const int KEY_PERIOD;        
244 extern const int KEY_FORWARDSLASH;
245 extern const int KEY_SLASH;           
246
247 extern const int KEY_SPACE;           
248
249 extern const int KEY_CAPSLOCK;     
250 extern const int KEY_CAPITAL;        
251
252 extern const int KEY_F1;              
253 extern const int KEY_F2;              
254 extern const int KEY_F3;              
255 extern const int KEY_F4;              
256 extern const int KEY_F5;              
257 extern const int KEY_F6;              
258 extern const int KEY_F7;              
259 extern const int KEY_F8;              
260 extern const int KEY_F9;              
261 extern const int KEY_F10;            
262 extern const int KEY_F11;            
263 extern const int KEY_F12;            
264
265 extern const int KEY_SYSRQ;        
266 extern const int KEY_SCROLLLOCK;
267 extern const int KEY_PAUSE;          
268
269 extern const int KEY_NUMLOCK;     
270 extern const int KEY_NUMPAD0;     
271 extern const int KEY_NUMPAD1;     
272 extern const int KEY_NUMPAD2;     
273 extern const int KEY_NUMPAD3;     
274 extern const int KEY_NUMPAD4;     
275 extern const int KEY_NUMPAD5;     
276 extern const int KEY_NUMPAD6;     
277 extern const int KEY_NUMPAD7;     
278 extern const int KEY_NUMPAD8;     
279 extern const int KEY_NUMPAD9;     
280 extern const int KEY_ADD;             
281 extern const int KEY_SUBTRACT;    
282 extern const int KEY_DIVIDE;         
283 extern const int KEY_MULTIPLY;     
284 extern const int KEY_DECIMAL;      
285 extern const int KEY_NUMPADENTER;     
286
287 extern const int KEY_INSERT;          
288 extern const int KEY_DELETE;         
289 extern const int KEY_HOME;            
290 extern const int KEY_END;             
291 extern const int KEY_PAGEUP;        
292 extern const int KEY_PAGEDOWN;  
293
294 extern const int KEY_UP;              
295 extern const int KEY_DOWN;        
296 extern const int KEY_LEFT;           
297 extern const int KEY_RIGHT;         
298
299 extern const int KEY_LWIN;          
300 extern const int KEY_RWIN;          
301 extern const int KEY_APPS;           
302
303 #define D 200 
304 #define R 1 
305
306
307         
308 extern int key_val;
309 extern bool key_press;
310
311 //group: Classes
312
313 /*class: Input
314 Handles keyboard and mouse input*/
315 class Input
316 {
317 protected:
318         int lockBuffer;
319         int mouseLockBuffer[4];
320         char map[512];
321         int keyLockDuration;
322         int buttonLockDuration;
323         char symbol[10];
324    //SDL_Event event;
325         int mx,my;
326
327         
328 public:
329         
330 //group:        Constructors
331         /*constructor: Input
332         parameters:
333         keyb -  *true* to enable the keyboard subsystem, *false* otherwise
334         mous -  *true* to enable the mouse subsystem, *false* otherwise
335         */
336         Input(bool keyb, bool mous);
337         ~Input(void);
338
339 /*group: Methods */
340         
341 /*method: mousePrepare
342         This method is the actual method that makes the reading from the hardware.
343         It should be called at regular intervals. If called too often or too sparsely it will result in missing some information
344         from the input. In general terms it is safe just to call it in every frame. But if the frame rate if very high it might
345         result in strange behavior from the mouse. We suggest assigning a timer of X ms to the calling of the function
346         and fine-tune it for better results.
347         
348 see also:
349         <mouseGetButtonState>,  <mouseGetXDelta> and <mouseGetYDelta>*/
350         void mousePrepare();
351
352 /*method: mouseGetButtonState
353         Checks whether a speficic mouse button is pressed
354
355         parameters:
356         button - the mouse button to check. Valid values are
357
358         + *LEFT_BUTTON*
359         + *MIDDLE_BUTTON*
360         + *RIGHT_BUTTON*
361         
362         retuns:
363         *true* if _button_ is pressed, *false* otherwise
364
365 see also:
366         <mousePrepare>*/
367         bool mouseGetButtonState(int button);
368
369 /*method: mouseGetXDelta
370         Reports deltas for mouse movement in X axis
371
372         returns:
373         the units of the mouse movement in the X axis. A negative integer will be returned when the mouse is moved in the
374         left direction, and a positive when moved in the right. Zero will be returned when there is no movement
375
376         see also:
377         <mouseGetYDelta>*/
378         long mouseGetXDelta(void);
379
380 /*method: mouseGetYDelta
381         Reports deltas for mouse movement in Y axis
382         
383         returns:
384         the units of the mouse movement in the Y axis
385
386         see also:
387         <mouseGetXDelta>*/
388         long mouseGetYDelta(void);
389
390 /*method: lockButton
391         Locks a mouse button for _duration_ milliseconds. When you lock a button it will not report its state for _duration_ millis
392
393         button - the desired button to lock
394         duration - duration of the locking in milliseconds
395
396         see also:
397         <mouseGetButtonState>*/
398         void lockButton(int button, int duration=100);
399
400 /*method: keyboardGetKeyState
401         Checks whether a speficic key on the keyboard is pressed
402
403         parameters:
404                         key - the key to check. See the <KEY codes>
405
406         retuns:
407                         *true* if _key_ is pressed, *false* otherwise*/
408         bool keyboardGetKeyState(int key);
409
410 /*method: getChar
411 Returns the character that has been pressed on the keyboard*/
412         char getChar(void);
413
414 /*method: lockKey */
415         void lockKey(int key, int duration=100);
416 };
417
418 #endif