Blender V2.61 - r43446

SCA_IInputDevice.h

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