Split control/joystickkeyboardcontroller.?pp
authorgrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Wed, 18 Nov 2009 03:16:33 +0000 (03:16 +0000)
committergrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Wed, 18 Nov 2009 03:16:33 +0000 (03:16 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6025 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/control/joystick_menu.cpp [new file with mode: 0644]
src/control/joystick_menu.hpp [new file with mode: 0644]
src/control/joystickkeyboardcontroller.cpp
src/control/joystickkeyboardcontroller.hpp
src/control/keyboard_menu.cpp [new file with mode: 0644]
src/control/keyboard_menu.hpp [new file with mode: 0644]

diff --git a/src/control/joystick_menu.cpp b/src/control/joystick_menu.cpp
new file mode 100644 (file)
index 0000000..f55c8a9
--- /dev/null
@@ -0,0 +1,185 @@
+//  SuperTux
+//  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.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 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
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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, see <http://www.gnu.org/licenses/>.
+
+#include "control/joystick_menu.hpp"
+
+#include <sstream>
+
+#include "util/gettext.hpp"
+#include "supertux/gameconfig.hpp"
+
+namespace{
+  const int SCAN_JOYSTICKS = Controller::CONTROLCOUNT + 1;
+}
+
+JoystickMenu::JoystickMenu(JoystickKeyboardController* _controller) :
+  controller(_controller)
+{
+  recreateMenu();
+}
+
+JoystickMenu::~JoystickMenu()
+{}
+
+void
+JoystickMenu::recreateMenu()
+{
+  clear();
+  add_label(_("Setup Joystick"));
+  add_hl();
+  if(controller->joysticks.size() > 0) {
+    add_controlfield(Controller::UP,          _("Up"));
+    add_controlfield(Controller::DOWN,        _("Down"));
+    add_controlfield(Controller::LEFT,        _("Left"));
+    add_controlfield(Controller::RIGHT,       _("Right"));
+    add_controlfield(Controller::JUMP,        _("Jump"));
+    add_controlfield(Controller::ACTION,      _("Action"));
+    add_controlfield(Controller::PAUSE_MENU,  _("Pause/Menu"));
+    add_controlfield(Controller::PEEK_LEFT,   _("Peek Left"));
+    add_controlfield(Controller::PEEK_RIGHT,  _("Peek Right"));
+    add_controlfield(Controller::PEEK_UP,     _("Peek Up"));
+    add_controlfield(Controller::PEEK_DOWN,   _("Peek Down"));
+
+    add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_joy);
+  } else {
+    add_inactive(-1, _("No Joysticks found"));
+  }
+  add_inactive(-1,"");
+  add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks"));
+
+  //Show Joysticks currently activated:
+  for(std::vector<SDL_Joystick*>::iterator i = controller->joysticks.begin();
+      i != controller->joysticks.end(); ++i) {
+    if(*i != 0)
+      add_inactive(-1, SDL_JoystickName(SDL_JoystickIndex(*i)) );
+  }
+
+  add_hl();
+  add_back(_("Back"));
+  update();
+}
+
+std::string
+JoystickMenu::get_button_name(int button)
+{
+  if(button < 0)
+    return _("None");
+
+  std::ostringstream name;
+  name << "Button " << button;
+  return name.str();
+}
+
+void
+JoystickMenu::menu_action(MenuItem* item)
+{
+  if (item->id >= 0 && item->id < Controller::CONTROLCOUNT) {
+    item->change_input(_("Press Button"));
+    controller->wait_for_joystick = item->id;
+  } else if (item->id == Controller::CONTROLCOUNT) {
+    controller->jump_with_up_joy = item->toggled;
+  } else if( item->id == SCAN_JOYSTICKS) {
+    controller->updateAvailableJoysticks();
+    recreateMenu();
+  }
+}
+
+void
+JoystickMenu::update_menu_item(Controller::Control id)
+{
+  int button  = controller->reversemap_joybutton(id);
+  int axis    = controller->reversemap_joyaxis(id);
+  int hat_dir = controller->reversemap_joyhat(id);
+
+  if (button != -1) {
+    get_item_by_id((int)id).change_input(get_button_name(button));
+  } else if (axis != 0) {
+    std::ostringstream name;
+
+    name << "Axis ";
+
+    if (axis < 0)
+      name << "-";
+    else
+      name << "+";
+
+    if (abs(axis) == 1)
+      name << "X";
+    else if (abs(axis) == 2)
+      name << "Y";
+    else if (abs(axis) == 2)
+      name << "X2";
+    else if (abs(axis) == 3)
+      name << "Y2";
+    else
+      name << abs(axis);
+
+    get_item_by_id((int)id).change_input(name.str());
+  } else if (hat_dir != -1) {
+    std::string name;
+
+    switch (hat_dir)
+    {
+      case SDL_HAT_UP:
+        name = "Hat Up";
+        break;
+
+      case SDL_HAT_DOWN:
+        name = "Hat Down";
+        break;
+
+      case SDL_HAT_LEFT:
+        name = "Hat Left";
+        break;
+
+      case SDL_HAT_RIGHT:
+        name = "Hat Right";
+        break;
+
+      default:
+        name = "Unknown hat_dir";
+        break;
+    }
+
+    get_item_by_id((int)id).change_input(name);
+  } else {
+    get_item_by_id((int)id).change_input("None");
+  }
+}
+
+void
+JoystickMenu::update()
+{
+  if(controller->joysticks.size() == 0)
+    return;
+
+  update_menu_item(Controller::UP);
+  update_menu_item(Controller::DOWN);
+  update_menu_item(Controller::LEFT);
+  update_menu_item(Controller::RIGHT);
+
+  update_menu_item(Controller::JUMP);
+  update_menu_item(Controller::ACTION);
+  update_menu_item(Controller::PAUSE_MENU);
+  update_menu_item(Controller::PEEK_LEFT);
+  update_menu_item(Controller::PEEK_RIGHT);
+  update_menu_item(Controller::PEEK_UP);
+  update_menu_item(Controller::PEEK_DOWN);
+
+  get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_joy;
+}
+
+/* EOF */
diff --git a/src/control/joystick_menu.hpp b/src/control/joystick_menu.hpp
new file mode 100644 (file)
index 0000000..ff186fd
--- /dev/null
@@ -0,0 +1,48 @@
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
+//                2007 Ingo Ruhnke <grumbel@gmx.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 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
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_CONTROL_JOYSTICK_MENU_HPP
+#define HEADER_SUPERTUX_CONTROL_JOYSTICK_MENU_HPP
+
+#include "control/joystickkeyboardcontroller.hpp"
+#include "control/controller.hpp"
+#include "gui/menu.hpp"
+#include "gui/menu_item.hpp"
+
+class JoystickMenu : public Menu
+{
+public:
+  JoystickMenu(JoystickKeyboardController* controller);
+  virtual ~JoystickMenu();
+
+  void update();
+  std::string get_button_name(int button);
+  void update_menu_item(Controller::Control id);
+  virtual void menu_action(MenuItem* item);
+  JoystickKeyboardController* controller;
+
+private:
+  void recreateMenu();
+
+private:
+  JoystickMenu(const JoystickMenu&);
+  JoystickMenu& operator=(const JoystickMenu&);
+};
+
+#endif
+
+/* EOF */
index 006fb2c..6a613a8 100644 (file)
 
 #include <iostream>
 
