rebranch from 2.5
[blender.git] / source / gameengine / BlenderRoutines / KX_BlenderInputDevice.h
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29 #ifndef __KX_BLENDERINPUTDEVICE
30 #define __KX_BLENDERINPUTDEVICE
31
32 #ifdef WIN32
33 #pragma warning(disable : 4786)  // shut off 255 char limit debug template warning
34 #endif
35
36 #include <map>
37
38 #include "wm_event_types.h"
39 #include "SCA_IInputDevice.h"
40
41 /**
42  Base Class for Blender specific inputdevices. Blender specific inputdevices are used when the gameengine is running in embedded mode instead of standalone mode.
43 */
44 class BL_BlenderInputDevice : public SCA_IInputDevice                                                               
45 {
46         // this map is Blender specific: a conversion between blender and ketsji enums
47         std::map<int,KX_EnumInputs> m_reverseKeyTranslateTable;
48 public:
49         BL_BlenderInputDevice()                                                                                    
50                 {                                                                                                          
51                         
52                         /* The reverse table. In order to not confuse ourselves, we      */
53                         /* immediately convert all events that come in to KX codes.      */
54                         m_reverseKeyTranslateTable[LEFTMOUSE                    ] =     KX_LEFTMOUSE            ;
55                         m_reverseKeyTranslateTable[MIDDLEMOUSE                  ] =     KX_MIDDLEMOUSE          ;
56                         m_reverseKeyTranslateTable[RIGHTMOUSE                   ] =     KX_RIGHTMOUSE           ;
57                         m_reverseKeyTranslateTable[WHEELUPMOUSE                 ] =     KX_WHEELUPMOUSE         ;
58                         m_reverseKeyTranslateTable[WHEELDOWNMOUSE               ] =     KX_WHEELDOWNMOUSE       ;
59                         m_reverseKeyTranslateTable[MOUSEX                       ] =     KX_MOUSEX               ;
60                         m_reverseKeyTranslateTable[MOUSEY                       ] =     KX_MOUSEY               ;
61                                                                                                                    
62                         // TIMERS                                                                                                  
63
64                         m_reverseKeyTranslateTable[TIMER0                           ] = KX_TIMER0                  ;                  
65                         m_reverseKeyTranslateTable[TIMER1                           ] = KX_TIMER1                  ;                  
66                         m_reverseKeyTranslateTable[TIMER2                           ] = KX_TIMER2                  ;                  
67                         m_reverseKeyTranslateTable[TIMER3                           ] = KX_TIMER3                  ;                  
68                                                                                                                    
69                         // SYSTEM                                                                                                  
70                                                                                                                    
71                         m_reverseKeyTranslateTable[KEYBD                            ] = KX_KEYBD                   ;                  
72                         m_reverseKeyTranslateTable[RAWKEYBD                         ] = KX_RAWKEYBD                ;                  
73                         m_reverseKeyTranslateTable[REDRAW                           ] = KX_REDRAW                  ;                  
74                         m_reverseKeyTranslateTable[INPUTCHANGE                      ] = KX_INPUTCHANGE             ;                  
75                         m_reverseKeyTranslateTable[QFULL                            ] = KX_QFULL                   ;                  
76                         m_reverseKeyTranslateTable[WINFREEZE                        ] = KX_WINFREEZE               ;                  
77                         m_reverseKeyTranslateTable[WINTHAW                          ] = KX_WINTHAW                 ;                  
78                         m_reverseKeyTranslateTable[WINCLOSE                         ] = KX_WINCLOSE                ;                  
79                         m_reverseKeyTranslateTable[WINQUIT                          ] = KX_WINQUIT                 ;                  
80                         m_reverseKeyTranslateTable[Q_FIRSTTIME                      ] = KX_Q_FIRSTTIME             ;                  
81                                                                                                                    
82                         // standard keyboard                                                                                       
83                                                                                                                    
84                         m_reverseKeyTranslateTable[AKEY                             ] = KX_AKEY                    ;                  
85                         m_reverseKeyTranslateTable[BKEY                             ] = KX_BKEY                    ;                  
86                         m_reverseKeyTranslateTable[CKEY                             ] = KX_CKEY                    ;                  
87                         m_reverseKeyTranslateTable[DKEY                             ] = KX_DKEY                    ;                  
88                         m_reverseKeyTranslateTable[EKEY                             ] = KX_EKEY                    ;                  
89                         m_reverseKeyTranslateTable[FKEY                             ] = KX_FKEY                    ;                  
90                         m_reverseKeyTranslateTable[GKEY                             ] = KX_GKEY                    ;                  
91 //XXX clean up
92 #ifdef WIN32
93 #define HKEY    'h'
94 #endif
95                         m_reverseKeyTranslateTable[HKEY                             ] = KX_HKEY                    ;                  
96 //XXX clean up
97 #ifdef WIN32
98 #undef HKEY
99 #endif
100                         m_reverseKeyTranslateTable[IKEY                             ] = KX_IKEY                    ;                  
101                         m_reverseKeyTranslateTable[JKEY                             ] = KX_JKEY                    ;                  
102                         m_reverseKeyTranslateTable[KKEY                             ] = KX_KKEY                    ;                  
103                         m_reverseKeyTranslateTable[LKEY                             ] = KX_LKEY                    ;                  
104                         m_reverseKeyTranslateTable[MKEY                             ] = KX_MKEY                    ;                  
105                         m_reverseKeyTranslateTable[NKEY                             ] = KX_NKEY                    ;                  
106                         m_reverseKeyTranslateTable[OKEY                             ] = KX_OKEY                    ;                  
107                         m_reverseKeyTranslateTable[PKEY                             ] = KX_PKEY                    ;                  
108                         m_reverseKeyTranslateTable[QKEY                             ] = KX_QKEY                    ;                  
109                         m_reverseKeyTranslateTable[RKEY                             ] = KX_RKEY                    ;                  
110                         m_reverseKeyTranslateTable[SKEY                             ] = KX_SKEY                    ;                  
111                         m_reverseKeyTranslateTable[TKEY                             ] = KX_TKEY                    ;                  
112                         m_reverseKeyTranslateTable[UKEY                             ] = KX_UKEY                    ;                  
113                         m_reverseKeyTranslateTable[VKEY                             ] = KX_VKEY                    ;                  
114                         m_reverseKeyTranslateTable[WKEY                             ] = KX_WKEY                    ;                  
115                         m_reverseKeyTranslateTable[XKEY                             ] = KX_XKEY                    ;                  
116                         m_reverseKeyTranslateTable[YKEY                             ] = KX_YKEY                    ;                  
117                         m_reverseKeyTranslateTable[ZKEY                             ] = KX_ZKEY                    ;                  
118                                                                                                                    
119                         m_reverseKeyTranslateTable[ZEROKEY                              ] = KX_ZEROKEY                  ;                  
120                         m_reverseKeyTranslateTable[ONEKEY                               ] = KX_ONEKEY                   ;                  
121                         m_reverseKeyTranslateTable[TWOKEY                               ] = KX_TWOKEY                   ;                  
122                         m_reverseKeyTranslateTable[THREEKEY                     ] = KX_THREEKEY                ;                  
123                         m_reverseKeyTranslateTable[FOURKEY                              ] = KX_FOURKEY                  ;                  
124                         m_reverseKeyTranslateTable[FIVEKEY                              ] = KX_FIVEKEY                  ;                  
125                         m_reverseKeyTranslateTable[SIXKEY                               ] = KX_SIXKEY                   ;                  
126                         m_reverseKeyTranslateTable[SEVENKEY                         ] = KX_SEVENKEY                ;                  
127                         m_reverseKeyTranslateTable[EIGHTKEY                         ] = KX_EIGHTKEY                ;                  
128                         m_reverseKeyTranslateTable[NINEKEY                              ] = KX_NINEKEY                  ;                  
129                                                                                                                    
130                         m_reverseKeyTranslateTable[CAPSLOCKKEY                      ] = KX_CAPSLOCKKEY             ;                  
131                                                                 
132                         m_reverseKeyTranslateTable[LEFTCTRLKEY                  ] = KX_LEFTCTRLKEY              ;                  
133                         m_reverseKeyTranslateTable[LEFTALTKEY                   ] = KX_LEFTALTKEY               ;                  
134                         m_reverseKeyTranslateTable[RIGHTALTKEY                  ] = KX_RIGHTALTKEY              ;                  
135                         m_reverseKeyTranslateTable[RIGHTCTRLKEY                         ] = KX_RIGHTCTRLKEY             ;                  
136                         m_reverseKeyTranslateTable[RIGHTSHIFTKEY                        ] = KX_RIGHTSHIFTKEY            ;                  
137                         m_reverseKeyTranslateTable[LEFTSHIFTKEY                     ] = KX_LEFTSHIFTKEY            ;                  
138                                                                                                                    
139                         m_reverseKeyTranslateTable[ESCKEY                           ] = KX_ESCKEY                  ;                  
140                         m_reverseKeyTranslateTable[TABKEY                           ] = KX_TABKEY                  ;                  
141                         m_reverseKeyTranslateTable[RETKEY                           ] = KX_RETKEY                  ;                  
142                         m_reverseKeyTranslateTable[SPACEKEY                         ] = KX_SPACEKEY                ;                  
143                         m_reverseKeyTranslateTable[LINEFEEDKEY                  ] = KX_LINEFEEDKEY              ;                  
144                         m_reverseKeyTranslateTable[BACKSPACEKEY                     ] = KX_BACKSPACEKEY            ;                  
145                         m_reverseKeyTranslateTable[DELKEY                           ] = KX_DELKEY                  ;                  
146                         m_reverseKeyTranslateTable[SEMICOLONKEY                     ] = KX_SEMICOLONKEY            ;                  
147                         m_reverseKeyTranslateTable[PERIODKEY                    ] = KX_PERIODKEY                ;                  
148                         m_reverseKeyTranslateTable[COMMAKEY                             ] = KX_COMMAKEY         ;                  
149                         m_reverseKeyTranslateTable[QUOTEKEY                             ] = KX_QUOTEKEY         ;                  
150                         m_reverseKeyTranslateTable[ACCENTGRAVEKEY                       ] = KX_ACCENTGRAVEKEY           ;                  
151                         m_reverseKeyTranslateTable[MINUSKEY                             ] = KX_MINUSKEY         ;                  
152                         m_reverseKeyTranslateTable[SLASHKEY                             ] = KX_SLASHKEY         ;                  
153                         m_reverseKeyTranslateTable[BACKSLASHKEY                     ] = KX_BACKSLASHKEY            ;                  
154                         m_reverseKeyTranslateTable[EQUALKEY                             ] = KX_EQUALKEY         ;                  
155                         m_reverseKeyTranslateTable[LEFTBRACKETKEY                       ] = KX_LEFTBRACKETKEY           ;                  
156                         m_reverseKeyTranslateTable[RIGHTBRACKETKEY                      ] = KX_RIGHTBRACKETKEY          ;                  
157                                                                                                                    
158                         m_reverseKeyTranslateTable[LEFTARROWKEY                     ] = KX_LEFTARROWKEY            ;                  
159                         m_reverseKeyTranslateTable[DOWNARROWKEY                     ] = KX_DOWNARROWKEY            ;                  
160                         m_reverseKeyTranslateTable[RIGHTARROWKEY                        ] = KX_RIGHTARROWKEY            ;                  
161                         m_reverseKeyTranslateTable[UPARROWKEY                   ] = KX_UPARROWKEY               ;                  
162                                                                                                                    
163                         m_reverseKeyTranslateTable[PAD2                         ] = KX_PAD2                     ;                  
164                         m_reverseKeyTranslateTable[PAD4                         ] = KX_PAD4                     ;                  
165                         m_reverseKeyTranslateTable[PAD6                         ] = KX_PAD6                     ;                  
166                         m_reverseKeyTranslateTable[PAD8                         ] = KX_PAD8                     ;                  
167                                                                                                                    
168                         m_reverseKeyTranslateTable[PAD1                         ] = KX_PAD1                     ;                  
169                         m_reverseKeyTranslateTable[PAD3                         ] = KX_PAD3                     ;                  
170                         m_reverseKeyTranslateTable[PAD5                         ] = KX_PAD5                     ;                  
171                         m_reverseKeyTranslateTable[PAD7                         ] = KX_PAD7                     ;                  
172                         m_reverseKeyTranslateTable[PAD9                         ] = KX_PAD9                     ;                  
173
174                         m_reverseKeyTranslateTable[PADPERIOD                        ] = KX_PADPERIOD               ;                  
175                         m_reverseKeyTranslateTable[PADSLASHKEY                    ] = KX_PADSLASHKEY           ;                  
176                         m_reverseKeyTranslateTable[PADASTERKEY                      ] = KX_PADASTERKEY             ;                  
177                                                                                                                    
178                                                                                                                    
179                         m_reverseKeyTranslateTable[PAD0                         ] = KX_PAD0                     ;                  
180                         m_reverseKeyTranslateTable[PADMINUS                         ] = KX_PADMINUS                ;                  
181                         m_reverseKeyTranslateTable[PADENTER                         ] = KX_PADENTER                ;                  
182                         m_reverseKeyTranslateTable[PADPLUSKEY                       ] = KX_PADPLUSKEY              ;                  
183                                                                                                                    
184                                                                                                                    
185                         m_reverseKeyTranslateTable[F1KEY                            ] = KX_F1KEY                   ;                  
186                         m_reverseKeyTranslateTable[F2KEY                            ] = KX_F2KEY                   ;                  
187                         m_reverseKeyTranslateTable[F3KEY                            ] = KX_F3KEY                   ;                  
188                         m_reverseKeyTranslateTable[F4KEY                            ] = KX_F4KEY                   ;                  
189                         m_reverseKeyTranslateTable[F5KEY                            ] = KX_F5KEY                   ;                  
190                         m_reverseKeyTranslateTable[F6KEY                            ] = KX_F6KEY                   ;                  
191                         m_reverseKeyTranslateTable[F7KEY                            ] = KX_F7KEY                   ;                  
192                         m_reverseKeyTranslateTable[F8KEY                            ] = KX_F8KEY                   ;                  
193                         m_reverseKeyTranslateTable[F9KEY                            ] = KX_F9KEY                   ;                  
194                         m_reverseKeyTranslateTable[F10KEY                           ] = KX_F10KEY                  ;                  
195                         m_reverseKeyTranslateTable[F11KEY      ] = KX_F11KEY                  ;                  
196                         m_reverseKeyTranslateTable[F12KEY      ] = KX_F12KEY                  ;                  
197                                                                                                                    
198                         m_reverseKeyTranslateTable[PAUSEKEY    ] = KX_PAUSEKEY                ;                  
199                         m_reverseKeyTranslateTable[INSERTKEY   ] = KX_INSERTKEY               ;                  
200                         m_reverseKeyTranslateTable[HOMEKEY     ] = KX_HOMEKEY                 ;                  
201                         m_reverseKeyTranslateTable[PAGEUPKEY   ] = KX_PAGEUPKEY               ;                  
202                         m_reverseKeyTranslateTable[PAGEDOWNKEY ] = KX_PAGEDOWNKEY             ;                  
203                         m_reverseKeyTranslateTable[ENDKEY      ] = KX_ENDKEY                  ;                  
204
205                                                                                                                    
206                 }                                                                                                          
207
208         virtual ~BL_BlenderInputDevice()
209                 {
210
211                 }
212                                                                                                                    
213          KX_EnumInputs ToNative(unsigned short incode) {
214                 return m_reverseKeyTranslateTable[incode];
215         }
216
217         virtual bool    IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
218 //      virtual const SCA_InputEvent&   GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
219         virtual bool    ConvertBlenderEvent(unsigned short incode,short val)=0;
220
221 };                                                                                                                 
222 #endif //__KX_BLENDERINPUTDEVICE
223