2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
17 #ifndef HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
18 #define HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
20 #include "control/controller.hpp"
28 #include "util/reader_fwd.hpp"
29 #include "util/writer_fwd.hpp"
36 class JoystickKeyboardController
39 friend class KeyboardMenu;
40 friend class JoystickMenu;
42 typedef Controller::Control Control;
45 typedef std::map<SDLKey, Control> KeyMap;
46 typedef std::map<std::pair<JoyId, int>, Control> ButtonMap;
47 typedef std::map<std::pair<JoyId, int>, Control> AxisMap;
48 typedef std::map<std::pair<JoyId, int>, Control> HatMap;
51 JoystickKeyboardController();
52 virtual ~JoystickKeyboardController();
54 /** Process an SDL Event and return true if the event has been used
56 void process_event(const SDL_Event& event);
58 void write(Writer& writer);
59 void read(const Reader& lisp);
63 void updateAvailableJoysticks();
65 Controller *get_main_controller();
68 void process_key_event(const SDL_KeyboardEvent& event);
69 void process_hat_event(const SDL_JoyHatEvent& jhat);
70 void process_axis_event(const SDL_JoyAxisEvent& jaxis);
71 void process_button_event(const SDL_JoyButtonEvent& jbutton);
72 void process_console_key_event(const SDL_KeyboardEvent& event);
73 void process_menu_key_event(const SDL_KeyboardEvent& event);
75 void print_joystick_mappings();
77 SDLKey reversemap_key(Control c);
78 int reversemap_joybutton(Control c);
79 int reversemap_joyaxis(Control c);
80 int reversemap_joyhat(Control c);
82 void unbind_joystick_control(Control c);
84 void bind_joybutton(JoyId joy_id, int button, Control c);
85 void bind_joyaxis(JoyId joy_id, int axis, Control c);
86 void bind_joyhat(JoyId joy_id, int dir, Control c);
87 void bind_key(SDLKey key, Control c);
89 void set_joy_controls(Control id, bool value);
92 Controller *controller;
96 ButtonMap joy_button_map;
102 std::vector<SDL_Joystick*> joysticks;
107 /// the number of buttons all joysticks have
109 /// the max number of buttons a joystick has
118 bool jump_with_up_joy; // Joystick up jumps
119 bool jump_with_up_kbd; // Keyboard up jumps
122 int wait_for_joystick;
125 JoystickKeyboardController(const JoystickKeyboardController&);
126 JoystickKeyboardController& operator=(const JoystickKeyboardController&);