[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / input / SDLJoystick.h
1 /*
2 *      Copyright (C) 2007-2013 Team XBMC
3 *      http://www.xbmc.org
4 *
5 *  This Program is free software; you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation; either version 2, or (at your option)
8 *  any later version.
9 *
10 *  This Program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with XBMC; see the file COPYING.  If not, see
17 *  <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #ifndef SDL_JOYSTICK_H
22 #define SDL_JOYSTICK_H
23
24 #include "system.h" // for HAS_SDL_JOYSTICK
25 #include <vector>
26 #include <string>
27
28 #define JACTIVE_BUTTON 0x00000001
29 #define JACTIVE_AXIS   0x00000002
30 #define JACTIVE_HAT    0x00000004
31 #define JACTIVE_NONE   0x00000000
32 #define JACTIVE_HAT_UP    0x01
33 #define JACTIVE_HAT_RIGHT 0x02
34 #define JACTIVE_HAT_DOWN  0x04
35 #define JACTIVE_HAT_LEFT  0x08
36
37 #ifdef HAS_SDL_JOYSTICK
38
39 #include <SDL/SDL_joystick.h>
40 #include <SDL/SDL_events.h>
41
42 #define MAX_AXES 64
43 #define MAX_AXISAMOUNT 32768
44
45
46 // Class to manage all connected joysticks
47
48 class CJoystick
49 {
50 public:
51   CJoystick();
52
53   void Initialize();
54   void Reset(bool axis=false);
55   void ResetAxis(int axisId) { m_Amount[axisId] = 0; }
56   void Update();
57   void Update(SDL_Event& event);
58   bool GetButton (int& id, bool consider_repeat=true);
59   bool GetAxis (int &id);
60   bool GetHat (int &id, int &position, bool consider_repeat=true);
61   std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
62   int GetAxisWithMaxAmount();
63   float GetAmount(int axis);
64   float GetAmount() { return GetAmount(m_AxisId); }
65   bool IsEnabled() const { return m_joystickEnabled; }
66   void SetEnabled(bool enabled = true);
67   float SetDeadzone(float val);
68   bool Reinitialize();
69
70 private:
71   void SetAxisActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_AXIS):(m_ActiveFlags&(~JACTIVE_AXIS)); }
72   void SetButtonActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_BUTTON):(m_ActiveFlags&(~JACTIVE_BUTTON)); }
73   void SetHatActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_HAT):(m_ActiveFlags&(~JACTIVE_HAT)); }
74   bool IsButtonActive() { return (m_ActiveFlags & JACTIVE_BUTTON) == JACTIVE_BUTTON; }
75   bool IsAxisActive() { return (m_ActiveFlags & JACTIVE_AXIS) == JACTIVE_AXIS; }
76   bool IsHatActive() { return (m_ActiveFlags & JACTIVE_HAT) == JACTIVE_HAT; }
77
78   bool ReleaseJoysticks();
79
80   int m_Amount[MAX_AXES];
81   int m_AxisId;
82   int m_ButtonId;
83   uint8_t m_HatState;
84   int m_HatId; 
85   int m_JoyId;
86   int m_NumAxes;
87   int m_DeadzoneRange;
88   bool m_joystickEnabled;
89   uint32_t m_pressTicksButton;
90   uint32_t m_pressTicksHat;
91   uint8_t m_ActiveFlags;
92   std::vector<SDL_Joystick*> m_Joysticks;
93   std::vector<std::string> m_JoystickNames;
94 };
95
96 extern CJoystick g_Joystick;
97
98 #endif
99
100 #endif