-#include "gui/menu.hpp"
-#include "gui/menu_item.hpp"
+#include "control/joystick_menu.hpp"
+#include "control/keyboard_menu.hpp"
 #include "util/writer.hpp"
 #include "lisp/list_iterator.hpp"
 #include "supertux/gameconfig.hpp"
 #include "supertux/console.hpp"
 #include "util/gettext.hpp"
 
-namespace{
-  const int SCAN_JOYSTICKS = Controller::CONTROLCOUNT + 1;
-}
-
-class JoystickKeyboardController::JoystickMenu : public Menu
-{
-public:
-  JoystickMenu(JoystickKeyboardController* controller);
-  virtual ~JoystickMenu();
-
-  void update();
-  std::string get_button_name(int button);
-  void update_menu_item(Control id);
-  virtual void menu_action(MenuItem* item);
-  JoystickKeyboardController* controller;
-
-private:
-  void recreateMenu();
-
-private:
-  JoystickMenu(const JoystickMenu&);
-  JoystickMenu& operator=(const JoystickMenu&);
-};
-
-class JoystickKeyboardController::KeyboardMenu : public Menu
-{
-public:
-  KeyboardMenu(JoystickKeyboardController* controller);
-  ~KeyboardMenu();
-
-  void update();
-  std::string get_key_name(SDLKey key);
-  virtual void menu_action(MenuItem* item);
-  JoystickKeyboardController* controller;
-
-private:
-  KeyboardMenu(const KeyboardMenu&);
-  KeyboardMenu& operator=(const KeyboardMenu&);
-};
-
 JoystickKeyboardController::JoystickKeyboardController() :
   keymap(),
   joy_button_map(),
