X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fvideo%2Ffont.h;h=429cf97e113004431e607b9fc856cd110db07871;hb=9599042661b468aae7bd34dca05441c0ebc93ad7;hp=d0b328b317a9e615e8c1e4a3bad81b303381686d;hpb=4b476ec30e7dd62249328054402d6493c20a685d;p=supertux.git diff --git a/lib/video/font.h b/lib/video/font.h index d0b328b31..429cf97e1 100644 --- a/lib/video/font.h +++ b/lib/video/font.h @@ -23,21 +23,23 @@ #include -#include "../video/surface.h" -#include "../math/vector.h" +#include "video/surface.h" +#include "math/vector.h" namespace SuperTux { - /** Reads a text file (using LispReader, so it as to be in its formatting) - and displays it in a StarTrek fashion */ - void display_text_file(const std::string& file, float scroll_speed); + enum { + LEFT_ALLIGN, + CENTER_ALLIGN, + RIGHT_ALLIGN + }; - /* Text type */ + /// Font class Font { public: - /* Kinds of texts. */ + /// Kinds of texts. enum FontType { TEXT, // images for all characters NUM // only images for numbers @@ -46,21 +48,38 @@ namespace SuperTux Font(const std::string& file, FontType type, int w, int h, int shadowsize=2); ~Font(); - /** returns the height of the font */ - float get_height() const; /** returns the width of a given text. (Note that I won't add a normal * get_width function here, as we might switch to variable width fonts in the - * future. + * future.) + * Supports breaklines. */ float get_text_width(const std::string& text) const; + /** returns the height of a given text. (Note that I won't add a normal + * get_width function here, as we might switch to variable width fonts in the + * future.) + * Supports breaklines. + * In case, you are positive that your text doesn't use break lines, you can + * just use get_height(). + */ + float get_text_height(const std::string& text) const; + /// returns the height of the font. + float get_height() const; + + /** Draws the given text to the screen. Also needs the position. + * Type of alignment, drawing effect and alpha are optional. */ + void draw(const std::string& text, const Vector& pos, + int allignment = LEFT_ALLIGN, + Uint32 drawing_effect = NONE_EFFECT, int alpha = 255); + private: friend class DrawingContext; - void draw(const std::string& text, const Vector& pos, - Uint32 drawing_effect = NONE_EFFECT); + void draw_text(const std::string& text, const Vector& pos, + Uint32 drawing_effect = NONE_EFFECT, int alpha = 255); + void draw_chars(Surface* pchars, const std::string& text, - const Vector& position, Uint32 drawing_effect); + const Vector& position, Uint32 drawing_effect, int alpha); Surface* chars; Surface* shadow_chars; @@ -75,6 +94,11 @@ namespace SuperTux int last_char; }; + + /** Reads a text file (using LispReader, so it as to be in its formatting) + and displays it in a StarTrek fashion */ + void display_text_file(const std::string& file, float scroll_speed, Font* heading_font, Font* normal_font, Font* small_font, Font* reference_font ); + } //namespace SuperTux #endif /*SUPERTUX_FONT_H*/