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
25 #include "settings/lib/ISettingCallback.h"
29 #define JACTIVE_BUTTON 0x00000001
30 #define JACTIVE_AXIS 0x00000002
31 #define JACTIVE_HAT 0x00000004
32 #define JACTIVE_NONE 0x00000000
33 #define JACTIVE_HAT_UP 0x01
34 #define JACTIVE_HAT_RIGHT 0x02
35 #define JACTIVE_HAT_DOWN 0x04
36 #define JACTIVE_HAT_LEFT 0x08
38 #ifdef HAS_SDL_JOYSTICK
40 #include <SDL/SDL_joystick.h>
41 #include <SDL/SDL_events.h>
44 #define MAX_AXISAMOUNT 32768
47 // Class to manage all connected joysticks
49 class CJoystick : public ISettingCallback
54 virtual void OnSettingChanged(const CSetting *setting);
57 void Reset(bool axis=false);
58 void ResetAxis(int axisId) { m_Amount[axisId] = 0; }
60 void Update(SDL_Event& event);
61 bool GetButton (int& id, bool consider_repeat=true);
62 bool GetAxis (int &id);
63 bool GetHat (int &id, int &position, bool consider_repeat=true);
64 std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
65 int GetAxisWithMaxAmount();
66 float GetAmount(int axis);
67 float GetAmount() { return GetAmount(m_AxisId); }
68 bool IsEnabled() const { return m_joystickEnabled; }
69 void SetEnabled(bool enabled = true);
70 float SetDeadzone(float val);
74 void SetAxisActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_AXIS):(m_ActiveFlags&(~JACTIVE_AXIS)); }
75 void SetButtonActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_BUTTON):(m_ActiveFlags&(~JACTIVE_BUTTON)); }
76 void SetHatActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_HAT):(m_ActiveFlags&(~JACTIVE_HAT)); }
77 bool IsButtonActive() { return (m_ActiveFlags & JACTIVE_BUTTON) == JACTIVE_BUTTON; }
78 bool IsAxisActive() { return (m_ActiveFlags & JACTIVE_AXIS) == JACTIVE_AXIS; }
79 bool IsHatActive() { return (m_ActiveFlags & JACTIVE_HAT) == JACTIVE_HAT; }
81 bool ReleaseJoysticks();
83 int m_Amount[MAX_AXES];
91 bool m_joystickEnabled;
92 uint32_t m_pressTicksButton;
93 uint32_t m_pressTicksHat;
94 uint8_t m_ActiveFlags;
95 std::vector<SDL_Joystick*> m_Joysticks;
96 std::vector<std::string> m_JoystickNames;
99 extern CJoystick g_Joystick;