joystickCtrl.h
Go to the documentation of this file.00001 #ifndef JOYSTICK_CTRL_H
00002 #define JOYSTICK_CTRL_H
00003
00013 #include "sdlBase.h"
00014 #include "typeUtils.h"
00015 #include <SDL.h>
00016 #include <deque>
00017 #include <vector>
00018
00019
00023 class JoystickCtrl : private SDL_Base {
00024 friend class UserInput;
00025
00026 static bool joystick_initialized;
00027
00028 class EachJoystick {
00029 public:
00030 EachJoystick(void)
00031 : ptr(NULL), used(false) {}
00032 ~EachJoystick(void) {}
00033 SDL_Joystick* ptr;
00034 bool used;
00035 int num_axis;
00036
00037
00038 int num_buttons;
00039 std::vector<short> axis_value;
00040 std::deque<bool> buttons_value;
00041 };
00042
00043 class JoystickResource {
00044 public:
00045 JoystickResource(void) : num_max(0), used_num(0) {}
00046 ~JoystickResource(void) {}
00047 int num_max;
00048 int used_num;
00049 std::vector<EachJoystick> js;
00050 };
00051 static JoystickResource jsr;
00052 int own_index;
00053
00054 static void initJoystickSystem(void);
00055 static void init(void);
00056 static void joyAxisEventHandler(SDL_JoyAxisEvent& event);
00057 static void joyBallEventHandler(SDL_JoyBallEvent& event);
00058 static void joyHatEventHandler(SDL_JoyHatEvent& event);
00059 static void joyButtonEventHandler(SDL_JoyButtonEvent& event);
00060 JoystickCtrl(const JoystickCtrl& rhs);
00061
00062 public:
00063 enum { FreeIndex = -1 };
00064 JoystickCtrl(void);
00065 ~JoystickCtrl(void);
00066
00072 const char* what(void);
00073
00082 bool activate(int index = FreeIndex);
00083
00089 static int size(void);
00090
00098 static void joystickEventHandler(SDL_Event& event);
00099
00105 bool isActivated(void) const;
00106
00112 int getNumAxis(void) const;
00113
00119 int getNumButtons(void) const;
00120
00127 short getAxisValue(int index) const;
00128
00135 bool getButtonValue(int index) const;
00136 };
00137
00138 #endif
00139