Implemented basic support for SDL GameController
[supertux.git] / src / control / joystickkeyboardcontroller.hpp
index 7d88932..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.
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
+#define HEADER_SUPERTUX_CONTROL_JOYSTICKKEYBOARDCONTROLLER_HPP
 
-#ifndef __JOYSTICKKEYBOARDCONTROLLER_H__
-#define __JOYSTICKKEYBOARDCONTROLLER_H__
+#include "control/controller.hpp"
 
-#include "controller.hpp"
-#include "lisp/lisp.hpp"
-#include "lisp/writer.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();
@@ -39,67 +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();
+
+  Controller *get_main_controller();
+
+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);
+
+  SDL_Keycode reversemap_key(Control c);
+  void bind_key(SDL_Keycode key, Control c);
 
 private:
-  void process_key_event(const SDL_Event& event);
-  void process_console_key_event(const SDL_Event& event);
-  void process_menu_key_event(const SDL_Event& event);
+  std::unique_ptr<Controller> controller;
+public:
+  bool m_use_game_controller;
+  std::unique_ptr<JoystickManager> joystick_manager;
+  std::unique_ptr<GameControllerManager> game_controller_manager;
 
-  typedef std::map<SDLKey, Control> KeyMap;
+private:
   KeyMap keymap;
 
-  std::vector<SDL_Joystick*> joysticks;
-
-  typedef std::map<int, Control> ButtonMap;
-  ButtonMap joy_button_map;
-  std::string name;
-  bool use_hat;
-  int joyaxis_x;
-  int joyaxis_y;
-  int dead_zone_x;
-  int dead_zone_y;
-  /// the number of buttons all joysticks have
-  int min_joybuttons;
-  /// the max number of buttons a joystick has
-  int max_joybuttons;
-/*
-  enum {
-    MNID_KEY_UP,
-    MNID_KEY_DOWN,
-    MNID_KEY_LEFT,
-    MNID_KEY_RIGHT,
-    MNID_KEY_JUMP,
-    MNID_KEY_ACTION,
-    MNID_KEY_CONSOLE
-  };
-  enum {
-    MNID_JS_JUMP,
-    MNID_JS_ACTION,
-    MNID_JS_MENU,
-    MNID_JS_PAUSE
-  };
-  */
-  SDLKey reversemap_key(Control c);
-  int reversemap_joybutton(Control c);
-  void reset_joybutton(int button, Control c);
-  void reset_key(SDLKey key, Control c);
+  bool jump_with_up_kbd; // Keyboard up jumps
 
   int wait_for_key;
-  int wait_for_joybutton;
 
-  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 */