supertux
keyboard_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_KEYBOARD_CONFIG_HPP
18 #define HEADER_SUPERTUX_CONTROL_KEYBOARD_CONFIG_HPP
19 
20 #include <SDL.h>
21 #include <map>
22 #include <set>
23 
24 #include "control/controller.hpp"
25 
26 class ReaderMapping;
27 class Writer;
28 
29 class KeyboardConfig final
30 {
31  friend class KeyboardManager;
32  friend class KeyboardMenu;
33 
34 public:
35  class PlayerControl final
36  {
37  public:
38  inline bool operator==(const PlayerControl& other) const
39  {
40  return player == other.player && control == other.control;
41  }
42 
43  public:
44  int player;
45  Control control;
46  };
47 
48 public:
50 
51  SDL_Keycode reversemap_key(int player, Control c) const;
52  void bind_key(SDL_Keycode key, int player, Control c);
53 
54  void read(const ReaderMapping& keymap_mapping);
55  void write(Writer& writer);
56 
57 private:
58  std::map<SDL_Keycode, PlayerControl> m_keymap;
59  std::set<Control> m_configurable_controls;
60  bool m_jump_with_up_kbd;
61 
62 private:
63  KeyboardConfig(const KeyboardConfig&) = delete;
64  KeyboardConfig& operator=(const KeyboardConfig&) = delete;
65 };
66 
67 #endif
68 
69 /* EOF */
Definition: keyboard_config.hpp:29
Definition: keyboard_manager.hpp:30
Definition: keyboard_config.hpp:35
Definition: keyboard_menu.hpp:26
Definition: reader_mapping.hpp:32
Definition: writer.cpp:23