2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
3 // 2007 Ingo Ruhnke <grumbel@gmx.de>
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 #include "control/input_manager.hpp"
22 #include "control/keyboard_manager.hpp"
23 #include "control/joystick_manager.hpp"
24 #include "control/game_controller_manager.hpp"
25 #include "gui/menu_manager.hpp"
26 #include "lisp/list_iterator.hpp"
27 #include "supertux/gameconfig.hpp"
28 #include "util/gettext.hpp"
29 #include "util/writer.hpp"
31 InputManager::InputManager() :
32 controller(new Controller),
33 m_use_game_controller(true),
34 keyboard_manager(new KeyboardManager(this)),
35 joystick_manager(new JoystickManager(this)),
36 game_controller_manager(new GameControllerManager(this))
40 InputManager::~InputManager()
45 InputManager::get_controller()
47 return controller.get();
51 InputManager::use_game_controller(bool v)
53 m_use_game_controller = v;
57 InputManager::read(const Reader& lisp)
59 const lisp::Lisp* keymap_lisp = lisp.get_lisp("keymap");
62 keyboard_manager->read(keymap_lisp);
65 const lisp::Lisp* joystick_lisp = lisp.get_lisp(_("joystick"));
68 joystick_manager->read(joystick_lisp);
73 InputManager::write(Writer& writer)
75 writer.start_list("keymap");
76 keyboard_manager->write(writer);
77 writer.end_list("keymap");
79 writer.start_list("joystick");
80 joystick_manager->write(writer);
81 writer.end_list("joystick");
85 InputManager::update()
97 InputManager::process_event(const SDL_Event& event)
101 keyboard_manager->process_text_input_event(event.text);
106 keyboard_manager->process_key_event(event.key);
109 case SDL_JOYAXISMOTION:
110 if (!m_use_game_controller) joystick_manager->process_axis_event(event.jaxis);
113 case SDL_JOYHATMOTION:
114 if (!m_use_game_controller) joystick_manager->process_hat_event(event.jhat);
117 case SDL_JOYBUTTONDOWN:
118 case SDL_JOYBUTTONUP:
119 if (!m_use_game_controller) joystick_manager->process_button_event(event.jbutton);
122 case SDL_JOYDEVICEADDED:
123 joystick_manager->on_joystick_added(event.jdevice.which);
126 case SDL_JOYDEVICEREMOVED:
127 joystick_manager->on_joystick_removed(event.jdevice.which);
130 case SDL_CONTROLLERAXISMOTION:
131 if (m_use_game_controller) game_controller_manager->process_axis_event(event.caxis);
134 case SDL_CONTROLLERBUTTONDOWN:
135 if (m_use_game_controller) game_controller_manager->process_button_event(event.cbutton);
138 case SDL_CONTROLLERBUTTONUP:
139 if (m_use_game_controller) game_controller_manager->process_button_event(event.cbutton);
142 case SDL_CONTROLLERDEVICEADDED:
143 std::cout << "SDL_CONTROLLERDEVICEADDED" << std::endl;
144 game_controller_manager->on_controller_added(event.cdevice.which);
147 case SDL_CONTROLLERDEVICEREMOVED:
148 std::cout << "SDL_CONTROLLERDEVICEREMOVED" << std::endl;
149 game_controller_manager->on_controller_removed(event.cdevice.which);
152 case SDL_CONTROLLERDEVICEREMAPPED:
153 std::cout << "SDL_CONTROLLERDEVICEREMAPPED" << std::endl;