@@ -817,271 +777,4 @@ JoystickKeyboardController::get_joystick_options_menu()
   return joystick_options_menu;
 }
 
-//----------------------------------------------------------------------------
-
-JoystickKeyboardController::KeyboardMenu::KeyboardMenu(
-  JoystickKeyboardController* _controller)
-  : controller(_controller)
-{
-  add_label(_("Setup Keyboard"));
-  add_hl();
-  add_controlfield(Controller::UP,         _("Up"));
-  add_controlfield(Controller::DOWN,       _("Down"));
-  add_controlfield(Controller::LEFT,       _("Left"));
-  add_controlfield(Controller::RIGHT,      _("Right"));
-  add_controlfield(Controller::JUMP,       _("Jump"));
-  add_controlfield(Controller::ACTION,     _("Action"));
-  add_controlfield(Controller::PEEK_LEFT,  _("Peek Left"));
-  add_controlfield(Controller::PEEK_RIGHT, _("Peek Right"));
-  add_controlfield(Controller::PEEK_UP,    _("Peek Up"));
-  add_controlfield(Controller::PEEK_DOWN,  _("Peek Down"));
-  if (g_config->console_enabled) {
-    add_controlfield(Controller::CONSOLE, _("Console"));
-  }
-  add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_kbd);
-  add_hl();
-  add_back(_("Back"));
-  update();
-}
-
-JoystickKeyboardController::KeyboardMenu::~KeyboardMenu()
-{}
-
-std::string
-JoystickKeyboardController::KeyboardMenu::get_key_name(SDLKey key)
-{
-  switch(key) {
-    case SDLK_UNKNOWN:
-      return _("None");
-    case SDLK_UP:
-      return _("Up cursor");
-    case SDLK_DOWN:
-      return _("Down cursor");
-    case SDLK_LEFT:
-      return _("Left cursor");
-    case SDLK_RIGHT:
-      return _("Right cursor");
-    case SDLK_RETURN:
-      return _("Return");
-    case SDLK_SPACE:
-      return _("Space");
-    case SDLK_RSHIFT:
-      return _("Right Shift");
-    case SDLK_LSHIFT:
-      return _("Left Shift");
-    case SDLK_RCTRL:
-      return _("Right Control");
-    case SDLK_LCTRL:
-      return _("Left Control");
-    case SDLK_RALT:
-      return _("Right Alt");
-    case SDLK_LALT:
-      return _("Left Alt");
-    default:
-      return SDL_GetKeyName((SDLKey) key);
-  }
-}
-
-void
-JoystickKeyboardController::KeyboardMenu::menu_action(MenuItem* item)
-{
-  if(item->id >= 0 && item->id < Controller::CONTROLCOUNT){
-    item->change_input(_("Press Key"));
-    controller->wait_for_key = item->id;
-  } else if( item->id == Controller::CONTROLCOUNT) {
-    controller->jump_with_up_kbd = item->toggled;
-  } 
-}
-
-void
-JoystickKeyboardController::KeyboardMenu::update()
-{
-  // update menu
-  get_item_by_id((int) Controller::UP).change_input(get_key_name(
-                                                      controller->reversemap_key(Controller::UP)));
-  get_item_by_id((int) Controller::DOWN).change_input(get_key_name(
-                                                        controller->reversemap_key(Controller::DOWN)));
-  get_item_by_id((int) Controller::LEFT).change_input(get_key_name(
-                                                        controller->reversemap_key(Controller::LEFT)));
-  get_item_by_id((int) Controller::RIGHT).change_input(get_key_name(
-                                                         controller->reversemap_key(Controller::RIGHT)));
-  get_item_by_id((int) Controller::JUMP).change_input(get_key_name(
-                                                        controller->reversemap_key(Controller::JUMP)));
-  get_item_by_id((int) Controller::ACTION).change_input(get_key_name(
-                                                          controller->reversemap_key(Controller::ACTION)));
-  get_item_by_id((int) Controller::PEEK_LEFT).change_input(get_key_name(
-                                                             controller->reversemap_key(Controller::PEEK_LEFT)));
-  get_item_by_id((int) Controller::PEEK_RIGHT).change_input(get_key_name(
-                                                              controller->reversemap_key(Controller::PEEK_RIGHT)));
-  get_item_by_id((int) Controller::PEEK_UP).change_input(get_key_name(
-                                                           controller->reversemap_key(Controller::PEEK_UP)));
-  get_item_by_id((int) Controller::PEEK_DOWN).change_input(get_key_name(
-                                                             controller->reversemap_key(Controller::PEEK_DOWN)));
-  if (g_config->console_enabled) {
-    get_item_by_id((int) Controller::CONSOLE).change_input(get_key_name(
-                                                             controller->reversemap_key(Controller::CONSOLE)));
-  }
-  get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_kbd;
-}
-
-//---------------------------------------------------------------------------
-
-JoystickKeyboardController::JoystickMenu::JoystickMenu(
-  JoystickKeyboardController* _controller)
-  : controller(_controller)
-{
-  recreateMenu();
-}
-
-JoystickKeyboardController::JoystickMenu::~JoystickMenu()
-{}
-
-void
-JoystickKeyboardController::JoystickMenu::recreateMenu()
-{
-  clear();
-  add_label(_("Setup Joystick"));
-  add_hl();
-  if(controller->joysticks.size() > 0) {
-    add_controlfield(Controller::UP,          _("Up"));
-    add_controlfield(Controller::DOWN,        _("Down"));
-    add_controlfield(Controller::LEFT,        _("Left"));
-    add_controlfield(Controller::RIGHT,       _("Right"));
-    add_controlfield(Controller::JUMP,        _("Jump"));
-    add_controlfield(Controller::ACTION,      _("Action"));
-    add_controlfield(Controller::PAUSE_MENU,  _("Pause/Menu"));
-    add_controlfield(Controller::PEEK_LEFT,   _("Peek Left"));
-    add_controlfield(Controller::PEEK_RIGHT,  _("Peek Right"));
-    add_controlfield(Controller::PEEK_UP,     _("Peek Up"));
-    add_controlfield(Controller::PEEK_DOWN,   _("Peek Down"));
-
-    add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_joy);
-  } else {
-    add_inactive(-1, _("No Joysticks found"));
-  }
-  add_inactive(-1,"");
-  add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks"));
-
-  //Show Joysticks currently activated:
-  for(std::vector<SDL_Joystick*>::iterator i = controller->joysticks.begin();
-      i != controller->joysticks.end(); ++i) {
-    if(*i != 0)
-      add_inactive(-1, SDL_JoystickName(SDL_JoystickIndex(*i)) );
-  }
-
-  add_hl();
-  add_back(_("Back"));
-  update();
-}
-
-std::string
-JoystickKeyboardController::JoystickMenu::get_button_name(int button)
-{
-  if(button < 0)
-    return _("None");
-
-  std::ostringstream name;
-  name << "Button " << button;
-  return name.str();
-}
-
-void
-JoystickKeyboardController::JoystickMenu::menu_action(MenuItem* item)
-{
-  if (item->id >= 0 && item->id < Controller::CONTROLCOUNT) {
-    item->change_input(_("Press Button"));
-    controller->wait_for_joystick = item->id;
-  } else if (item->id == Controller::CONTROLCOUNT) {
-    controller->jump_with_up_joy = item->toggled;
-  } else if( item->id == SCAN_JOYSTICKS) {
-    controller->updateAvailableJoysticks();
-    recreateMenu();
-  }
-}
-
-void
-JoystickKeyboardController::JoystickMenu::update_menu_item(Control id)
-{
-  int button  = controller->reversemap_joybutton(id);
-  int axis    = controller->reversemap_joyaxis(id);
-  int hat_dir = controller->reversemap_joyhat(id);
-
-  if (button != -1) {
-    get_item_by_id((int)id).change_input(get_button_name(button));
-  } else if (axis != 0) {
-    std::ostringstream name;
-
-    name << "Axis ";
-
-    if (axis < 0)
-      name << "-";
-    else
-      name << "+";
-
-    if (abs(axis) == 1)
-      name << "X";
-    else if (abs(axis) == 2)
-      name << "Y";
-    else if (abs(axis) == 2)
-      name << "X2";
-    else if (abs(axis) == 3)
-      name << "Y2";
-    else
-      name << abs(axis);
-
-    get_item_by_id((int)id).change_input(name.str());
-  } else if (hat_dir != -1) {
-    std::string name;
-
-    switch (hat_dir)
-    {
-      case SDL_HAT_UP:
-        name = "Hat Up";
-        break;
-
-      case SDL_HAT_DOWN:
-        name = "Hat Down";
-        break;
-
-      case SDL_HAT_LEFT:
-        name = "Hat Left";
-        break;
-
-      case SDL_HAT_RIGHT:
-        name = "Hat Right";
-        break;
-
-      default:
-        name = "Unknown hat_dir";
-        break;
-    }
-
-    get_item_by_id((int)id).change_input(name);
-  } else {
-    get_item_by_id((int)id).change_input("None");
-  }
-}
-
-void
-JoystickKeyboardController::JoystickMenu::update()
-{
-  if(controller->joysticks.size() == 0)
-    return;
-
-  update_menu_item(Controller::UP);
-  update_menu_item(Controller::DOWN);
-  update_menu_item(Controller::LEFT);
-  update_menu_item(Controller::RIGHT);
-
-  update_menu_item(Controller::JUMP);
-  update_menu_item(Controller::ACTION);
-  update_menu_item(Controller::PAUSE_MENU);
-  update_menu_item(Controller::PEEK_LEFT);
-  update_menu_item(Controller::PEEK_RIGHT);
-  update_menu_item(Controller::PEEK_UP);
-  update_menu_item(Controller::PEEK_DOWN);
-
-  get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_joy;
-}
-
 /* EOF */
