Moved some more menu stuff out of control/joystickkeyboardcontroller.cpp
authorIngo Ruhnke <grumbel@gmx.de>
Thu, 19 Nov 2009 05:18:11 +0000 (05:18 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Thu, 19 Nov 2009 05:18:11 +0000 (05:18 +0000)
SVN-Revision: 6044

src/control/joystickkeyboardcontroller.cpp
src/control/joystickkeyboardcontroller.hpp
src/supertux/menu/menu_storage.cpp
src/supertux/menu/menu_storage.hpp
src/supertux/menu/options_menu.cpp

index 53a252d..761c6a0 100644 (file)
@@ -23,6 +23,7 @@
 #include "gui/menu_manager.hpp"
 #include "supertux/console.hpp"
 #include "supertux/gameconfig.hpp"
+#include "supertux/menu/menu_storage.hpp"
 #include "supertux/menu/joystick_menu.hpp"
 #include "supertux/menu/keyboard_menu.hpp"
 #include "util/gettext.hpp"
@@ -44,9 +45,7 @@ JoystickKeyboardController::JoystickKeyboardController() :
   jump_with_up_joy(),
   jump_with_up_kbd(),
   wait_for_key(-1), 
-  wait_for_joystick(-1),
-  key_options_menu(0), 
-  joystick_options_menu(0)
+  wait_for_joystick(-1)
 {
   // initialize default keyboard map
   keymap[SDLK_LEFT]     = LEFT;
@@ -109,9 +108,6 @@ JoystickKeyboardController::~JoystickKeyboardController()
     if(*i != 0)
       SDL_JoystickClose(*i);
   }
-
-  delete key_options_menu;
-  delete joystick_options_menu;
 }
 
 void
@@ -357,7 +353,7 @@ JoystickKeyboardController::process_button_event(const SDL_JoyButtonEvent& jbutt
     if(jbutton.state == SDL_PRESSED)
     {
       bind_joybutton(jbutton.button, (Control)wait_for_joystick);
-      joystick_options_menu->update();
+      MenuStorage::get_joystick_options_menu()->update();
       reset();
       wait_for_joystick = -1;
     }
@@ -384,7 +380,7 @@ JoystickKeyboardController::process_axis_event(const SDL_JoyAxisEvent& jaxis)
       else
         bind_joyaxis(jaxis.axis + 1, Control(wait_for_joystick));
 
-      joystick_options_menu->update();
+      MenuStorage::get_joystick_options_menu()->update();
       wait_for_joystick = -1;
     }
   }
@@ -440,7 +436,7 @@ JoystickKeyboardController::process_hat_event(const SDL_JoyHatEvent& jhat)
     if (changed & SDL_HAT_RIGHT && jhat.value & SDL_HAT_RIGHT)
       bind_joyhat(SDL_HAT_RIGHT, (Control)wait_for_joystick);
 
-    joystick_options_menu->update();
+    MenuStorage::get_joystick_options_menu()->update();
     wait_for_joystick = -1;
   }
   else
@@ -567,14 +563,14 @@ JoystickKeyboardController::process_menu_key_event(const SDL_Event& event)
       bind_key(event.key.keysym.sym, (Control) wait_for_key);
     }
     reset();
-    key_options_menu->update();
+    MenuStorage::get_key_options_menu()->update();
     wait_for_key = -1;
     return;
   }
   if(wait_for_joystick >= 0) {
     if(event.key.keysym.sym == SDLK_ESCAPE) {
       reset();
-      joystick_options_menu->update();
+      MenuStorage::get_joystick_options_menu()->update();
       wait_for_joystick = -1;
     }
     return;
@@ -758,24 +754,4 @@ JoystickKeyboardController::reversemap_joyhat(Control c)
   return -1;
 }
 
-Menu*
-JoystickKeyboardController::get_key_options_menu()
-{
-  if(key_options_menu == 0) {
-    key_options_menu = new KeyboardMenu(this);
-  }
-
-  return key_options_menu;
-}
-
-Menu*
-JoystickKeyboardController::get_joystick_options_menu()
-{
-  if(joystick_options_menu == 0) {
-    joystick_options_menu = new JoystickMenu(this);
-  }
-
-  return joystick_options_menu;
-}
-
 /* EOF */
