Only refresh menu items that have been created in the JoystickMenu to avoid crash
[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 public:
51   int wait_for_joystick;
52
53 public:
54   std::vector<SDL_Joystick*> joysticks;
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 set_joy_controls(Controller::Control id, bool value);
65
66   void on_joystick_added(int joystick_index);
67   void on_joystick_removed(int instance_id);
68
69 private:
70   JoystickManager(const JoystickManager&) = delete;
71   JoystickManager& operator=(const JoystickManager&) = delete;
72 };
73
74 #endif
75
76 /* EOF */