2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // 2014 Ingo Ruhnke <grumbel@gmail.com>
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.
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 this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef HEADER_SUPERTUX_CONTROL_JOYSTICK_MANAGER_HPP
19 #define HEADER_SUPERTUX_CONTROL_JOYSTICK_MANAGER_HPP
26 #include "control/controller.hpp"
27 #include "util/reader_fwd.hpp"
28 #include "util/writer_fwd.hpp"
32 class JoystickManager final
37 typedef std::map<std::pair<JoyId, int>, Controller::Control> ButtonMap;
38 typedef std::map<std::pair<JoyId, int>, Controller::Control> AxisMap;
39 typedef std::map<std::pair<JoyId, int>, Controller::Control> HatMap;
44 ButtonMap joy_button_map;
50 /// the number of buttons all joysticks have
53 /// the max number of buttons a joystick has
62 bool jump_with_up_joy;
65 int wait_for_joystick;
68 std::vector<SDL_Joystick*> joysticks;
71 JoystickManager(InputManager* parent);
74 void process_hat_event(const SDL_JoyHatEvent& jhat);
75 void process_axis_event(const SDL_JoyAxisEvent& jaxis);
76 void process_button_event(const SDL_JoyButtonEvent& jbutton);
78 void print_joystick_mappings();
80 int reversemap_joybutton(Controller::Control c);
81 int reversemap_joyaxis(Controller::Control c);
82 int reversemap_joyhat(Controller::Control c);
84 void unbind_joystick_control(Controller::Control c);
86 void bind_joybutton(JoyId joy_id, int button, Controller::Control c);
87 void bind_joyaxis(JoyId joy_id, int axis, Controller::Control c);
88 void bind_joyhat(JoyId joy_id, int dir, Controller::Control c);
90 void set_joy_controls(Controller::Control id, bool value);
92 void on_joystick_added(int joystick_index);
93 void on_joystick_removed(int instance_id);
95 void read(const lisp::Lisp* joystick_lisp);
96 void write(Writer& writer);
99 JoystickManager(const JoystickManager&) = delete;
100 JoystickManager& operator=(const JoystickManager&) = delete;