1 | // SuperTux |
2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
3 | // 2014 Ingo Ruhnke <grumbel@gmail.com> |
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 3 of the License, or |
8 | // (at your option) 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 this program. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | #ifndef HEADER_SUPERTUX_CONTROL_JOYSTICK_MANAGER_HPP |
19 | #define |
20 | |
21 | #include <SDL.h> |
22 | #include <vector> |
23 | |
24 | #include "control/controller.hpp" |
25 | |
26 | class InputManager; |
27 | class JoystickConfig; |
28 | |
29 | class JoystickManager final |
30 | { |
31 | friend class KeyboardManager; |
32 | |
33 | public: |
34 | JoystickManager(InputManager* parent, JoystickConfig& joystick_config); |
35 | ~JoystickManager(); |
36 | |
37 | void process_hat_event(const SDL_JoyHatEvent& jhat); |
38 | void process_axis_event(const SDL_JoyAxisEvent& jaxis); |
39 | void process_button_event(const SDL_JoyButtonEvent& jbutton); |
40 | |
41 | void bind_next_event_to(Control id); |
42 | |
43 | void set_joy_controls(Control id, bool value); |
44 | |
45 | void on_joystick_added(int joystick_index); |
46 | void on_joystick_removed(int instance_id); |
47 | |
48 | int get_num_joysticks() const { return static_cast<int>(joysticks.size()); } |
49 | |
50 | private: |
51 | InputManager* parent; |
52 | JoystickConfig& m_joystick_config; |
53 | |
54 | /// the number of buttons all joysticks have |
55 | int min_joybuttons; |
56 | |
57 | /// the max number of buttons a joystick has |
58 | int max_joybuttons; |
59 | |
60 | int max_joyaxis; |
61 | int max_joyhats; |
62 | |
63 | Uint8 hat_state; |
64 | |
65 | int wait_for_joystick; |
66 | |
67 | std::vector<SDL_Joystick*> joysticks; |
68 | |
69 | private: |
70 | JoystickManager(const JoystickManager&) = delete; |
71 | JoystickManager& operator=(const JoystickManager&) = delete; |
72 | }; |
73 | |
74 | #endif |
75 | |
76 | /* EOF */ |
77 | |