index 1bcf23b..33d6020 100644 (file)
@@ -114,9 +114,6 @@ private:
   int wait_for_key;
   int wait_for_joystick;
 
-  KeyboardMenu* key_options_menu;
-  JoystickMenu* joystick_options_menu;
-
 private:
   JoystickKeyboardController(const JoystickKeyboardController&);
   JoystickKeyboardController& operator=(const JoystickKeyboardController&);
index 22a6949..a502503 100644 (file)
 
 #include "supertux/menu/options_menu.hpp"
 #include "supertux/menu/profile_menu.hpp"
+#include "supertux/menu/joystick_menu.hpp"
+#include "supertux/menu/keyboard_menu.hpp"
+#include "supertux/globals.hpp"
 
 Menu* MenuStorage::options_menu = 0;
 Menu* MenuStorage::profile_menu = 0;
+KeyboardMenu* MenuStorage::key_options_menu = 0;
+JoystickMenu* MenuStorage::joystick_options_menu = 0;
 
 Menu*
 MenuStorage::get_options_menu()
@@ -50,4 +55,27 @@ MenuStorage::free_profile_menu()
   profile_menu = 0;
 }
 
+
+KeyboardMenu*
+MenuStorage::get_key_options_menu()
+{
+  if (!key_options_menu)
+  { // FIXME: this in never freed
+    key_options_menu = new KeyboardMenu(g_main_controller);
+  }
+
+  return key_options_menu;
+}
+
+JoystickMenu*
+MenuStorage::get_joystick_options_menu()
+{
+  if (!joystick_options_menu)
+  { // FIXME: this in never freed
+    joystick_options_menu = new JoystickMenu(g_main_controller);
+  }
+
+  return joystick_options_menu;
+}
+
 /* EOF */
index 84ff7c9..dabb47b 100644 (file)
@@ -18,6 +18,8 @@
 #define HEADER_SUPERTUX_SUPERTUX_MENU_MENU_STORAGE_HPP
 
 class Menu;
+class JoystickMenu;
+class KeyboardMenu;
 
 class MenuStorage
 {
@@ -25,14 +27,19 @@ public:
   MenuStorage();
 
   static Menu* get_options_menu();
-  static void free_options_menu();
+  static void  free_options_menu();
 
   static Menu* get_profile_menu();
-  static void free_profile_menu();
+  static void  free_profile_menu();
+
+  static KeyboardMenu* get_key_options_menu();
+  static JoystickMenu* get_joystick_options_menu();
 
 private:
   static Menu* options_menu;
   static Menu* profile_menu;
+  static KeyboardMenu* key_options_menu;
+  static JoystickMenu* joystick_options_menu;
 
 private:
   MenuStorage(const MenuStorage&);
index 9d5b021..8d0123d 100644 (file)
 #include "audio/sound_manager.hpp"
 #include "control/joystickkeyboardcontroller.hpp"
 #include "gui/menu.hpp"
-#include "gui/menu_manager.hpp"
 #include "gui/menu_item.hpp"
+#include "gui/menu_manager.hpp"
 #include "supertux/gameconfig.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/main.hpp"
-#include "supertux/menu/profile_menu.hpp"
+#include "supertux/menu/joystick_menu.hpp"
+#include "supertux/menu/keyboard_menu.hpp"
 #include "supertux/menu/language_menu.hpp"
 #include "supertux/menu/menu_storage.hpp"
+#include "supertux/menu/profile_menu.hpp"
 #include "util/gettext.hpp"
 #include "video/renderer.hpp"
 
@@ -153,10 +155,10 @@ OptionsMenu::OptionsMenu() :
     add_inactive(MNID_MUSIC, _("Music (disabled)"));
   }
   
-  add_submenu(_("Setup Keyboard"), g_main_controller->get_key_options_menu())
+  add_submenu(_("Setup Keyboard"), MenuStorage::get_key_options_menu())
     ->set_help(_("Configure key-action mappings"));
 
-  add_submenu(_("Setup Joystick") ,g_main_controller->get_joystick_options_menu())
+  add_submenu(_("Setup Joystick"), MenuStorage::get_joystick_options_menu())
     ->set_help(_("Configure joystick control-action mappings"));
   add_hl();
   add_back(_("Back"));