From f26940f1db73c045618c17e163cfff5f64948c04 Mon Sep 17 00:00:00 2001 From: grumbel Date: Sat, 21 Nov 2009 16:12:01 +0000 Subject: [PATCH] Replaced .reset(new Surface()) with a factory method git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6080 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/badguy/yeti.cpp | 2 +- src/gui/menu.cpp | 10 +++++----- src/object/background.cpp | 6 +++--- src/object/decal.cpp | 2 +- src/object/level_time.cpp | 2 +- src/object/player.cpp | 2 +- src/supertux/console.cpp | 4 ++-- src/supertux/game_session.cpp | 2 +- src/supertux/info_box_line.cpp | 8 +++++--- src/supertux/info_box_line.hpp | 3 ++- src/supertux/player_status.cpp | 2 +- src/supertux/textscroller.cpp | 2 +- src/video/surface.cpp | 18 ++++++++++++++++++ src/video/surface.hpp | 6 ++++++ 14 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 08631e55d..d56e3a508 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -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() diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 48a4c879a..f80569d22 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -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() diff --git a/src/object/background.cpp b/src/object/background.cpp index 619645b63..59a8871e3 100644 --- a/src/object/background.cpp +++ b/src/object/background.cpp @@ -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 diff --git a/src/object/decal.cpp b/src/object/decal.cpp index a22d8db66..67d5011ab 100644 --- a/src/object/decal.cpp +++ b/src/object/decal.cpp @@ -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); } diff --git a/src/object/level_time.cpp b/src/object/level_time.cpp index bc32397ea..6f096b01f 100644 --- a/src/object/level_time.cpp +++ b/src/object/level_time.cpp @@ -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 diff --git a/src/object/player.cpp b/src/object/player.cpp index e394c0e11..575113e3a 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -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"); diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index ba171d013..ffff99fad 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -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 diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index b1396bf21..cffb72d3f 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -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(); diff --git a/src/supertux/info_box_line.cpp b/src/supertux/info_box_line.cpp index 19bf347c3..23fb1a6b5 100644 --- a/src/supertux/info_box_line.cpp +++ b/src/supertux/info_box_line.cpp @@ -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 @@ -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); diff --git a/src/supertux/info_box_line.hpp b/src/supertux/info_box_line.hpp index ac1f07982..350122927 100644 --- a/src/supertux/info_box_line.hpp +++ b/src/supertux/info_box_line.hpp @@ -19,6 +19,7 @@ #include #include +#include #include "video/color.hpp" @@ -48,7 +49,7 @@ private: Font* font; Color color; std::string text; - Surface* image; + std::auto_ptr image; private: InfoBoxLine(const InfoBoxLine&); diff --git a/src/supertux/player_status.cpp b/src/supertux/player_status.cpp index 24bde7029..4dc518809 100644 --- a/src/supertux/player_status.cpp +++ b/src/supertux/player_status.cpp @@ -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"); } diff --git a/src/supertux/textscroller.cpp b/src/supertux/textscroller.cpp index 8d5db1ace..61af4c600 100644 --- a/src/supertux/textscroller.cpp +++ b/src/supertux/textscroller.cpp @@ -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; diff --git a/src/video/surface.cpp b/src/video/surface.cpp index b15d80b62..6c55ab1a2 100644 --- a/src/video/surface.cpp +++ b/src/video/surface.cpp @@ -23,6 +23,24 @@ #include "video/texture.hpp" #include "video/video_systems.hpp" +std::auto_ptr +Surface::create(const std::string& file) +{ + return std::auto_ptr(new Surface(file)); +} + +std::auto_ptr +Surface::create(const std::string& file, int x, int y, int w, int h) +{ + return std::auto_ptr(new Surface(file, x, y, w, h)); +} + +std::auto_ptr +Surface::create(const Surface& other) +{ + return std::auto_ptr(new Surface(other)); +} + Surface::Surface(const std::string& file) : texture(texture_manager->get(file)), surface_data(), diff --git a/src/video/surface.hpp b/src/video/surface.hpp index 96139176f..6769e60eb 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_VIDEO_SURFACE_HPP #include +#include #include "math/vector.hpp" @@ -30,6 +31,11 @@ class Texture; */ class Surface { +public: + static std::auto_ptr create(const std::string& file); + static std::auto_ptr create(const std::string& file, int x, int y, int w, int h); + static std::auto_ptr create(const Surface& other); + private: Texture* texture; void *surface_data; -- 2.11.0