Make tux and yeti dying state not reveal secret tilemaps
[supertux.git] / src / control / joystick_manager.hpp
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 HEADER_SUPERTUX_CONTROL_JOYSTICK_MANAGER_HPP
20
21 #include <map>
22 #include <vector>
23
24 #include "SDL.h"
25
26 #include "control/controller.hpp"
27 #include "util/reader_fwd.hpp"
28 #include "util/writer_fwd.hpp"
29
30 class InputManager;
31 class JoystickConfig;
32
33 class JoystickManager final
34 {
35 private:
36   InputManager* parent;
37   JoystickConfig& m_joystick_config;
38
39   /// the number of buttons all joysticks have
40   int min_joybuttons;
41
42   /// the max number of buttons a joystick has
43   int max_joybuttons;
44
45   int max_joyaxis;
46   int max_joyhats;
47
48   Uint8 hat_state;
49
50   int wait_for_joystick;
51
52   std::vector<SDL_Joystick*> joysticks;
53
54   friend class KeyboardManager;
55
56 public:
57   JoystickManager(InputManager* parent, JoystickConfig& joystick_config);
58   ~JoystickManager();
59
60   void process_hat_event(const SDL_JoyHatEvent& jhat);
61   void process_axis_event(const SDL_JoyAxisEvent& jaxis);
62   void process_button_event(const SDL_JoyButtonEvent& jbutton);
63
64   void bind_next_event_to(Controller::Control id);
65
66   void set_joy_controls(Controller::Control id, bool value);
67
68   void on_joystick_added(int joystick_index);
69   void on_joystick_removed(int instance_id);
70
71   int get_num_joysticks() const { return static_cast<int>(joysticks.size()); }
72
73 private:
74   JoystickManager(const JoystickManager&) = delete;
75   JoystickManager& operator=(const JoystickManager&) = delete;
76 };
77
78 #endif
79
80 /* EOF */