Fix for coverity #29402
[supertux.git] / src / control / 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 #include "lisp/lisp.hpp"
25 #include "util/writer.hpp"
26
27 class JoystickConfig
28 {
29 public:
30   typedef Uint8 JoyId;
31   typedef std::map<std::pair<JoyId, int>, Controller::Control> ButtonMap;
32   typedef std::map<std::pair<JoyId, int>, Controller::Control> AxisMap;
33   typedef std::map<std::pair<JoyId, int>, Controller::Control> HatMap;
34
35 public:
36   int dead_zone;
37   bool jump_with_up_joy;
38
39   ButtonMap joy_button_map;
40   AxisMap joy_axis_map;
41   HatMap joy_hat_map;
42
43 public:
44   JoystickConfig();
45
46   void print_joystick_mappings();
47
48   int reversemap_joybutton(Controller::Control c);
49   int reversemap_joyaxis(Controller::Control c);
50   int reversemap_joyhat(Controller::Control c);
51
52   void unbind_joystick_control(Controller::Control c);
53
54   void bind_joybutton(JoyId joy_id, int button, Controller::Control c);
55   void bind_joyaxis(JoyId joy_id, int axis, Controller::Control c);
56   void bind_joyhat(JoyId joy_id, int dir, Controller::Control c);
57
58   void read(const lisp::Lisp& joystick_lisp);
59   void write(Writer& writer);
60
61 private:
62   JoystickConfig(const JoystickConfig&) = delete;
63   JoystickConfig& operator=(const JoystickConfig&) = delete;
64 };
65
66 #endif
67
68 /* EOF */