Replaced .reset(new Surface()) with a factory method
authorIngo Ruhnke <grumbel@gmx.de>
Sat, 21 Nov 2009 16:12:01 +0000 (16:12 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sat, 21 Nov 2009 16:12:01 +0000 (16:12 +0000)
SVN-Revision: 6080

14 files changed:
src/badguy/yeti.cpp
src/gui/menu.cpp
src/object/background.cpp
src/object/decal.cpp
src/object/level_time.cpp
src/object/player.cpp
src/supertux/console.cpp
src/supertux/game_session.cpp
src/supertux/info_box_line.cpp
src/supertux/info_box_line.hpp
src/supertux/player_status.cpp
src/supertux/textscroller.cpp
src/video/surface.cpp
src/video/surface.hpp

index 08631e5..d56e3a5 100644 (file)
@@ -64,7 +64,7 @@ Yeti::Yeti(const Reader& reader) :
   countMe = false;
   sound_manager->preload("sounds/yeti_gna.wav");
   sound_manager->preload("sounds/yeti_roar.wav");
-  hud_head.reset(new Surface("images/creatures/yeti/hudlife.png"));
+  hud_head = Surface::create("images/creatures/yeti/hudlife.png");
 }
 
 Yeti::~Yeti()
index 48a4c87..f80569d 100644 (file)
@@ -68,11 +68,11 @@ Menu::Menu() :
   effect_progress   = 0.0f;
   effect_start_time = 0.0f;
 
-  checkbox.reset(new Surface("images/engine/menu/checkbox-unchecked.png"));
-  checkbox_checked.reset(new Surface("images/engine/menu/checkbox-checked.png"));
-  back.reset(new Surface("images/engine/menu/arrow-back.png"));
-  arrow_left.reset(new Surface("images/engine/menu/arrow-left.png"));
-  arrow_right.reset(new Surface("images/engine/menu/arrow-right.png"));
+  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()
index 619645b..59a8871 100644 (file)
@@ -62,10 +62,10 @@ Background::Background(const Reader& reader) :
   set_image(imagefile, speed);
   reader.get("speed-y", speed_y);
   if (reader.get("image-top", imagefile_top)) {
-    image_top.reset(new Surface(imagefile_top));
+    image_top = Surface::create(imagefile_top);
   }
   if (reader.get("image-bottom", imagefile_bottom)) {
-    image_bottom.reset(new Surface(imagefile_bottom));
+    image_bottom = Surface::create(imagefile_bottom);
   }
 }
 
@@ -84,7 +84,7 @@ Background::set_image(const std::string& name, float speed)
   this->imagefile = name;
   this->speed = speed;
 
-  image.reset(new Surface(name));
+  image = Surface::create(name);
 }
 
 void
index a22d8db..67d5011 100644 (file)
@@ -31,7 +31,7 @@ Decal::Decal(const Reader& reader) :
   pos = Vector(px, py);
 
   if(!reader.get("image", imagefile)) throw std::runtime_error("Must specify image for decal");
-  image.reset(new Surface(imagefile));
+  image = Surface::create(imagefile);
 
   reader.get("layer", layer);
 }
index bc32397..6f096b0 100644 (file)
@@ -39,7 +39,7 @@ LevelTime::LevelTime(const Reader& reader) :
   reader.get("name", name);
   reader.get("time", time_left);
   if(time_left <= 0) throw std::runtime_error("No or invalid leveltime specified");
-  time_surface.reset(new Surface("images/engine/hud/time-0.png"));
+  time_surface = Surface::create("images/engine/hud/time-0.png");
 }
 
 void
index e394c0e..575113e 100644 (file)
@@ -155,7 +155,7 @@ Player::Player(PlayerStatus* _player_status, const std::string& name) :
   controller = g_main_controller;
   scripting_controller.reset(new CodeController());
   sprite = sprite_manager->create("images/creatures/tux/tux.sprite");
-  airarrow.reset(new Surface("images/engine/hud/airarrow.png"));
+  airarrow = Surface::create("images/engine/hud/airarrow.png");
   idle_timer.start(IDLE_TIME[0]/1000.0f);
 
   sound_manager->preload("sounds/bigjump.wav");
