Reverted r6576, Menus don't belong into JoystickKeyboardController
[supertux.git] / src / control / joystickkeyboardcontroller.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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_JOYSTICKKEYBOARDCONTROLLER_HPP
18 #define HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
19
20 #include "control/controller.hpp"
21
22 #include <SDL.h>
23
24 #include <map>
25 #include <string>
26 #include <vector>
27
28 #include "util/reader_fwd.hpp"
29 #include "util/writer_fwd.hpp"
30
31 class Menu;
32 class KeyboardMenu;
33 class JoystickMenu;
34
35 class JoystickKeyboardController : public Controller
36 {
37 public:
38   JoystickKeyboardController();
39   virtual ~JoystickKeyboardController();
40
41   /** Process an SDL Event and return true if the event has been used
42    */
43   void process_event(const SDL_Event& event);
44
45   void write(Writer& writer);
46   void read(const Reader& lisp);
47   void reset();
48
49   Menu* get_key_options_menu();
50   Menu* get_joystick_options_menu();
51   void updateAvailableJoysticks();
52
53 private:
54   void process_key_event(const SDL_Event& event);
55   void process_hat_event(const SDL_JoyHatEvent& jhat);
56   void process_axis_event(const SDL_JoyAxisEvent& jaxis);
57   void process_button_event(const SDL_JoyButtonEvent& jbutton);
58   void process_console_key_event(const SDL_Event& event);
59   void process_menu_key_event(const SDL_Event& event);
60
61   void print_joystick_mappings();
62
63   SDLKey reversemap_key(Control c);
64   int    reversemap_joybutton(Control c);
65   int    reversemap_joyaxis(Control c);
66   int    reversemap_joyhat(Control c);
67
68   void unbind_joystick_control(Control c);
69
70   void bind_joybutton(int button, Control c);
71   void bind_joyaxis(int axis, Control c);
72   void bind_joyhat(int dir, Control c);
73   void bind_key(SDLKey key, Control c);
74
75   void set_joy_controls(Control id, bool value);
76
77 private:
78   friend class KeyboardMenu;
79   friend class JoystickMenu;
80
81   typedef std::map<SDLKey, Control> KeyMap;
82   typedef std::map<int, Control> ButtonMap;
83   typedef std::map<int, Control> AxisMap;
84   typedef std::map<int, Control> HatMap;
85
86 private:
87   KeyMap keymap;
88
89   ButtonMap joy_button_map;
90
91   AxisMap joy_axis_map;
92
93   HatMap joy_hat_map;
94
95   std::vector<SDL_Joystick*> joysticks;
96
97   std::string name;
98
99   int dead_zone;
100   /// the number of buttons all joysticks have
101   int min_joybuttons;
102   /// the max number of buttons a joystick has
103   int max_joybuttons;
104
105   int max_joyaxis;
106
107   int max_joyhats;
108
109   Uint8 hat_state;
110
111   bool jump_with_up_joy; // Joystick up jumps
112   bool jump_with_up_kbd; // Keyboard up jumps
113
114   int wait_for_key;
115   int wait_for_joystick;
116
117 private:
118   JoystickKeyboardController(const JoystickKeyboardController&);
119   JoystickKeyboardController& operator=(const JoystickKeyboardController&);
120 };
121
122 #endif
123
124 /* EOF */