#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(),
#include <string>
#include "math/vector.hpp"
+#include "video/font_ptr.hpp"
#include "video/surface_ptr.hpp"
class DrawingContext;
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;
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;
#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,
void update(float elapsed_time);
private:
- Font* font;
+ FontPtr font;
std::string text;
float fading;
float fadetime;
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);
}
}
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();
}
#include <sstream>
#include <vector>
+#include "video/font_ptr.hpp"
#include "video/surface_ptr.hpp"
class Console;
class ConsoleStreamBuffer;
class ConsoleCommandReceiver;
class DrawingContext;
-class Font;
class Console
{
float alpha;
int offset; /**< decrease to scroll text up */
bool focused; /**< true if console has input focus */
- std::auto_ptr<Font> 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;
namespace {
-Font* get_font_by_format_char(char format_char) {
+FontPtr get_font_by_format_char(char format_char) {
switch(format_char)
{
case ' ':
// 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));
#include <memory>
#include "video/color.hpp"
+#include "video/font_ptr.hpp"
#include "video/surface_ptr.hpp"
class DrawingContext;
-class Font;
class Rectf;
/**
private:
InfoBoxLine::LineType lineType;
- Font* font;
+ FontPtr font;
Color color;
std::string text;
SurfacePtr image;
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
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();
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;
#ifndef HEADER_SUPERTUX_SUPERTUX_RESOURCES_HPP
#define HEADER_SUPERTUX_SUPERTUX_RESOURCES_HPP
-class Font;
+#include "video/font_ptr.hpp"
+
class MouseCursor;
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();
}
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();
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;
}
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),
#include "video/color.hpp"
#include "video/drawing_request.hpp"
#include "video/font.hpp"
+#include "video/font_ptr.hpp"
#include "video/texture.hpp"
class Surface;
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);
--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_VIDEO_FONT_PTR_HPP
+#define HEADER_SUPERTUX_VIDEO_FONT_PTR_HPP
+
+#include <boost/shared_ptr.hpp>
+
+class Font;
+typedef boost::shared_ptr<Font> FontPtr;
+
+#endif
+
+/* EOF */