Partial resolution of bug 952
authorTobias Markus <tobbi@mozilla-uk.org>
Sat, 17 Aug 2013 19:18:50 +0000 (09:18 -1000)
committerLMH <lmh.0013@gmail.com>
Sat, 17 Aug 2013 19:18:50 +0000 (09:18 -1000)
src/gui/menu.cpp
src/gui/menu.hpp
src/supertux/resources.cpp
src/supertux/resources.hpp

index 21df675..2c6f81c 100644 (file)
@@ -46,12 +46,7 @@ Menu::Menu() :
   effect_progress(),
   effect_start_time(),
   arrange_left(),
-  active_item(),
-  checkbox(),
-  checkbox_checked(),
-  back(),
-  arrow_left(),
-  arrow_right()
+  active_item()
 {
   MenuManager::all_menus.push_back(this);
 
@@ -67,12 +62,6 @@ Menu::Menu() :
 
   effect_progress   = 0.0f;
   effect_start_time = 0.0f;
-
-  checkbox         = Surface::create("images/engine/menu/checkbox-unchecked.png");
-  checkbox_checked = Surface::create("images/engine/menu/checkbox-checked.png");
-  back             = Surface::create("images/engine/menu/arrow-back.png");
-  arrow_left       = Surface::create("images/engine/menu/arrow-left.png");
-  arrow_right      = Surface::create("images/engine/menu/arrow-right.png");
 }
 
 Menu::~Menu()
@@ -547,17 +536,17 @@ Menu::draw_item(DrawingContext& context, int index)
     }
     case MN_STRINGSELECT:
     {
-      float roff = arrow_left->get_width();
+      float roff = Resources::arrow_left->get_width();
       // Draw left side
       context.draw_text(Resources::normal_font, pitem.text,
                         Vector(left, y_pos - int(Resources::normal_font->get_height()/2)),
                         ALIGN_LEFT, LAYER_GUI, text_color);
 
       // Draw right side
-      context.draw_surface(arrow_left,
+      context.draw_surface(Resources::arrow_left,
                            Vector(right - list_width - roff - roff, y_pos - 8),
                            LAYER_GUI);
-      context.draw_surface(arrow_right,
+      context.draw_surface(Resources::arrow_right,
                            Vector(right - roff, y_pos - 8),
                            LAYER_GUI);
       context.draw_text(Resources::normal_font, pitem.list[pitem.selected],
@@ -570,7 +559,7 @@ Menu::draw_item(DrawingContext& context, int index)
       context.draw_text(Resources::Resources::normal_font, pitem.text,
                         Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                         ALIGN_CENTER, LAYER_GUI, text_color);
-      context.draw_surface(back,
+      context.draw_surface(Resources::back,
                            Vector(x_pos + text_width/2  + 16, y_pos - 8),
                            LAYER_GUI);
       break;
@@ -583,12 +572,12 @@ Menu::draw_item(DrawingContext& context, int index)
                         ALIGN_LEFT, LAYER_GUI, text_color);
 
       if(pitem.toggled)
-        context.draw_surface(checkbox_checked,
-                             Vector(x_pos + (menu_width/2-16) - checkbox->get_width(), y_pos - 8),
+        context.draw_surface(Resources::checkbox_checked,
+                             Vector(x_pos + (menu_width/2-16) - Resources::checkbox->get_width(), y_pos - 8),
                              LAYER_GUI + 1);
       else
-        context.draw_surface(checkbox,
-                             Vector(x_pos + (menu_width/2-16) - checkbox->get_width(), y_pos - 8),
+        context.draw_surface(Resources::checkbox,
+                             Vector(x_pos + (menu_width/2-16) - Resources::checkbox->get_width(), y_pos - 8),
                              LAYER_GUI + 1);
       break;
     }
index b00c9c8..ab9f6e1 100644 (file)
@@ -137,12 +137,6 @@ public:
 private:
   int arrange_left;
   int active_item;
-
-  SurfacePtr checkbox;
-  SurfacePtr checkbox_checked;
-  SurfacePtr back;
-  SurfacePtr arrow_left;
-  SurfacePtr arrow_right;
 };
 
 #endif
index 7d2e147..0b09aa5 100644 (file)
@@ -30,6 +30,12 @@ FontPtr Resources::normal_font;
 FontPtr Resources::small_font;
 FontPtr Resources::big_font;
 
+SurfacePtr Resources::checkbox;
+SurfacePtr Resources::checkbox_checked;
+SurfacePtr Resources::back;
+SurfacePtr Resources::arrow_left;
+SurfacePtr Resources::arrow_right;
+
 /* Load graphics/sounds shared between all levels: */
 void
 Resources::load_shared()
@@ -44,6 +50,13 @@ Resources::load_shared()
   small_font.reset(new Font(Font::VARIABLE, "fonts/white-small.stf", 1));
   big_font.reset(new Font(Font::VARIABLE, "fonts/white-big.stf", 3));
 
+  /* Load menu images */
+  checkbox = Surface::create("images/engine/menu/checkbox-unchecked.png");
+  checkbox_checked = Surface::create("images/engine/menu/checkbox-checked.png");
+  back = Surface::create("images/engine/menu/arrow-back.png");
+  arrow_left = Surface::create("images/engine/menu/arrow-left.png");
+  arrow_right = Surface::create("images/engine/menu/arrow-right.png");
+
   tile_manager   = new TileManager();
   sprite_manager = new SpriteManager();
 }
@@ -52,6 +65,13 @@ Resources::load_shared()
 void
 Resources::unload_shared()
 {
+  /* Free menu images */
+  checkbox.reset();
+  checkbox_checked.reset();
+  back.reset();
+  arrow_left.reset();
+  arrow_right.reset();
+
   /* Free global images: */
   fixed_font.reset();
   normal_font.reset();
index f63c56a..8648a91 100644 (file)
@@ -19,6 +19,7 @@
 #define HEADER_SUPERTUX_SUPERTUX_RESOURCES_HPP
 
 #include "video/font_ptr.hpp"
+#include "video/surface_ptr.hpp"
 
 class MouseCursor;
 
@@ -32,6 +33,12 @@ public:
   static FontPtr small_font;
   static FontPtr big_font;
 
+  static SurfacePtr checkbox;
+  static SurfacePtr checkbox_checked;
+  static SurfacePtr back;
+  static SurfacePtr arrow_left;
+  static SurfacePtr arrow_right;
+
 public:
   static void load_shared();
   static void unload_shared();