90930ead68b1b2f5750be376d85f08ecb34a7657
[supertux.git] / src / control / joystickkeyboardcontroller.hpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #ifndef __JOYSTICKKEYBOARDCONTROLLER_H__
22 #define __JOYSTICKKEYBOARDCONTROLLER_H__
23
24 #include "controller.hpp"
25 #include "lisp/lisp.hpp"
26 #include "lisp/writer.hpp"
27 #include <SDL.h>
28 #include <string>
29 #include <map>
30
31 class Menu;
32
33 class JoystickKeyboardController : public Controller
34 {
35 public:
36   JoystickKeyboardController();
37   virtual ~JoystickKeyboardController();
38
39   /** Process an SDL Event and return true if the event has been used
40    */
41   void process_event(const SDL_Event& event);
42
43   void write(lisp::Writer& writer);
44   void read(const lisp::Lisp& lisp);
45   void reset();
46
47   Menu* get_key_options_menu();
48   Menu* get_joystick_options_menu();
49
50 private:
51   void process_key_event(const SDL_Event& event);
52   void process_console_key_event(const SDL_Event& event);
53   void process_menu_key_event(const SDL_Event& event);
54   
55   typedef std::map<SDLKey, Control> KeyMap;
56   KeyMap keymap;
57
58   std::vector<SDL_Joystick*> joysticks;
59     
60   typedef std::map<int, Control> ButtonMap;
61   ButtonMap joy_button_map;
62   std::string name;
63   bool use_hat;
64   int joyaxis_x;
65   int joyaxis_y;
66   int dead_zone_x;
67   int dead_zone_y;
68   /// the number of buttons all joysticks have
69   int min_joybuttons;
70   /// the max number of buttons a joystick has
71   int max_joybuttons;
72 /*
73   enum {
74     MNID_KEY_UP,
75     MNID_KEY_DOWN,
76     MNID_KEY_LEFT,
77     MNID_KEY_RIGHT,
78     MNID_KEY_JUMP,
79     MNID_KEY_ACTION,
80     MNID_KEY_CONSOLE
81   };
82   enum {
83     MNID_JS_JUMP,
84     MNID_JS_ACTION,
85     MNID_JS_MENU,
86     MNID_JS_PAUSE
87   };
88   */
89   SDLKey reversemap_key(Control c);
90   int reversemap_joybutton(Control c);
91   void reset_joybutton(int button, Control c);
92   void reset_key(SDLKey key, Control c);
93
94   int wait_for_key;
95   int wait_for_joybutton;
96
97   class KeyboardMenu;
98   class JoystickMenu;
99   
100   KeyboardMenu* key_options_menu;
101   JoystickMenu* joystick_options_menu;
102   friend class KeyboardMenu;
103   friend class JoystickMenu;
104 };
105
106 #endif
107