supertux
joystick_config.hpp
1 // SuperTux
2 // Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_CONTROL_JOYSTICK_CONFIG_HPP
18 #define HEADER_SUPERTUX_CONTROL_JOYSTICK_CONFIG_HPP
19 
20 #include <map>
21 #include <SDL.h>
22 
23 #include "control/controller.hpp"
24 
25 class ReaderMapping;
26 class Writer;
27 
28 class JoystickConfig final
29 {
30  friend class InputManager;
31  friend class JoystickManager;
32  friend class JoystickMenu;
33 
34 public:
35  using JoystickID = SDL_JoystickID;
36 
37 public:
39 
40  void print_joystick_mappings() const;
41 
42  int reversemap_joybutton(Control c) const;
43  int reversemap_joyaxis(Control c) const;
44  int reversemap_joyhat(Control c) const;
45 
46  void unbind_joystick_control(Control c);
47 
48  void bind_joybutton(JoystickID joy_id, int button, Control c);
49  void bind_joyaxis(JoystickID joy_id, int axis, Control c);
50  void bind_joyhat(JoystickID joy_id, int dir, Control c);
51 
52  void read(const ReaderMapping& joystick_mapping);
53  void write(Writer& writer);
54 
55 private:
56  int m_dead_zone;
57  bool m_jump_with_up_joy;
58  bool m_use_game_controller;
59 
60  std::map<std::pair<JoystickID, int>, Control> m_joy_button_map;
61  std::map<std::pair<JoystickID, int>, Control> m_joy_axis_map;
62  std::map<std::pair<JoystickID, int>, Control> m_joy_hat_map;
63 
64 private:
65  JoystickConfig(const JoystickConfig&) = delete;
66  JoystickConfig& operator=(const JoystickConfig&) = delete;
67 };
68 
69 #endif
70 
71 /* EOF */
Manages Joysticks.
Definition: joystick_manager.hpp:36
Definition: input_manager.hpp:39
Definition: joystick_config.hpp:28
Definition: reader_mapping.hpp:32
Definition: writer.cpp:23
Definition: joystick_menu.hpp:24