Blender  V2.59
SCA_IInputDevice.h
Go to the documentation of this file.
00001 /*
00002  * $Id: SCA_IInputDevice.h 35063 2011-02-22 10:33:14Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00037 #ifndef KX_INPUTDEVICE_H
00038 #define KX_INPUTDEVICE_H
00039 
00040 #ifdef WITH_CXX_GUARDEDALLOC
00041 #include "MEM_guardedalloc.h"
00042 #endif
00043 
00044 class SCA_InputEvent 
00045 {
00046         
00047 public:
00048         enum SCA_EnumInputs {
00049         
00050                 KX_NO_INPUTSTATUS = 0,
00051                 KX_JUSTACTIVATED,
00052                 KX_ACTIVE,
00053                 KX_JUSTRELEASED,
00054         };
00055 
00056         SCA_InputEvent(SCA_EnumInputs status=KX_NO_INPUTSTATUS,int eventval=0)
00057                 :       m_status(status),
00058                 m_eventval(eventval)
00059         {
00060 
00061         }
00062 
00063         SCA_EnumInputs m_status;
00064         int             m_eventval;
00065 };
00066 
00067 class SCA_IInputDevice 
00068 {
00069 
00070         
00071 public:
00072 
00073         SCA_IInputDevice();
00074         virtual ~SCA_IInputDevice();    
00075 
00076         enum KX_EnumInputs {
00077         
00078                 KX_NOKEY = 0,
00079         
00080                 // TIMERS 
00081         
00082                 KX_TIMER0,
00083                 KX_TIMER1,
00084                 KX_TIMER2,
00085         
00086                 // SYSTEM
00087 
00088                 /* Moved to avoid clashes with KX_RETKEY */
00089                 KX_KEYBD,
00090                 KX_RAWKEYBD,
00091                 KX_REDRAW,
00092                 KX_INPUTCHANGE,
00093                 KX_QFULL,
00094                 KX_WINFREEZE,
00095                 KX_WINTHAW,
00096                 /* thaw is 11 */
00097 
00098                 /* move past retkey*/
00099                 KX_WINCLOSE = 14,
00100                 KX_WINQUIT,
00101                 KX_Q_FIRSTTIME,
00102                 /* sequence ends on 16 */
00103         
00104                 // standard keyboard 
00105 
00106                 /* Because of the above preamble, KX_BEGINKEY is 15 ! This
00107                  * means that KX_RETKEY on 13d (0Dh)) will double up with
00108                  * KX_WINQUIT!  Why is it 13? Because ascii 13d is Ctrl-M aka
00109                  * CR! Its little brother, LF has 10d (0Ah). This is
00110                  * dangerous, since the keyboards start scanning at
00111                  * KX_BEGINKEY. I think the keyboard system should push its
00112                  * key events instead of demanding the user to poll the
00113                  * table... But that's for another time... The fix for now is
00114                  * to move the above system events into a 'safe' (ie. unused)
00115                  * range. I am loathe to move it away from this 'magical'
00116                  * coincidence.. it's probably exploited somewhere. I hope the
00117                  * close and quit events don't mess up 'normal' kb code
00118                  * scanning.
00119                  * */
00120                 KX_BEGINKEY = 12,
00121 
00122                 KX_RETKEY = 13,
00123                 KX_SPACEKEY = 32,
00124                 KX_PADASTERKEY = 42,
00125                 KX_COMMAKEY = 44,               
00126                 KX_MINUSKEY = 45,               
00127                 KX_PERIODKEY = 46,
00128                 KX_ZEROKEY = 48,
00129                 
00130                 KX_ONEKEY,              // =49
00131                 KX_TWOKEY,              
00132                 KX_THREEKEY,
00133                 KX_FOURKEY,             
00134                 KX_FIVEKEY,             
00135                 KX_SIXKEY,              
00136                 KX_SEVENKEY,
00137                 KX_EIGHTKEY,
00138                 KX_NINEKEY,             // = 57
00139 
00140                 KX_AKEY = 97,
00141                 KX_BKEY,
00142                 KX_CKEY,
00143                 KX_DKEY,
00144                 KX_EKEY,
00145                 KX_FKEY,
00146                 KX_GKEY,
00147                 KX_HKEY,
00148                 KX_IKEY,
00149                 KX_JKEY,
00150                 KX_KKEY,
00151                 KX_LKEY,
00152                 KX_MKEY,
00153                 KX_NKEY, // =110
00154                 KX_OKEY,
00155                 KX_PKEY,
00156                 KX_QKEY,
00157                 KX_RKEY,
00158                 KX_SKEY,
00159                 KX_TKEY,
00160                 KX_UKEY,
00161                 KX_VKEY,
00162                 KX_WKEY,
00163                 KX_XKEY, // =120
00164                 KX_YKEY,
00165                 KX_ZKEY, // =122
00166         
00167                 
00168                 
00169                 KX_CAPSLOCKKEY, // 123
00170                 
00171                 KX_LEFTCTRLKEY, // 124
00172                 KX_LEFTALTKEY,          
00173                 KX_RIGHTALTKEY,         
00174                 KX_RIGHTCTRLKEY,        
00175                 KX_RIGHTSHIFTKEY,       
00176                 KX_LEFTSHIFTKEY,// 129
00177                 
00178                 KX_ESCKEY, // 130
00179                 KX_TABKEY, //131
00180                 
00181                 
00182                 KX_LINEFEEDKEY,  // 132 
00183                 KX_BACKSPACEKEY,
00184                 KX_DELKEY,
00185                 KX_SEMICOLONKEY, // 135
00186                 
00187                 
00188                 KX_QUOTEKEY,            //136
00189                 KX_ACCENTGRAVEKEY,      //137
00190                 
00191                 KX_SLASHKEY,            //138
00192                 KX_BACKSLASHKEY,
00193                 KX_EQUALKEY,            
00194                 KX_LEFTBRACKETKEY,      
00195                 KX_RIGHTBRACKETKEY,     // 142
00196                 
00197                 KX_LEFTARROWKEY, // 145
00198                 KX_DOWNARROWKEY,
00199                 KX_RIGHTARROWKEY,       
00200                 KX_UPARROWKEY,          // 148
00201         
00202                 KX_PAD2 ,
00203                 KX_PAD4 ,
00204                 KX_PAD6 ,
00205                 KX_PAD8 ,
00206                 
00207                 KX_PAD1 ,
00208                 KX_PAD3 ,
00209                 KX_PAD5 ,
00210                 KX_PAD7 ,
00211                 KX_PAD9 ,
00212                 
00213                 KX_PADPERIOD,
00214                 KX_PADSLASHKEY,
00215                 
00216                 
00217                 
00218                 KX_PAD0 ,
00219                 KX_PADMINUS,
00220                 KX_PADENTER,
00221                 KX_PADPLUSKEY,
00222                 
00223                 
00224                 KX_F1KEY ,
00225                 KX_F2KEY ,
00226                 KX_F3KEY ,
00227                 KX_F4KEY ,
00228                 KX_F5KEY ,
00229                 KX_F6KEY ,
00230                 KX_F7KEY ,
00231                 KX_F8KEY ,
00232                 KX_F9KEY ,
00233                 KX_F10KEY,
00234                 KX_F11KEY,
00235                 KX_F12KEY,
00236                 KX_F13KEY,
00237                 KX_F14KEY,
00238                 KX_F15KEY,
00239                 KX_F16KEY,
00240                 KX_F17KEY,
00241                 KX_F18KEY,
00242                 KX_F19KEY,
00243                 
00244                 KX_PAUSEKEY,
00245                 KX_INSERTKEY,
00246                 KX_HOMEKEY ,
00247                 KX_PAGEUPKEY,
00248                 KX_PAGEDOWNKEY,
00249                 KX_ENDKEY,
00250 
00251                 // MOUSE
00252                 KX_BEGINMOUSE,
00253                 
00254                 KX_BEGINMOUSEBUTTONS,
00255 
00256                 KX_LEFTMOUSE,
00257                 KX_MIDDLEMOUSE,
00258                 KX_RIGHTMOUSE,
00259                 
00260                 KX_ENDMOUSEBUTTONS,
00261                 
00262                 KX_WHEELUPMOUSE,
00263                 KX_WHEELDOWNMOUSE,
00264 
00265                 KX_MOUSEX,
00266                 KX_MOUSEY,
00267         
00268                 KX_ENDMOUSE,
00269 
00270 
00271 
00272                 KX_MAX_KEYS
00273                 
00274         } ; // enum  
00275 
00276 
00277 protected:
00283         SCA_InputEvent  m_eventStatusTables[2][SCA_IInputDevice::KX_MAX_KEYS];
00287         int                             m_currentTable; 
00288         void                    ClearStatusTable(int tableid);
00289 
00290 public:
00291         virtual bool    IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
00292         virtual const SCA_InputEvent&   GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode);
00293 
00297         virtual int             GetNumActiveEvents();
00298 
00302         virtual int             GetNumJustEvents();
00303         
00304         virtual void            HookEscape();
00305         
00306         /* Next frame: we calculate the new key states. This goes as follows:
00307         *
00308         * KX_NO_INPUTSTATUS -> KX_NO_INPUTSTATUS
00309         * KX_JUSTACTIVATED  -> KX_ACTIVE
00310         * KX_ACTIVE         -> KX_ACTIVE
00311         * KX_JUSTRELEASED   -> KX_NO_INPUTSTATUS
00312         *
00313         * Getting new events provides the
00314         * KX_NO_INPUTSTATUS->KX_JUSTACTIVATED and
00315         * KX_ACTIVE->KX_JUSTRELEASED transitions.
00316         */
00317         virtual void    NextFrame();
00318 
00319 
00320 #ifdef WITH_CXX_GUARDEDALLOC
00321 public:
00322         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SCA_InputEvent"); }
00323         void operator delete(void *mem) { MEM_freeN(mem); }
00324 #endif
00325 };
00326 
00327 #endif  //KX_INPUTDEVICE_H
00328