From: grumbel Date: Mon, 14 Dec 2009 09:05:15 +0000 (+0000) Subject: Added FontPtr X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8877c6c3073ab8ba0a8e5f3ef2afb0bfbb3b3188;p=supertux.git Added FontPtr git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6216 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 0105741ff..587b1e315 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -19,7 +19,7 @@ #include "supertux/globals.hpp" #include "video/drawing_context.hpp" -Font* Button::info_font = 0; +FontPtr Button::info_font; Button::Button(SurfacePtr image_, std::string info_, SDLKey binding_) : pos(), diff --git a/src/gui/button.hpp b/src/gui/button.hpp index 7d08232ff..aeeb71c3b 100644 --- a/src/gui/button.hpp +++ b/src/gui/button.hpp @@ -21,6 +21,7 @@ #include #include "math/vector.hpp" +#include "video/font_ptr.hpp" #include "video/surface_ptr.hpp" class DrawingContext; @@ -46,7 +47,7 @@ public: void draw(DrawingContext& context, bool selected); int event(SDL_Event& event, int x_offset = 0, int y_offset = 0); - static Font* info_font; + static FontPtr info_font; private: friend class ButtonGroup; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index ab6c37be0..e086afc1c 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -615,7 +615,7 @@ Menu::get_width() const float menu_width = 0; for(unsigned int i = 0; i < items.size(); ++i) { - Font* font = Resources::Resources::normal_font; + FontPtr font = Resources::Resources::normal_font; if(items[i]->kind == MN_LABEL) font = Resources::big_font; diff --git a/src/object/text_object.hpp b/src/object/text_object.hpp index 24c96a2cc..c8903e79a 100644 --- a/src/object/text_object.hpp +++ b/src/object/text_object.hpp @@ -22,8 +22,7 @@ #include "supertux/game_object.hpp" #include "supertux/script_interface.hpp" #include "video/color.hpp" - -class Font; +#include "video/font_ptr.hpp" /** A text object intended for scripts that want to tell a story */ class TextObject : public GameObject, @@ -80,7 +79,7 @@ public: void update(float elapsed_time); private: - Font* font; + FontPtr font; std::string text; float fading; float fadetime; diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index 71a7fd592..e4f246c21 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -501,10 +501,10 @@ Console::draw(DrawingContext& context) if (focused) { lineNo++; float py = height-4-1 * font->get_height(); - context.draw_text(font.get(), "> "+inputBuffer, Vector(4, py), ALIGN_LEFT, layer); + context.draw_text(font, "> "+inputBuffer, Vector(4, py), ALIGN_LEFT, layer); if (SDL_GetTicks() % 1000 < 750) { int cursor_px = 2 + inputBufferPosition; - context.draw_text(font.get(), "_", Vector(4 + (cursor_px * font->get_text_width("X")), py), ALIGN_LEFT, layer); + context.draw_text(font, "_", Vector(4 + (cursor_px * font->get_text_width("X")), py), ALIGN_LEFT, layer); } } @@ -514,7 +514,7 @@ Console::draw(DrawingContext& context) lineNo++; float py = height - 4 - lineNo*font->get_height(); if (py < -font->get_height()) break; - context.draw_text(font.get(), *i, Vector(4, py), ALIGN_LEFT, layer); + context.draw_text(font, *i, Vector(4, py), ALIGN_LEFT, layer); } context.pop_transform(); } diff --git a/src/supertux/console.hpp b/src/supertux/console.hpp index b463b51a1..64b6c8dee 100644 --- a/src/supertux/console.hpp +++ b/src/supertux/console.hpp @@ -23,13 +23,13 @@ #include #include +#include "video/font_ptr.hpp" #include "video/surface_ptr.hpp" class Console; class ConsoleStreamBuffer; class ConsoleCommandReceiver; class DrawingContext; -class Font; class Console { @@ -97,7 +97,7 @@ private: float alpha; int offset; /**< decrease to scroll text up */ bool focused; /**< true if console has input focus */ - std::auto_ptr font; + FontPtr font; float fontheight; /**< height of the font (this is a separate var, because the font could not be initialized yet but is needed in the addLine message */ float stayOpen; diff --git a/src/supertux/info_box_line.cpp b/src/supertux/info_box_line.cpp index b77079277..6a9123a9b 100644 --- a/src/supertux/info_box_line.cpp +++ b/src/supertux/info_box_line.cpp @@ -26,7 +26,7 @@ static const float ITEMS_SPACE = 4; namespace { -Font* get_font_by_format_char(char format_char) { +FontPtr get_font_by_format_char(char format_char) { switch(format_char) { case ' ': @@ -157,7 +157,7 @@ InfoBoxLine::split(const std::string& text, float width) // append wrapped parts of line into list std::string overflow; do { - Font* font = get_font_by_format_char(format_char); + FontPtr font = get_font_by_format_char(format_char); std::string s2 = s; if (font) s2 = font->wrap_to_width(s2, width, &overflow); lines.push_back(new InfoBoxLine(format_char, s2)); diff --git a/src/supertux/info_box_line.hpp b/src/supertux/info_box_line.hpp index 7d5e9fe01..56c6bca96 100644 --- a/src/supertux/info_box_line.hpp +++ b/src/supertux/info_box_line.hpp @@ -22,10 +22,10 @@ #include #include "video/color.hpp" +#include "video/font_ptr.hpp" #include "video/surface_ptr.hpp" class DrawingContext; -class Font; class Rectf; /** @@ -46,7 +46,7 @@ public: private: InfoBoxLine::LineType lineType; - Font* font; + FontPtr font; Color color; std::string text; SurfacePtr image; diff --git a/src/supertux/resources.cpp b/src/supertux/resources.cpp index 9d573799c..6e4c203cd 100644 --- a/src/supertux/resources.cpp +++ b/src/supertux/resources.cpp @@ -25,10 +25,10 @@ MouseCursor* Resources::mouse_cursor = NULL; -Font* Resources::fixed_font = NULL; -Font* Resources::normal_font = NULL; -Font* Resources::small_font = NULL; -Font* Resources::big_font = NULL; +FontPtr Resources::fixed_font; +FontPtr Resources::normal_font; +FontPtr Resources::small_font; +FontPtr Resources::big_font; /* Load graphics/sounds shared between all levels: */ void @@ -39,10 +39,10 @@ Resources::load_shared() MouseCursor::set_current(mouse_cursor); /* Load global images: */ - fixed_font = new Font(Font::FIXED, "fonts/white.stf"); - normal_font = new Font(Font::VARIABLE, "fonts/white.stf"); - small_font = new Font(Font::VARIABLE, "fonts/white-small.stf", 1); - big_font = new Font(Font::VARIABLE, "fonts/white-big.stf", 3); + fixed_font.reset(new Font(Font::FIXED, "fonts/white.stf")); + normal_font.reset(new Font(Font::VARIABLE, "fonts/white.stf")); + small_font.reset(new Font(Font::VARIABLE, "fonts/white-small.stf", 1)); + big_font.reset(new Font(Font::VARIABLE, "fonts/white-big.stf", 3)); tile_manager = new TileManager(); sprite_manager = new SpriteManager(); @@ -55,9 +55,10 @@ void Resources::unload_shared() { /* Free global images: */ - delete normal_font; - delete small_font; - delete big_font; + fixed_font.reset(); + normal_font.reset(); + small_font.reset(); + big_font.reset(); delete sprite_manager; sprite_manager = NULL; diff --git a/src/supertux/resources.hpp b/src/supertux/resources.hpp index 06124c73e..f63c56a31 100644 --- a/src/supertux/resources.hpp +++ b/src/supertux/resources.hpp @@ -18,7 +18,8 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_RESOURCES_HPP #define HEADER_SUPERTUX_SUPERTUX_RESOURCES_HPP -class Font; +#include "video/font_ptr.hpp" + class MouseCursor; class Resources @@ -26,10 +27,10 @@ class Resources public: static MouseCursor* mouse_cursor; - static Font* fixed_font; - static Font* normal_font; - static Font* small_font; - static Font* big_font; + static FontPtr fixed_font; + static FontPtr normal_font; + static FontPtr small_font; + static FontPtr big_font; public: static void load_shared(); diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 5a31e4d5d..5814c042a 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -155,7 +155,7 @@ DrawingContext::draw_surface_part(SurfacePtr surface, const Vector& source, } void -DrawingContext::draw_text(const Font* font, const std::string& text, +DrawingContext::draw_text(FontPtr font, const std::string& text, const Vector& position, FontAlignment alignment, int layer, Color color) { DrawingRequest* request = new(obst) DrawingRequest(); @@ -169,7 +169,7 @@ DrawingContext::draw_text(const Font* font, const std::string& text, request->color = color; TextRequest* textrequest = new(obst) TextRequest(); - textrequest->font = font; + textrequest->font = font.get(); textrequest->text = text; textrequest->alignment = alignment; request->request_data = textrequest; @@ -178,7 +178,7 @@ DrawingContext::draw_text(const Font* font, const std::string& text, } void -DrawingContext::draw_center_text(const Font* font, const std::string& text, +DrawingContext::draw_center_text(FontPtr font, const std::string& text, const Vector& position, int layer, Color color) { draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y), diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index 6a8f447c6..3bfedc8b5 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -28,6 +28,7 @@ #include "video/color.hpp" #include "video/drawing_request.hpp" #include "video/font.hpp" +#include "video/font_ptr.hpp" #include "video/texture.hpp" class Surface; @@ -58,13 +59,13 @@ public: void draw_surface_part(SurfacePtr surface, const Vector& source, const Vector& size, const Vector& dest, int layer); /// Draws a text. - void draw_text(const Font* font, const std::string& text, + void draw_text(FontPtr font, const std::string& text, const Vector& position, FontAlignment alignment, int layer, Color color = Color(1.0,1.0,1.0)); /// Draws text on screen center (feed Vector.x with a 0). /// This is the same as draw_text() with a SCREEN_WIDTH/2 position and /// alignment set to LEFT_ALIGN - void draw_center_text(const Font* font, const std::string& text, + void draw_center_text(FontPtr font, const std::string& text, const Vector& position, int layer, Color color = Color(1.0,1.0,1.0)); /// Draws a color gradient onto the whole screen */ void draw_gradient(const Color& from, const Color& to, int layer); diff --git a/src/video/font_ptr.hpp b/src/video/font_ptr.hpp new file mode 100644 index 000000000..8fcfb0508 --- /dev/null +++ b/src/video/font_ptr.hpp @@ -0,0 +1,27 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// 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 . + +#ifndef HEADER_SUPERTUX_VIDEO_FONT_PTR_HPP +#define HEADER_SUPERTUX_VIDEO_FONT_PTR_HPP + +#include + +class Font; +typedef boost::shared_ptr FontPtr; + +#endif + +/* EOF */