diff options
author | AlTheKiller <AlTheKiller@svn> | 2009-09-23 01:49:50 +0000 |
---|---|---|
committer | AlTheKiller <AlTheKiller@svn> | 2009-09-23 01:49:50 +0000 |
commit | 45285e8a9300cd754a760560640b75b09f98035e (patch) | |
tree | ad9f093885ad5c98e9dd4156674e7691c22ed0a2 /guilib/common/SDLJoystick.h |
step 3/4: Move linuxport to trunk. How'd I get roped into this?
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23097 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'guilib/common/SDLJoystick.h')
-rw-r--r-- | guilib/common/SDLJoystick.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/guilib/common/SDLJoystick.h b/guilib/common/SDLJoystick.h new file mode 100644 index 0000000000..1aa89fecd4 --- /dev/null +++ b/guilib/common/SDLJoystick.h @@ -0,0 +1,78 @@ +#ifndef SDL_JOYSTICK_H +#define SDL_JOYSTICK_H + +#include "../system.h" +#include <vector> +#include <string> + +#ifdef HAS_SDL_JOYSTICK + +#include <SDL/SDL_joystick.h> +#include <SDL/SDL_events.h> + +#define MAX_AXES 64 + +#define JACTIVE_BUTTON 0x00000001 +#define JACTIVE_AXIS 0x00000002 +#define JACTIVE_HAT 0x00000004 +#define JACTIVE_NONE 0x00000000 + +// Class to manage all connected joysticks + +class CJoystick +{ +public: + CJoystick(); + + void Initialize(HWND hwnd); + void Reset(bool axis=false); + void CalibrateAxis(SDL_Joystick *joy); + void ResetAxis(int axisId) { m_Amount[axisId] = 0; } + void Update(); + void Update(SDL_Event& event); + float GetAmount(int axis) + { + if (m_Amount[axis]>0) + return (float)(m_Amount[axis]-m_SafeRange)/(32768.0f-(float)m_SafeRange); + return (float)(m_Amount[axis]+m_SafeRange)/(32768.0f-(float)m_SafeRange); + } + float GetAmount() + { + return GetAmount(m_AxisId); + } + bool GetButton (int& id, bool consider_repeat=true); + bool GetAxis (int &id) { if (!IsAxisActive()) return false; id=m_AxisId; return true; } + bool GetHat (int &id, int &position, bool consider_repeat=true); + std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; } + int GetAxisWithMaxAmount(); + void SetSafeRange(int val) { m_SafeRange=(val>32767)?32767:val; } + +private: + void SetAxisActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_AXIS):(m_ActiveFlags&(~JACTIVE_AXIS)); } + void SetButtonActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_BUTTON):(m_ActiveFlags&(~JACTIVE_BUTTON)); } + void SetHatActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_HAT):(m_ActiveFlags&(~JACTIVE_HAT)); } + bool IsButtonActive() { return (m_ActiveFlags & JACTIVE_BUTTON) == JACTIVE_BUTTON; } + bool IsAxisActive() { return (m_ActiveFlags & JACTIVE_AXIS) == JACTIVE_AXIS; } + bool IsHatActive() { return (m_ActiveFlags & JACTIVE_HAT) == JACTIVE_HAT; } + + int m_Amount[MAX_AXES]; + int m_DefaultAmount[MAX_AXES]; + int m_AxisId; + int m_ButtonId; + Uint8 m_HatState; + int m_HatId; + int m_JoyId; + int m_NumAxes; + int m_SafeRange; // dead zone + Uint32 m_pressTicksButton; + Uint32 m_pressTicksHat; + Uint8 m_ActiveFlags; + std::vector<SDL_Joystick*> m_Joysticks; + std::vector<std::string> m_JoystickNames; +}; + +extern CJoystick g_Joystick; + +#endif + +#endif |