index 5af4263..2a66f16 100644 (file)
@@ -29,6 +29,8 @@
 #include "util/writer_fwd.hpp"
 
 class Menu;
+class KeyboardMenu;
+class JoystickMenu;
 
 class JoystickKeyboardController : public Controller
 {
@@ -73,9 +75,6 @@ private:
   void set_joy_controls(Control id, bool value);
 
 private:
-  class KeyboardMenu;
-  class JoystickMenu;
-
   friend class KeyboardMenu;
   friend class JoystickMenu;
 
diff --git a/src/control/keyboard_menu.cpp b/src/control/keyboard_menu.cpp
new file mode 100644 (file)
index 0000000..9216787
--- /dev/null
@@ -0,0 +1,127 @@
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
+//                2007 Ingo Ruhnke <grumbel@gmx.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 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
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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, see <http://www.gnu.org/licenses/>.
+
+#include "control/keyboard_menu.hpp"
+
+#include "util/gettext.hpp"
+#include "supertux/gameconfig.hpp"
+
+KeyboardMenu::KeyboardMenu(JoystickKeyboardController* _controller) :
+  controller(_controller)
+{
+  add_label(_("Setup Keyboard"));
+  add_hl();
+  add_controlfield(Controller::UP,         _("Up"));
+  add_controlfield(Controller::DOWN,       _("Down"));
+  add_controlfield(Controller::LEFT,       _("Left"));
+  add_controlfield(Controller::RIGHT,      _("Right"));
+  add_controlfield(Controller::JUMP,       _("Jump"));
+  add_controlfield(Controller::ACTION,     _("Action"));
+  add_controlfield(Controller::PEEK_LEFT,  _("Peek Left"));
+  add_controlfield(Controller::PEEK_RIGHT, _("Peek Right"));
+  add_controlfield(Controller::PEEK_UP,    _("Peek Up"));
+  add_controlfield(Controller::PEEK_DOWN,  _("Peek Down"));
+  if (g_config->console_enabled) {
+    add_controlfield(Controller::CONSOLE, _("Console"));
+  }
+  add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_kbd);
+  add_hl();
+  add_back(_("Back"));
+  update();
+}
+
+KeyboardMenu::~KeyboardMenu()
+{}
+
+std::string
+KeyboardMenu::get_key_name(SDLKey key)
+{
+  switch(key) {
+    case SDLK_UNKNOWN:
+      return _("None");
+    case SDLK_UP:
+      return _("Up cursor");
+    case SDLK_DOWN:
+      return _("Down cursor");
+    case SDLK_LEFT:
+      return _("Left cursor");
+    case SDLK_RIGHT:
+      return _("Right cursor");
+    case SDLK_RETURN:
+      return _("Return");
+    case SDLK_SPACE:
+      return _("Space");
+    case SDLK_RSHIFT:
+      return _("Right Shift");
+    case SDLK_LSHIFT:
+      return _("Left Shift");
+    case SDLK_RCTRL:
+      return _("Right Control");
+    case SDLK_LCTRL:
+      return _("Left Control");
+    case SDLK_RALT:
+      return _("Right Alt");
+    case SDLK_LALT:
+      return _("Left Alt");
+    default:
+      return SDL_GetKeyName((SDLKey) key);
+  }
+}
+
+void
+KeyboardMenu::menu_action(MenuItem* item)
+{
+  if(item->id >= 0 && item->id < Controller::CONTROLCOUNT){
+    item->change_input(_("Press Key"));
+    controller->wait_for_key = item->id;
+  } else if( item->id == Controller::CONTROLCOUNT) {
+    controller->jump_with_up_kbd = item->toggled;
+  } 
+}
+
+void
+KeyboardMenu::update()
+{
+  // update menu
+  get_item_by_id((int) Controller::UP).change_input(get_key_name(
+                                                      controller->reversemap_key(Controller::UP)));
+  get_item_by_id((int) Controller::DOWN).change_input(get_key_name(
+                                                        controller->reversemap_key(Controller::DOWN)));
+  get_item_by_id((int) Controller::LEFT).change_input(get_key_name(
+                                                        controller->reversemap_key(Controller::LEFT)));
+  get_item_by_id((int) Controller::RIGHT).change_input(get_key_name(
+                                                         controller->reversemap_key(Controller::RIGHT)));
+  get_item_by_id((int) Controller::JUMP).change_input(get_key_name(
+                                                        controller->reversemap_key(Controller::JUMP)));
+  get_item_by_id((int) Controller::ACTION).change_input(get_key_name(
+                                                          controller->reversemap_key(Controller::ACTION)));
+  get_item_by_id((int) Controller::PEEK_LEFT).change_input(get_key_name(
+                                                             controller->reversemap_key(Controller::PEEK_LEFT)));
+  get_item_by_id((int) Controller::PEEK_RIGHT).change_input(get_key_name(
+                                                              controller->reversemap_key(Controller::PEEK_RIGHT)));
+  get_item_by_id((int) Controller::PEEK_UP).change_input(get_key_name(
+                                                           controller->reversemap_key(Controller::PEEK_UP)));
+  get_item_by_id((int) Controller::PEEK_DOWN).change_input(get_key_name(
+                                                             controller->reversemap_key(Controller::PEEK_DOWN)));
+  if (g_config->console_enabled) {
+    get_item_by_id((int) Controller::CONSOLE).change_input(get_key_name(
+                                                             controller->reversemap_key(Controller::CONSOLE)));
+  }
+  get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_kbd;
+}
+
+/* EOF */
diff --git a/src/control/keyboard_menu.hpp b/src/control/keyboard_menu.hpp
new file mode 100644 (file)
index 0000000..83b1908
--- /dev/null
@@ -0,0 +1,43 @@
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
+//                2007 Ingo Ruhnke <grumbel@gmx.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 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
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_CONTROL_KEYBOARD_MENU_HPP
+#define HEADER_SUPERTUX_CONTROL_KEYBOARD_MENU_HPP
+
+#include "control/joystickkeyboardcontroller.hpp"
+#include "gui/menu.hpp"
+#include "gui/menu_item.hpp"
+
+class KeyboardMenu : public Menu
+{
+public:
+  KeyboardMenu(JoystickKeyboardController* controller);
+  ~KeyboardMenu();
+
+  void update();
+  std::string get_key_name(SDLKey key);
+  virtual void menu_action(MenuItem* item);
+  JoystickKeyboardController* controller;
+
+private:
+  KeyboardMenu(const KeyboardMenu&);
+  KeyboardMenu& operator=(const KeyboardMenu&);
+};
+
+#endif
+
+/* EOF */