src/control/joystickkeyboardcontroller.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
00018 #define HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
00019 
00020 #include "control/controller.hpp"
00021 
00022 #include <SDL.h>
00023 
00024 #include <map>
00025 #include <string>
00026 #include <vector>
00027 
00028 #include "util/reader_fwd.hpp"
00029 #include "util/writer_fwd.hpp"
00030 
00031 class Menu;
00032 class KeyboardMenu;
00033 class JoystickMenu;
00034 class Controller;
00035 
00036 class JoystickKeyboardController
00037 {
00038 private:
00039   friend class KeyboardMenu;
00040   friend class JoystickMenu;
00041 
00042   typedef Controller::Control Control;
00043   typedef Uint8 JoyId;
00044 
00045   typedef std::map<SDLKey, Control> KeyMap;
00046   typedef std::map<std::pair<JoyId, int>, Control> ButtonMap;
00047   typedef std::map<std::pair<JoyId, int>, Control> AxisMap;
00048   typedef std::map<std::pair<JoyId, int>, Control> HatMap;
00049 
00050 public:
00051   JoystickKeyboardController();
00052   virtual ~JoystickKeyboardController();
00053 
00056   void process_event(const SDL_Event& event);
00057 
00058   void write(Writer& writer);
00059   void read(const Reader& lisp);
00060   void update();
00061   void reset();
00062 
00063   void updateAvailableJoysticks();
00064 
00065   Controller *get_main_controller();
00066 
00067 private:
00068   void process_key_event(const SDL_KeyboardEvent& event);
00069   void process_hat_event(const SDL_JoyHatEvent& jhat);
00070   void process_axis_event(const SDL_JoyAxisEvent& jaxis);
00071   void process_button_event(const SDL_JoyButtonEvent& jbutton);
00072   void process_console_key_event(const SDL_KeyboardEvent& event);
00073   void process_menu_key_event(const SDL_KeyboardEvent& event);
00074 
00075   void print_joystick_mappings();
00076 
00077   SDLKey reversemap_key(Control c);
00078   int    reversemap_joybutton(Control c);
00079   int    reversemap_joyaxis(Control c);
00080   int    reversemap_joyhat(Control c);
00081 
00082   void unbind_joystick_control(Control c);
00083 
00084   void bind_joybutton(JoyId joy_id, int button, Control c);
00085   void bind_joyaxis(JoyId joy_id, int axis, Control c);
00086   void bind_joyhat(JoyId joy_id, int dir, Control c);
00087   void bind_key(SDLKey key, Control c);
00088 
00089   void set_joy_controls(Control id, bool value);
00090 
00091 private:
00092   Controller *controller;
00093 
00094   KeyMap keymap;
00095 
00096   ButtonMap joy_button_map;
00097 
00098   AxisMap joy_axis_map;
00099 
00100   HatMap joy_hat_map;
00101 
00102   std::vector<SDL_Joystick*> joysticks;
00103 
00104   std::string name;
00105 
00106   int dead_zone;
00108   int min_joybuttons;
00110   int max_joybuttons;
00111 
00112   int max_joyaxis;
00113 
00114   int max_joyhats;
00115 
00116   Uint8 hat_state;
00117 
00118   bool jump_with_up_joy; // Joystick up jumps
00119   bool jump_with_up_kbd; // Keyboard up jumps
00120 
00121   int wait_for_key;
00122   int wait_for_joystick;
00123 
00124 private:
00125   JoystickKeyboardController(const JoystickKeyboardController&);
00126   JoystickKeyboardController& operator=(const JoystickKeyboardController&);
00127 };
00128 
00129 #endif
00130 
00131 /* EOF */

Generated on Mon Jun 9 03:38:18 2014 for SuperTux by  doxygen 1.5.1