Fixed text input in console, console itself doesn't handle unicode correctly, so...
[supertux.git] / src / control / joystickkeyboardcontroller.hpp
index 9b6a39f..705b7bc 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 <SDL_keycode.h> // add by giby
 #include <map>
+#include <string>
+#include <vector>
+
+#include "util/reader_fwd.hpp"
+#include "util/writer_fwd.hpp"
 
 class Menu;
+class KeyboardMenu;
+class JoystickMenu;
+class Controller;
 
-class JoystickKeyboardController : public Controller
+    //SDL_JoystickID myID = SDL_JoystickInstanceID(myOpenedStick);
+
+class JoystickKeyboardController // http://wiki.libsdl.org/moin.fcg/SDL_Joystick for info 
 {
+private:
+  friend class KeyboardMenu;
+  friend class JoystickMenu;
+
+  typedef Controller::Control Control;
+  typedef Uint8 JoyId;
+
+  typedef std::map<SDL_Keycode, Control> KeyMap;
+  typedef std::map<std::pair<JoyId, int>, Control> ButtonMap;
+  typedef std::map<std::pair<JoyId, int>, Control> AxisMap;
+  typedef std::map<std::pair<JoyId, int>, Control> HatMap;
+
 public:
   JoystickKeyboardController();
   virtual ~JoystickKeyboardController();
@@ -39,33 +57,49 @@ 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_key_event(const SDL_Event& event);
+  void process_text_input_event(const SDL_TextInputEvent& event);
+  void process_key_event(const SDL_KeyboardEvent& 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 process_console_key_event(const SDL_KeyboardEvent& event);
+  void process_menu_key_event(const SDL_KeyboardEvent& event);
 
   void print_joystick_mappings();
 
-  typedef std::map<SDLKey, Control> KeyMap;
+  SDL_Keycode 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(JoyId joy_id, int button, Control c);
+  void bind_joyaxis(JoyId joy_id, int axis, Control c);
+  void bind_joyhat(JoyId joy_id, int dir, Control c);
+  void bind_key(SDL_Keycode key, Control c);
+
+  void set_joy_controls(Control id, bool value); 
+
+private:
+  Controller *controller;
+
   KeyMap keymap;
 
-  typedef std::map<int, Control> ButtonMap;
   ButtonMap joy_button_map;
 
-  typedef std::map<int, Control> AxisMap;
   AxisMap joy_axis_map;
 
-  typedef std::map<int, Control> HatMap;
   HatMap joy_hat_map;
 
   std::vector<SDL_Joystick*> joysticks;
@@ -87,30 +121,14 @@ private:
   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 */