00001 #ifndef _MERCURY_INPUT_H
00002 #define _MERCURY_INPUT_H
00003
00004 #include <map>
00005 #include "MercuryString.h"
00006 #include "MercuryVector.h"
00007
00009 enum EventType
00010 {
00011 IET_NONE,
00012 IET_DOWN,
00013 IET_RELEASE,
00014 IET_REPEAT,
00015 };
00016
00018 class InputEvent
00019 {
00020 public:
00021 InputEvent( ) : DeviceNumber( 0 ), ButtonNumber( 0 ), Type( IET_NONE ) { }
00022 InputEvent( int DevNum, int BtnNum, EventType IET ) :
00023 DeviceNumber( DevNum ), ButtonNumber( BtnNum ), Type ( IET )
00024 { }
00026 int DeviceNumber;
00028 int ButtonNumber;
00030 EventType Type;
00031 };
00032
00034 class InputDevice
00035 {
00036 public:
00037 virtual ~InputDevice() {};
00038
00039 virtual void Init( MString Name ) = 0;
00040 virtual bool IsButtonDown( int ButtonNumber ) = 0;
00041 virtual int NumButtons() = 0;
00042 virtual void Update( );
00043 virtual InputEvent PopLastEvent() = 0;
00044 };
00045
00047 class InputDeviceTracker
00048 {
00049 public:
00050 ~InputDeviceTracker();
00051 bool AddDevice( MString Name, InputDevice * Device );
00052 InputDevice* ToDevice( MString Name );
00053 MString ListAvailableDevices();
00054 private:
00055 std::map < MString, InputDevice * > *m_pDevices;
00056 };
00057
00058 extern InputDeviceTracker AutoInputDeviceTracker;
00059
00061 class CursorDevice
00062 {
00063 public:
00064 CursorDevice();
00065 virtual ~CursorDevice() {};
00066
00067 virtual void GetPosition( int &x, int &y ) = 0;
00068 virtual void Update( ) = 0;
00069 static void UpdateFocus( const MString &message, void * data, void * info );
00070 protected:
00071 int m_x, m_y;
00072 int m_Xoff, m_Yoff;
00073 static bool m_bHasFocus;
00074 bool m_bSubscribed;
00075 };
00076
00077 extern CursorDevice * DefaultCursorDevice;
00078
00080 class MercuryInputManager
00081 {
00082 public:
00083 MercuryInputManager( );
00084 ~MercuryInputManager( ) { };
00085
00087 void Update();
00088
00090 bool IsButtonDown( int DeviceNumber, int ButtonNumber )
00091 { return m_vDevices[DeviceNumber]->IsButtonDown( ButtonNumber); }
00092
00094 bool IsButtonDown( int code );
00095
00097 InputEvent PopLastEvent();
00098
00100 bool GetCursorPosition( int &x, int &y )
00101 { if ( DefaultCursorDevice != NULL ) {
00102 DefaultCursorDevice->GetPosition( x, y );
00103 return true; } return false;}
00104
00105 private:
00106 MVector< InputDevice * > m_vDevices;
00107 };
00108
00109 extern MercuryInputManager * INPUTMAN;
00110
00112 class InputMappingTracker
00113 {
00114 public:
00115 ~InputMappingTracker()
00116 { delete m_pMappings; }
00117
00118 void ReadInMappingsFromINI();
00119 int MakeMappingCode( const MString& Name );
00120 int MakeMappingCode( const MString& Name, const MString Default );
00121
00123 int InputEventNameToCode( const MString & IE );
00124 int InputEventToCode( const InputEvent & IE );
00125 void CodeToHardware( int code, MVector<InputEvent> &out );
00126 private:
00127 std::map < MString, int > *m_pMappings;
00128 std::map < MString, int > *m_pCodes;
00129 std::map < MString, MString > *m_pAutoCodes;
00130 MVector< MVector<InputEvent> > m_vDemapped;
00131 int m_iCurMapNumber;
00132 };
00133
00134 extern InputMappingTracker AutoInputMappingTracker;
00135
00137 #define KeyMapping( x ) \
00138 const int x = AutoInputMappingTracker.MakeMappingCode( #x )
00139
00140 #define KeyMappingWithCode( x, y ) \
00141 const int x = AutoInputMappingTracker.MakeMappingCode( #x, y )
00142
00143 class PStack;
00145 struct InputMessageStruct
00146 {
00147 InputMessageStruct();
00148 InputMessageStruct( PStack & toload );
00149 int device;
00150 int button;
00151 int code;
00152 EventType type;
00153 };
00154
00156 class DeviceNull : public InputDevice
00157 {
00158 public:
00159 virtual ~DeviceNull() {};
00160
00161 virtual void Init( MString Name ) { };
00162 virtual bool IsButtonDown( int ButtonNumber ) { return false; }
00163 virtual int NumButtons() { return 0; }
00164 virtual void Update( ) { }
00165 virtual InputEvent PopLastEvent() { return InputEvent( 0,0,IET_NONE); }
00166 };
00167
00168 enum AllKBKeys
00169 {
00170 KB_0,
00171 KB_MOUSE1,
00172 KB_MOUSE2,
00173 KB_3,
00174 KB_4,
00175 KB_5
00176 };
00177
00178 char KeyToChar( char cHardwareChar, bool bShiftPressed );
00179
00180 #endif
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209