Implemented basic support for SDL GameController
[supertux.git] / src / control / joystickkeyboardcontroller.hpp
index f989ea6..411000b 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
 //
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-#ifndef __JOYSTICKKEYBOARDCONTROLLER_H__
-#define __JOYSTICKKEYBOARDCONTROLLER_H__
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include "controller.hpp"
+#ifndef HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
+#define HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
 
-namespace lisp {
-class Writer;
-class Lisp;
-}
+#include "control/controller.hpp"
 
 #include <SDL.h>
-
-#include <string>
 #include <map>
+#include <string>
 #include <vector>
+#include <memory>
 
+#include "util/reader_fwd.hpp"
+#include "util/writer_fwd.hpp"
+
+class Controller;
+class GameControllerManager;
+class JoystickManager;
+class JoystickMenu;
+class KeyboardMenu;
 class Menu;
 
-class JoystickKeyboardController : public Controller
+class JoystickKeyboardController
 {
+private:
+  friend class KeyboardMenu;
+  friend class JoystickMenu;
+
+  typedef Controller::Control Control;
+
+  typedef std::map<SDL_Keycode, Control> KeyMap;
+
 public:
   JoystickKeyboardController();
   virtual ~JoystickKeyboardController();
@@ -45,79 +53,43 @@ public:
    */
   void process_event(const SDL_Event& event);
 
-  void write(lisp::Writer& writer);
-  void read(const lisp::Lisp& lisp);
+  void write(Writer& writer);
+  void read(const Reader& lisp);
+  void update();
   void reset();
 
-  Menu* get_key_options_menu();
-  Menu* get_joystick_options_menu();
   void updateAvailableJoysticks();
 
-private:
-  void process_key_event(const SDL_Event& event);
-  void process_hat_event(const SDL_JoyHatEvent& jhat);
-  void process_axis_event(const SDL_JoyAxisEvent& jaxis);
-  void process_button_event(const SDL_JoyButtonEvent& jbutton);
-  void process_console_key_event(const SDL_Event& event);
-  void process_menu_key_event(const SDL_Event& event);
-
-  void print_joystick_mappings();
-
-  typedef std::map<SDLKey, Control> KeyMap;
-  KeyMap keymap;
-
-  typedef std::map<int, Control> ButtonMap;
-  ButtonMap joy_button_map;
-
-  typedef std::map<int, Control> AxisMap;
-  AxisMap joy_axis_map;
+  Controller *get_main_controller();
 
-  typedef std::map<int, Control> HatMap;
-  HatMap joy_hat_map;
-
-  std::vector<SDL_Joystick*> joysticks;
-
-  std::string name;
-
-  int dead_zone;
-  /// the number of buttons all joysticks have
-  int min_joybuttons;
-  /// the max number of buttons a joystick has
-  int max_joybuttons;
+private:
+  void process_text_input_event(const SDL_TextInputEvent& event);
+  void process_key_event(const SDL_KeyboardEvent& event);
+  void process_console_key_event(const SDL_KeyboardEvent& event);
+  void process_menu_key_event(const SDL_KeyboardEvent& event);
 
-  int max_joyaxis;
+  SDL_Keycode reversemap_key(Control c);
+  void bind_key(SDL_Keycode key, Control c);
 
-  int max_joyhats;
+private:
+  std::unique_ptr<Controller> controller;
+public:
+  bool m_use_game_controller;
+  std::unique_ptr<JoystickManager> joystick_manager;
+  std::unique_ptr<GameControllerManager> game_controller_manager;
 
-  Uint8 hat_state;
+private:
+  KeyMap keymap;
 
-  bool jump_with_up_joy; // Joystick up jumps
   bool jump_with_up_kbd; // Keyboard up jumps
 
-  SDLKey reversemap_key(Control c);
-  int    reversemap_joybutton(Control c);
-  int    reversemap_joyaxis(Control c);
-  int    reversemap_joyhat(Control c);
-
-  void unbind_joystick_control(Control c);
-
-  void bind_joybutton(int button, Control c);
-  void bind_joyaxis(int axis, Control c);
-  void bind_joyhat(int dir, Control c);
-  void bind_key(SDLKey key, Control c);
-
-  void set_joy_controls(Control id, bool value);
-
   int wait_for_key;
-  int wait_for_joystick;
-
-  class KeyboardMenu;
-  class JoystickMenu;
 
-  KeyboardMenu* key_options_menu;
-  JoystickMenu* joystick_options_menu;
-  friend class KeyboardMenu;
-  friend class JoystickMenu;
+private:
+  JoystickKeyboardController(const JoystickKeyboardController&);
+  JoystickKeyboardController& operator=(const JoystickKeyboardController&);
 };
 
 #endif
+
+/* EOF */