2 * Copyright (C) 2007-2013 Team XBMC
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)
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.
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/>.
21 #ifndef SDL_JOYSTICK_H
22 #define SDL_JOYSTICK_H
24 #include "system.h" // for HAS_SDL_JOYSTICK
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
37 #ifdef HAS_SDL_JOYSTICK
39 #include <SDL/SDL_joystick.h>
40 #include <SDL/SDL_events.h>
43 #define MAX_AXISAMOUNT 32768
46 // Class to manage all connected joysticks
54 void Reset(bool axis=false);
55 void ResetAxis(int axisId) { m_Amount[axisId] = 0; }
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);
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; }
78 bool ReleaseJoysticks();
80 int m_Amount[MAX_AXES];
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;
96 extern CJoystick g_Joystick;