Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

input.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                       input.h  -  Input subsystem classes
00003                              -------------------
00004     begin                : Thu Nov 8 2001
00005     copyright            : (C) 2001 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, input.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2001
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEINPUT_H
00028 #define __NEINPUT_H
00029 
00030 
00037 #include "base.h"
00038 #include "activator.h"
00039 #include "inputentity.h"
00040 #include "module.h"
00041 
00042 #include <vector>
00043 
00044 
00045 #ifdef MB_RIGHT
00046 #   undef MB_RIGHT
00047 #endif
00048 
00049 
00050 namespace NeoEngine
00051 {
00052 
00053 
00054 //Forward declarations
00055 class InputGroup;
00056 class InputManager;
00057 class InputDevice;
00058 
00059 
00060 
00064 enum INPUTEVENT
00065 {
00067     IE_NONE       = 0,
00068 
00070     IE_SYSEVENT   = 1,
00071 
00073     IE_KEYDOWN    = 10,
00074 
00076     IE_KEYUP      = 11,
00077 
00079     IE_MOUSEMOVE  = 20,
00080 
00082     IE_MOUSEDOWN  = 21,
00083 
00085     IE_MOUSEUP    = 22
00086 };
00087 
00088 
00089 
00093 enum INPUTSYSEVENT
00094 {
00095     IE_SYSEVENT_KILL    = 0
00096 };
00097 
00098 
00102 enum KEYCODE
00103 {
00104     KC_SPACE             = 32,
00105     KC_0                 = 48,
00106     KC_1                 = 49,
00107     KC_2                 = 50,
00108     KC_3                 = 51,
00109     KC_4                 = 52,
00110     KC_5                 = 53,
00111     KC_6                 = 54,
00112     KC_7                 = 55,
00113     KC_8                 = 56,
00114     KC_9                 = 57,
00115     KC_A                 = 97,
00116     KC_B                 = 98,
00117     KC_C                 = 99,
00118     KC_D                 = 100,
00119     KC_E                 = 101,
00120     KC_F                 = 102,
00121     KC_G                 = 103,
00122     KC_H                 = 104,
00123     KC_I                 = 105,
00124     KC_J                 = 106,
00125     KC_K                 = 107,
00126     KC_L                 = 108,
00127     KC_M                 = 109,
00128     KC_N                 = 110,
00129     KC_O                 = 111,
00130     KC_P                 = 112,
00131     KC_Q                 = 113,
00132     KC_R                 = 114,
00133     KC_S                 = 115,
00134     KC_T                 = 116,
00135     KC_U                 = 117,
00136     KC_V                 = 118,
00137     KC_W                 = 119,
00138     KC_X                 = 120,
00139     KC_Y                 = 121,
00140     KC_Z                 = 122,
00141 
00142     KC_RETURN            = 0x1000,
00143     KC_ESCAPE            = 0x1001,
00144     KC_BACKSPACE         = 0x1002,
00145     KC_UP                = 0x1100,
00146     KC_DOWN              = 0x1101,
00147     KC_LEFT              = 0x1102,
00148     KC_RIGHT             = 0x1103,
00149     KC_F1                = 0x1201,
00150     KC_F2                = 0x1202,
00151     KC_F3                = 0x1203,
00152     KC_F4                = 0x1204,
00153     KC_F5                = 0x1205,
00154     KC_F6                = 0x1206,
00155     KC_F7                = 0x1207,
00156     KC_F8                = 0x1208,
00157     KC_F9                = 0x1209,
00158     KC_F10               = 0x120a,
00159     KC_F11               = 0x120b,
00160     KC_F12               = 0x120b,
00161     KC_F13               = 0x120c,
00162     KC_F14               = 0x120d,
00163     KC_F15               = 0x120e,
00164 
00165     KC_DOT               = 0x2000,  // .
00166     KC_COMMA             = 0x2001,  // ,
00167     KC_COLON             = 0x2002,  // :
00168     KC_SEMICOLON         = 0x2003,  // ;
00169     KC_SLASH             = 0x2004,  // /
00170     KC_BACKSLASH         = 0x2005,  /* \ */
00171     KC_PLUS              = 0x2006,  // +
00172     KC_MINUS             = 0x2007,  // -
00173     KC_ASTERISK          = 0x2008,  // *
00174     KC_EXCLAMATION       = 0x2009,  // !
00175     KC_QUESTION          = 0x200a,  // ?
00176     KC_QUOTEDOUBLE       = 0x200b,  // "
00177     KC_QUOTE             = 0x200c,  // '
00178     KC_EQUAL             = 0x200d,  // =
00179     KC_HASH              = 0x200e,  // #
00180     KC_PERCENT           = 0x200f,  // %
00181     KC_AMPERSAND         = 0x2010,  // &
00182     KC_UNDERSCORE        = 0x2011,  // _
00183     KC_LEFTPARENTHESIS   = 0x2012,  // (
00184     KC_RIGHTPARENTHESIS  = 0x2013,  // )
00185     KC_LEFTBRACKET       = 0x2014,  // [
00186     KC_RIGHTBRACKET      = 0x2015,  // ]
00187     KC_LEFTCURL          = 0x2016,  // {
00188     KC_RIGHTCURL         = 0x2017,  // }
00189     KC_DOLLAR            = 0x2018,  // $
00190     KC_POUND             = 0x2019,  // £
00191     KC_EURO              = 0x201a,  // $
00192     KC_LESS              = 0x201b,  // <
00193     KC_GREATER           = 0x201c,  // >
00194     KC_BAR               = 0x201d,  // |
00195     KC_GRAVE             = 0x201e,
00196     KC_TILDE             = 0x201f,  // ~
00197     KC_AT                = 0x2020,  // @
00198 
00199     KC_KP_0              = 0x3000,
00200     KC_KP_1              = 0x3001,
00201     KC_KP_2              = 0x3002,
00202     KC_KP_3              = 0x3003,
00203     KC_KP_4              = 0x3004,
00204     KC_KP_5              = 0x3005,
00205     KC_KP_6              = 0x3006,
00206     KC_KP_7              = 0x3007,
00207     KC_KP_8              = 0x3008,
00208     KC_KP_9              = 0x3009,
00209     KC_KP_PLUS           = 0x300a,
00210     KC_KP_MINUS          = 0x300b,
00211     KC_KP_DECIMAL        = 0x300c,
00212     KC_KP_DIVIDE         = 0x300d,
00213     KC_KP_ASTERISK       = 0x300e,
00214     KC_KP_NUMLOCK        = 0x300f,
00215     KC_KP_ENTER          = 0x3010,
00216 
00217     KC_TAB               = 0x4000,
00218     KC_CAPSLOCK          = 0x4001,
00219     KC_LSHIFT            = 0x4002,
00220     KC_LCTRL             = 0x4003,
00221     KC_LALT              = 0x4004,
00222     KC_LWIN              = 0x4005,
00223     KC_RSHIFT            = 0x4006,
00224     KC_RCTRL             = 0x4007,
00225     KC_RALT              = 0x4008,
00226     KC_RWIN              = 0x4009,
00227     KC_INSERT            = 0x400a,
00228     KC_DELETE            = 0x400b,
00229     KC_HOME              = 0x400c,
00230     KC_END               = 0x400d,
00231     KC_PAGEUP            = 0x400e,
00232     KC_PAGEDOWN          = 0x400f,
00233     KC_SCROLLLOCK        = 0x4010,
00234     KC_PAUSE             = 0x4011,
00235 
00236     KC_UNKNOWN           = 0x6fff,
00237 
00238     KC_LAST_BUILTIN      = KC_UNKNOWN
00239 };
00240 
00244 enum MOUSEBUTTON
00245 {
00246     MB_1                 = 0,
00247     MB_LEFT              = 0,
00248     MB_2                 = 1,
00249     MB_RIGHT             = 1,
00250     MB_3                 = 2,
00251     MB_MIDDLE            = 2,
00252     MB_4                 = 3,
00253     MB_5                 = 4,
00254     MB_6                 = 5,
00255     MB_7                 = 6,
00256     MB_8                 = 7
00257 };
00258 
00259 
00265 class NEOENGINE_API InputEvent
00266 {
00267     public:
00268 
00270         int                                           m_iType;
00271 
00278         union
00279         {
00280           float                                       m_fData;
00281           int                                         m_iData;
00282           void                                       *m_pData;
00283         } m_aArgs[4];
00284 
00286         uint64_t                                      m_ulTimestamp;
00287 
00290                                                       InputEvent( int iType = 0, int iData0 = 0, int iData1 = 0, int iData2 = 0, int iData3 = 0 ) { m_iType = iType; m_aArgs[0].m_iData = iData0; m_aArgs[1].m_iData = iData1; m_aArgs[2].m_iData = iData2; m_aArgs[3].m_iData = iData3; }
00291 
00294                                                       InputEvent( int iType, float fData0 = 0.0f, float fData1 = 0.0f, float fData2 = 0.0f, float fData3 = 0 ) { m_iType = iType; m_aArgs[0].m_fData = fData0; m_aArgs[1].m_fData = fData1; m_aArgs[2].m_fData = fData2; m_aArgs[3].m_fData = fData3; }
00295 
00298                                                       InputEvent( int iType, void *pData0, void *pData1 = 0, void *pData2 = 0, void *pData3 = 0 ) { m_iType = iType; m_aArgs[0].m_pData = pData0; m_aArgs[1].m_pData = pData1; m_aArgs[2].m_pData = pData2; m_aArgs[3].m_pData = pData3; }
00299 };
00300 
00301 
00302 #ifdef WIN32
00303 #  ifdef _MSC_VER
00304 #    pragma warning( disable : 4231 )
00305 #  endif
00306 #  ifndef __HAVE_VECTOR_NEINPUTENTITY
00307      UDTVectorEXPIMP( class InputEntity* );
00308 #    define __HAVE_VECTOR_NEINPUTENTITY
00309 #  endif
00310 #endif
00311 
00312 
00318 class NEOENGINE_API InputGroup : public virtual Activator
00319 {
00320     friend class InputManager;
00321 
00322     protected:
00323 
00325         std::vector< InputEntity* >                   m_vpkInputObjects;
00326 
00328         InputManager                                 *m_pkManager;
00329 
00330 
00331 
00332     public:
00333 
00338                                                       InputGroup( InputManager *pkManager = 0 );
00339 
00343         virtual                                      ~InputGroup();
00344 
00349         void                                          AttachEntity( InputEntity *pkObject );
00350 
00355         void                                          DetachEntity( InputEntity *pkObject );
00356 
00361         void                                          Distribute( const std::vector< InputEvent* > &rvpkEvents );
00362 
00367         virtual void                                  Distribute( const InputEvent *pkEvent );
00368 
00372         InputManager                                 *GetManager() { return m_pkManager; }
00373 };
00374 
00375 
00376 #ifdef WIN32
00377 #  ifndef __HAVE_VECTOR_NEINPUTDEVICE
00378      UDTVectorEXPIMP( class InputDevice* );
00379 #    define __HAVE_VECTOR_NEINPUTDEVICE
00380 #  endif
00381 #  ifndef __HAVE_VECTOR_NEINPUTGROUP
00382      UDTVectorEXPIMP( class InputGroup* );
00383 #    define __HAVE_VECTOR_NEINPUTGROUP
00384 #  endif
00385 #endif
00386 
00387 
00393 class NEOENGINE_API InputManager
00394 {
00395     protected:
00396 
00398         std::vector< InputDevice* >                   m_vpkInputDevices;
00399 
00401         std::vector< InputGroup* >                    m_vpkInputGroups;
00402 
00403 
00404     public:
00405 
00408                                                       InputManager();
00409 
00412         virtual                                      ~InputManager();
00413 
00419         void                                          AttachDevice( InputDevice *pkDevice );
00420 
00426         void                                          AttachGroup( InputGroup *pkGroup );
00427 
00432         void                                          DetachDevice( InputDevice *pkDevice );
00433 
00438         void                                          DetachGroup( InputGroup *pkGroup );
00439 
00443         void                                          Process();
00444 };
00445 
00446 
00447 
00448 
00454 class NEOENGINE_API InputDevice : public virtual Activator
00455 {
00456     friend class InputManager;
00457     friend class Core;
00458 
00459     public:
00463         enum INPUTEVENTGROUP
00464         {
00466           SYSTEMINPUT                                 = 0x00000001,
00467 
00469           KEYBOARDINPUT                               = 0x00000002,
00470 
00472           MOUSEINPUT                                  = 0x00000004,
00473 
00475           JOYSTICKINPUT                               = 0x00000008
00476         };
00477 
00478 
00479     protected:
00480 
00482         InputManager                                 *m_pkManager;
00483 
00485         unsigned int                                  m_eInputEventGroups;
00486 
00487 
00492                                                       InputDevice( InputManager *pkManager );
00493 
00497         virtual                                      ~InputDevice();
00498 
00499 
00500     public:
00501 
00503         ModulePtr                                     m_pkModule;
00504 
00510         virtual bool                                  Collect( InputEvent *pkEvent ) = 0;
00511 
00516         virtual void                                  AddInputEventGroup( unsigned int uiInputEventGroup ) { m_eInputEventGroups |= uiInputEventGroup; }
00517 
00522         virtual void                                  DeleteInputEventGroup( unsigned int uiInputEventGroup ) { m_eInputEventGroups &= ~uiInputEventGroup; }
00523 
00529         virtual bool                                  HasInputEventGroup (unsigned int uiInputEventGroup ) { return (m_eInputEventGroups & uiInputEventGroup) != 0; }
00530 };
00531 
00532 
00533 };
00534 
00535 
00536 #endif

Generated on Wed Jan 21 14:21:06 2004 for NeoEngine by doxygen 1.3.5