00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef OIS_Joystick_H
00024 #define OIS_Joystick_H
00025 #include "OISObject.h"
00026 #include "OISEvents.h"
00027
00028 namespace OIS
00029 {
00031 struct _OISExport Pov : Component
00032 {
00033 Pov() : Component(OIS_POV), direction(0) {}
00034
00035 static const int Centered = 0x00000000;
00036 static const int North = 0x00000001;
00037 static const int South = 0x00000010;
00038 static const int East = 0x00000100;
00039 static const int West = 0x00001000;
00040 static const int NorthEast = 0x00000101;
00041 static const int SouthEast = 0x00000110;
00042 static const int NorthWest = 0x00001001;
00043 static const int SouthWest = 0x00001010;
00044
00045 int direction;
00046 };
00047
00049 struct _OISExport Slider : Component
00050 {
00051 Slider() : Component(OIS_Slider), abX(0), abY(0) {};
00053 int abX, abY;
00054 };
00055
00061 struct _OISExport JoyStickState
00062 {
00063 JoyStickState() : buttons(0) { clear(); }
00064
00066 std::vector<Axis> mAxes;
00067
00069 Pov mPOV[4];
00070
00072 Slider mSliders[4];
00073
00075 int buttons;
00076
00078 inline int buttonDown( int button ) const
00079 {
00080 return ((buttons & ( 1L << button )) == 0) ? false : true;
00081 }
00082
00084 void clear()
00085 {
00086 buttons = 0;
00087 for( std::vector<Axis>::iterator i = mAxes.begin(), e = mAxes.end(); i != e; ++i )
00088 {
00089 (*i).absOnly = true;
00090 (*i).clear();
00091 }
00092 }
00093 };
00094
00096 class _OISExport JoyStickEvent : public EventArg
00097 {
00098 public:
00099 JoyStickEvent( Object* obj, const JoyStickState &st ) : EventArg(obj), state(st) {}
00100 virtual ~JoyStickEvent() {}
00101
00102 const JoyStickState &state;
00103 };
00104
00112 class _OISExport JoyStickListener
00113 {
00114 public:
00115 virtual ~JoyStickListener() {}
00116
00117 virtual bool buttonPressed( const JoyStickEvent &arg, int button ) = 0;
00118 virtual bool buttonReleased( const JoyStickEvent &arg, int button ) = 0;
00119
00120 virtual bool axisMoved( const JoyStickEvent &arg, int axis ) = 0;
00121
00122
00123 virtual bool sliderMoved( const JoyStickEvent &, int ) {return true;}
00124
00125 virtual bool povMoved( const JoyStickEvent &, int ) {return true;}
00126 };
00127
00132 class _OISExport JoyStick : public Object
00133 {
00134 public:
00135 virtual ~JoyStick() {}
00136
00138 short buttons() {return numButtons;}
00139
00141 short axes() {return numAxes;}
00142
00144 short hats() {return numHats;}
00145
00153 virtual void setEventCallback( JoyStickListener *joyListener ) {listener = joyListener;}
00154
00156 JoyStickListener* getEventCallback() {return listener;}
00157
00159 const JoyStickState& getJoyStickState() const { return mState; }
00160
00162 static const int MIN_AXIS = -32768;
00163
00165 static const int MAX_AXIS = 32767;
00166
00167 protected:
00168 JoyStick() : numButtons(0), numAxes(0), numHats(0), listener(0) {}
00169
00170 short numButtons;
00171 short numAxes;
00172 short numHats;
00173
00174 JoyStickState mState;
00175
00176 JoyStickListener *listener;
00177 };
00178 }
00179 #endif