font.hpp

Go to the documentation of this file.
00001 /* $Id: font.hpp 24305 2008-03-04 18:24:15Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 #ifndef FONT_HPP_INCLUDED
00015 #define FONT_HPP_INCLUDED
00016 
00017 #include "SDL.h"
00018 #include "SDL_ttf.h"
00019 
00020 class CVideo;
00021 #include "sdl_utils.hpp"
00022 #include "serialization/string_utils.hpp"
00023 
00024 #include <string>
00025 #include <vector>
00026 
00027 namespace font {
00028 
00029 //object which initializes and destroys structures needed for fonts
00030 struct manager {
00031     manager();
00032     ~manager();
00033     struct error {};
00034 };
00035 
00036 //various standard colours
00037 extern const SDL_Color NORMAL_COLOUR, GRAY_COLOUR, LOBBY_COLOUR, GOOD_COLOUR, BAD_COLOUR,
00038                        BLACK_COLOUR, YELLOW_COLOUR, BUTTON_COLOUR, BIGMAP_COLOUR,
00039                        STONED_COLOUR, TITLE_COLOUR, DISABLED_COLOUR, LABEL_COLOUR;
00040 
00041 // font sizes, to be made theme parameters
00042 #ifdef USE_TINY_GUI
00043 // this is not meant for normal play, just for checking other dimensions get adapted accordingly
00044 const int SIZE_NORMAL = 9;
00045 #else
00046 const int SIZE_NORMAL = 14;
00047 #endif
00048 inline int relative_size(int size)
00049 {
00050     return (SIZE_NORMAL * size / 14);
00051 }
00052 
00053 // automatic computation of other font sizes, to be made a default for theme-provided values
00054 #ifdef USE_TINY_GUI
00055     const int
00056     SIZE_TINY   = 8,
00057     SIZE_SMALL  = 8,
00058     SIZE_15     = 9,
00059     SIZE_PLUS   = 9,
00060     SIZE_LARGE  = 10,
00061     SIZE_XLARGE = 10
00062   ;
00063 #else
00064 const int
00065     SIZE_TINY       = relative_size(10),
00066     SIZE_SMALL      = relative_size(12),
00067 
00068     SIZE_15         = relative_size(15),
00069     SIZE_PLUS       = relative_size(16),
00070     SIZE_LARGE      = relative_size(18),
00071     SIZE_XLARGE     = relative_size(24)
00072   ;
00073 #endif
00074 
00075 // Returns a SDL surface containing the text rendered in a given colour.
00076 surface get_rendered_text(const std::string& text, int size, const SDL_Color& colour, int style=0);
00077 
00078 SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size,
00079                         const SDL_Color& colour, const std::string& text,
00080                         int x, int y, bool use_tooltips, int style);
00081 
00082 SDL_Rect draw_text_line(CVideo* gui, const SDL_Rect& area, int size,
00083                         const SDL_Color& colour, const std::string& text,
00084                         int x, int y, bool use_tooltips, int style);
00085 
00086 // Returns the maximum height of a font, in pixels
00087 int get_max_height(int size);
00088 
00089 ///
00090 /// Determine the width of a line of text given a certain font size.
00091 /// The font type used is the default wesnoth font type.
00092 ///
00093 int line_width(const std::string& line, int font_size, int style=TTF_STYLE_NORMAL);
00094 
00095 ///
00096 /// Determine the size of a line of text given a certain font size. Similar to
00097 /// line_width, but for both coordinates.
00098 ///
00099 SDL_Rect line_size(const std::string& line, int font_size, int style=TTF_STYLE_NORMAL);
00100 
00101 ///
00102 /// If the text excedes the specified max width, end it with an ellipsis (...)
00103 /// The with_tags can probably always be set to false
00104 ///
00105 std::string make_text_ellipsis(const std::string& text, int font_size, int max_width, bool with_tags = true);
00106 
00107 
00108 /// structure which will hide all current floating labels, and cause floating labels
00109 /// instantiated after it is created to be displayed
00110 struct floating_label_context
00111 {
00112     floating_label_context();
00113     ~floating_label_context();
00114 };
00115 
00116 enum ALIGN { LEFT_ALIGN, CENTER_ALIGN, RIGHT_ALIGN };
00117 
00118 enum LABEL_SCROLL_MODE { ANCHOR_LABEL_SCREEN, ANCHOR_LABEL_MAP };
00119 
00120 /// add a label floating on the screen above everything else.
00121 /// 'text': the text to display
00122 /// 'font_size': the size to display the text in
00123 /// 'colour': the colour of the text
00124 /// 'xpos,ypos': the location on the screen to display the text.
00125 /// 'xmove,ymove': the amount to move the text each frame
00126 /// 'lifetime': the number of frames to display the text for, or -1 to display until removed
00127 /// 'clip_rect': the rectangle to clip the label to.
00128 ///
00129 /// @returns a handle to the label which can be used with other label functions
00130 int add_floating_label(const std::string& text, int font_size, const SDL_Color& colour,
00131         double xpos, double ypos, double xmove, double ymove, int lifetime,
00132         const SDL_Rect& clip_rect, ALIGN alignment=CENTER_ALIGN,
00133         const SDL_Color* bg_colour=NULL, int border_size=0,
00134         LABEL_SCROLL_MODE scroll_mode=ANCHOR_LABEL_SCREEN);
00135 
00136 /// moves the floating label given by 'handle' by (xmove,ymove)
00137 void move_floating_label(int handle, double xmove, double ymove);
00138 
00139 /// moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
00140 void scroll_floating_labels(double xmove, double ymove);
00141 
00142 /// removes the floating label given by 'handle' from the screen
00143 void remove_floating_label(int handle);
00144 
00145 /// hides or shows a floating label
00146 void show_floating_label(int handle, bool show);
00147 
00148 SDL_Rect get_floating_label_rect(int handle);
00149 
00150 void draw_floating_labels(surface screen);
00151 void undraw_floating_labels(surface screen);
00152 
00153 bool load_font_config();
00154 
00155 enum CACHE { CACHE_LOBBY, CACHE_GAME };
00156 void cache_mode(CACHE mode);
00157 
00158 }
00159 
00160 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs