E:/Download/ois-1.0RC1/includes/OISJoyStick.h

Go to the documentation of this file.
00001 /*
00002 The zlib/libpng License
00003 
00004 Copyright (c) 2006 Phillip Castaneda (pjcast -- www.wreckedgames.com)
00005 
00006 This software is provided 'as-is', without any express or implied warranty. In no event will
00007 the authors be held liable for any damages arising from the use of this software.
00008 
00009 Permission is granted to anyone to use this software for any purpose, including commercial
00010 applications, and to alter it and redistribute it freely, subject to the following
00011 restrictions:
00012 
00013     1. The origin of this software must not be misrepresented; you must not claim that
00014                 you wrote the original software. If you use this software in a product,
00015                 an acknowledgment in the product documentation would be appreciated but is
00016                 not required.
00017 
00018     2. Altered source versions must be plainly marked as such, and must not be
00019                 misrepresented as being the original software.
00020 
00021     3. This notice may not be removed or altered from any source distribution.
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;    //Currently, joysticks only report Abs
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                 //Joystick Event, amd sliderID
00123                 virtual bool sliderMoved( const JoyStickEvent &, int ) {return true;}
00124                 //Joystick Event, amd povID
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

Generated on Sat Dec 1 20:13:51 2007 for OIS by  doxygen 1.5.4