index ba171d0..ffff99f 100644 (file)
@@ -60,8 +60,8 @@ Console::init_graphics()
 {
   font.reset(new Font(Font::FIXED,"fonts/andale12.stf",1));
   fontheight = font->get_height();
-  background.reset(new Surface("images/engine/console.png"));
-  background2.reset(new Surface("images/engine/console2.png"));
+  background = Surface::create("images/engine/console.png");
+  background2 = Surface::create("images/engine/console2.png");
 }
 
 void
index b1396bf..cffb72d 100644 (file)
@@ -73,7 +73,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics)
   game_pause = false;
   speed_before_pause = g_screen_manager->get_speed();
 
-  statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
+  statistics_backdrop = Surface::create("images/engine/menu/score-backdrop.png");
 
   restart_level();
 
index 19bf347..23fb1a6 100644 (file)
@@ -111,12 +111,14 @@ InfoBoxLine::InfoBoxLine(char format_char, const std::string& text) :
   font = get_font_by_format_char(format_char);
   lineType = get_linetype_by_format_char(format_char);
   color = get_color_by_format_char(format_char);
-  if (lineType == IMAGE) image = new Surface(text);
+  if (lineType == IMAGE) 
+  {
+    image = Surface::create(text);
+  }
 }
 
 InfoBoxLine::~InfoBoxLine()
 {
-  delete image;
 }
 
 const std::vector<InfoBoxLine*>
@@ -172,7 +174,7 @@ InfoBoxLine::draw(DrawingContext& context, const Rect& bbox, int layer)
   Vector position = bbox.p1;
   switch (lineType) {
     case IMAGE:
-      context.draw_surface(image, Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer);
+      context.draw_surface(image.get(), Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer);
       break;
     case NORMAL_LEFT:
       context.draw_text(font, text, Vector(position.x, position.y), ALIGN_LEFT, layer, color);
index ac1f079..3501229 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <string>
 #include <vector>
+#include <memory>
 
 #include "video/color.hpp"
 
@@ -48,7 +49,7 @@ private:
   Font* font;
   Color color;
   std::string text;
-  Surface* image;
+  std::auto_ptr<Surface> image;
 
 private:
   InfoBoxLine(const InfoBoxLine&);
index 24bde70..4dc5188 100644 (file)
@@ -40,7 +40,7 @@ PlayerStatus::PlayerStatus() :
 {
   reset();
 
-  coin_surface.reset(new Surface("images/engine/hud/coins-0.png"));
+  coin_surface = Surface::create("images/engine/hud/coins-0.png");
   sound_manager->preload("sounds/coin.wav");
   sound_manager->preload("sounds/lifeup.wav");
 }
index 8d5db1a..61af4c6 100644 (file)
@@ -70,7 +70,7 @@ TextScroller::TextScroller(const std::string& filename) :
   lines = InfoBoxLine::split(text, SCREEN_WIDTH - 2*LEFT_BORDER);
 
   // load background image
-  background.reset(new Surface("images/background/" + background_file));
+  background = Surface::create("images/background/" + background_file);
 
   scroll = 0;
   fading = false;
index b15d80b..6c55ab1 100644 (file)
 #include "video/texture.hpp"
 #include "video/video_systems.hpp"
 
+std::auto_ptr<Surface>
+Surface::create(const std::string& file)
+{
+  return std::auto_ptr<Surface>(new Surface(file));
+}
+
+std::auto_ptr<Surface> 
+Surface::create(const std::string& file, int x, int y, int w, int h)
+{
+  return std::auto_ptr<Surface>(new Surface(file, x, y, w, h));
+}
+
+std::auto_ptr<Surface> 
+Surface::create(const Surface& other)
+{
+  return std::auto_ptr<Surface>(new Surface(other));
+}
+
 Surface::Surface(const std::string& file) :
   texture(texture_manager->get(file)),
   surface_data(),
index 9613917..6769e60 100644 (file)
@@ -18,6 +18,7 @@
 #define HEADER_SUPERTUX_VIDEO_SURFACE_HPP
 
 #include <string>
+#include <memory>
 
 #include "math/vector.hpp"
 
@@ -30,6 +31,11 @@ class Texture;
  */
 class Surface
 {
+public:
+  static std::auto_ptr<Surface> create(const std::string& file);
+  static std::auto_ptr<Surface> create(const std::string& file, int x, int y, int w, int h);
+  static std::auto_ptr<Surface> create(const Surface& other);
+
 private:
   Texture* texture;
   void *surface_data;