font Namespace Reference

Graphical text output. More...


Classes

struct  subset_descriptor
struct  manager
struct  floating_label_context
 structure which will hide all current floating labels, and cause floating labels instantiated after it is created to be displayed More...

Enumerations

enum  ALIGN { LEFT_ALIGN, CENTER_ALIGN, RIGHT_ALIGN }
enum  LABEL_SCROLL_MODE { ANCHOR_LABEL_SCREEN, ANCHOR_LABEL_MAP }
enum  CACHE { CACHE_LOBBY, CACHE_GAME }

Functions

static void set_font_list (const std::vector< subset_descriptor > &fontlist)
static surface render_text (const std::string &text, int fontsize, const SDL_Color &colour, int style)
surface get_rendered_text (const std::string &str, int size, const SDL_Color &colour, int style)
SDL_Rect draw_text_line (surface gui_surface, const SDL_Rect &area, int size, const SDL_Color &colour, const std::string &text, int x, int y, bool use_tooltips, int style)
SDL_Rect draw_text_line (CVideo *gui, const SDL_Rect &area, int size, const SDL_Color &colour, const std::string &text, int x, int y, bool use_tooltips, int style)
int get_max_height (int size)
int line_width (const std::string &line, int font_size, int style=TTF_STYLE_NORMAL)
 Determine the width of a line of text given a certain font size.
SDL_Rect line_size (const std::string &line, int font_size, int style=TTF_STYLE_NORMAL)
 Determine the size of a line of text given a certain font size.
std::string make_text_ellipsis (const std::string &text, int font_size, int max_width, bool with_tags=true)
 If the text excedes the specified max width, end it with an ellipsis (.
int add_floating_label (const std::string &text, int font_size, const SDL_Color &colour, double xpos, double ypos, double xmove, double ymove, int lifetime, const SDL_Rect &clip_rect, ALIGN alignment=CENTER_ALIGN, const SDL_Color *bg_colour=NULL, int border_size=0, LABEL_SCROLL_MODE scroll_mode=ANCHOR_LABEL_SCREEN)
 add a label floating on the screen above everything else.
void move_floating_label (int handle, double xmove, double ymove)
 moves the floating label given by 'handle' by (xmove,ymove)
void scroll_floating_labels (double xmove, double ymove)
 moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
void remove_floating_label (int handle)
 removes the floating label given by 'handle' from the screen
void show_floating_label (int handle, bool show)
 hides or shows a floating label
SDL_Rect get_floating_label_rect (int handle)
void draw_floating_labels (surface screen)
void undraw_floating_labels (surface screen)
bool load_font_config ()
void cache_mode (CACHE mode)
int relative_size (int size)
static std::string::const_iterator parse_markup (std::string::const_iterator i1, std::string::const_iterator i2, int *font_size, SDL_Color *colour, int *style)
 Parses the markup-tags at the front of a string.
std::string del_tags (const std::string &text)
 Copy string, but without tags at the beginning.
std::string nullify_markup (const std::string &text)
 Copy string, but with NULL MARKUP tag at the beginning of each line.
std::string color2markup (const SDL_Color color)
 Create string of color-markup, such as "<255,255,0>" for yellow.
SDL_Rect text_area (const std::string &text, int size, int style)
 Calculate the size of a text (in pixels) if it were to be drawn.
SDL_Rect draw_text (CVideo *gui, const SDL_Rect &area, int size, const SDL_Color &colour, const std::string &txt, int x, int y, bool use_tooltips, int style)
 Draw text on the screen, clip text to area.
bool is_format_char (char c)
 Determine if char is one of the special chars used as markup.
static void cut_word (std::string &line, std::string &word, int font_size, int style, int max_width)
bool no_break_after (wchar_t ch)
bool no_break_before (wchar_t ch)
bool break_before (wchar_t ch)
bool break_after (wchar_t ch)
std::string word_wrap_text (const std::string &unwrapped_text, int font_size, int max_width, int max_height, int max_lines)
 Wrap text.
SDL_Rect draw_wrapped_text (CVideo *gui, const SDL_Rect &area, int font_size, const SDL_Color &colour, const std::string &text, int x, int y, int max_width)
 Draw text on the screen, fit text to maximum width, no markup, no tooltips.
size_t text_to_lines (std::string &message, size_t max_length)
 Chop up one long string of text into lines.

Variables

const SDL_Color NORMAL_COLOUR = {0xDD,0xDD,0xDD,0}
const SDL_Color GRAY_COLOUR = {0x77,0x77,0x77,0}
const SDL_Color LOBBY_COLOUR = {0xBB,0xBB,0xBB,0}
const SDL_Color GOOD_COLOUR = {0x00,0xFF,0x00,0}
const SDL_Color BAD_COLOUR = {0xFF,0x00,0x00,0}
const SDL_Color BLACK_COLOUR = {0x00,0x00,0x00,0}
const SDL_Color YELLOW_COLOUR = {0xFF,0xFF,0x00,0}
const SDL_Color BUTTON_COLOUR = {0xBC,0xB0,0x88,0}
const SDL_Color STONED_COLOUR = {0xA0,0xA0,0xA0,0}
const SDL_Color TITLE_COLOUR = {0xBC,0xB0,0x88,0}
const SDL_Color LABEL_COLOUR = {0x6B,0x8C,0xFF,0}
const SDL_Color BIGMAP_COLOUR = {0xFF,0xFF,0xFF,0}
const SDL_Color DISABLED_COLOUR = inverse(STONED_COLOUR)
static const size_t max_text_line_width = 4096
const int SIZE_NORMAL = 14
const int SIZE_TINY = relative_size(10)
const int SIZE_SMALL = relative_size(12)
const int SIZE_15 = relative_size(15)
const int SIZE_PLUS = relative_size(16)
const int SIZE_LARGE = relative_size(18)
const int SIZE_XLARGE = relative_size(24)
const char LARGE_TEXT = '*'
 Standard markups for color, size, font, images.
const char SMALL_TEXT = '`'
const char BOLD_TEXT = '~'
const char NORMAL_TEXT = '{'
const char NULL_MARKUP = '^'
const char BLACK_TEXT = '}'
const char GRAY_TEXT = '|'
const char GOOD_TEXT = '@'
const char BAD_TEXT = '#'
const char GREEN_TEXT = '@'
const char RED_TEXT = '#'
const char COLOR_TEXT = '<'
const char IMAGE = '&'
const char YELLOW_TEXT


Detailed Description

Graphical text output.

This module is used to display and measure text. Text can optionally contain special characters, which may change specified display properties such as colour or font size. If special characters are turned on, they can be escaped, C-style, using backslashes.


Enumeration Type Documentation

Enumerator:
LEFT_ALIGN 
CENTER_ALIGN 
RIGHT_ALIGN 

Definition at line 116 of file font.hpp.

Enumerator:
CACHE_LOBBY 
CACHE_GAME 

Definition at line 155 of file font.hpp.

Enumerator:
ANCHOR_LABEL_SCREEN 
ANCHOR_LABEL_MAP 

Definition at line 118 of file font.hpp.


Function Documentation

int font::add_floating_label ( const std::string &  text,
int  font_size,
const SDL_Color &  colour,
double  xpos,
double  ypos,
double  xmove,
double  ymove,
int  lifetime,
const SDL_Rect &  clip_rect,
ALIGN  alignment = CENTER_ALIGN,
const SDL_Color *  bg_colour = NULL,
int  border_size = 0,
LABEL_SCROLL_MODE  scroll_mode = ANCHOR_LABEL_SCREEN 
)

add a label floating on the screen above everything else.

'text': the text to display 'font_size': the size to display the text in 'colour': the colour of the text 'xpos,ypos': the location on the screen to display the text. 'xmove,ymove': the amount to move the text each frame 'lifetime': the number of frames to display the text for, or -1 to display until removed 'clip_rect': the rectangle to clip the label to.

Returns:
a handle to the label which can be used with other label functions

Definition at line 939 of file font.cpp.

References ANCHOR_LABEL_MAP, and floating_label.

Referenced by game_display::add_chat_message(), display::announce(), terrain_label::draw(), game_display::float_label(), display::set_diagnostic(), CVideo::set_help_string(), show_tooltip(), display::update_display(), and gui::floating_textbox::update_location().

bool font::@122::break_after ( wchar_t  ch  )  [inline, static]

Definition at line 336 of file marked-up_text.cpp.

References no_break_after().

Referenced by word_wrap_text().

bool font::@122::break_before ( wchar_t  ch  )  [inline, static]

Definition at line 324 of file marked-up_text.cpp.

References no_break_before().

Referenced by word_wrap_text().

void font::cache_mode ( CACHE  mode  ) 

Definition at line 1157 of file font.cpp.

References CACHE_LOBBY.

Referenced by run_lobby_loop().

std::string font::color2markup ( const SDL_Color  color  ) 

Create string of color-markup, such as "<255,255,0>" for yellow.

Definition at line 157 of file marked-up_text.cpp.

Referenced by reports::generate_report(), dialogs::units_list_preview_pane::get_details(), and events::menu_handler::unit_list().

static void font::cut_word ( std::string &  line,
std::string &  word,
int  font_size,
int  style,
int  max_width 
) [static]

std::string font::del_tags ( const std::string &  text  ) 

Copy string, but without tags at the beginning.

Definition at line 132 of file marked-up_text.cpp.

References utils::join(), parse_markup(), and utils::split().

Referenced by gui::menu::basic_sorter::less(), and make_text_ellipsis().

void font::draw_floating_labels ( surface  screen  ) 

SDL_Rect font::draw_text ( CVideo gui,
const SDL_Rect &  area,
int  size,
const SDL_Color &  colour,
const std::string &  txt,
int  x,
int  y,
bool  use_tooltips,
int  style 
)

Draw text on the screen, clip text to area.

Supports simple markup.

If the text runs outside of area horizontally, an ellipsis will be displayed at the end of it. If use_tooltips is true, then text with an ellipsis will have a tooltip set for it equivalent to the entire contents of the text.

Some very basic 'markup' will be done on the text:

  • any line beginning in # will be displayed in BAD_COLOUR (red)
  • any line beginning in @ will be displayed in GOOD_COLOUR (green)
  • any line beginning in + will be displayed with size increased by 2
  • any line beginning in - will be displayed with size decreased by 2
  • any line beginning with 0x0n will be displayed in the colour of side n

The above special characters can be quoted using a C-style backslash.

A bounding rectangle of the text is returned. If gui is NULL, then the text will not be drawn, and only a bounding rectangle will be returned.

Definition at line 195 of file marked-up_text.cpp.

References draw_text_line(), parse_markup(), rect, text, and utils::unescape().

Referenced by gui::button::calculate_size(), draw_background(), gui::progress_bar::draw_contents(), mp::wait::leader_preview_pane::draw_contents(), mp::gamebrowser::draw_contents(), gui::label::draw_contents(), dialogs::campaign_preview_pane::draw_contents(), dialogs::unit_preview_pane::draw_contents(), gui::button::draw_contents(), draw_label(), gui::menu::draw_row(), draw_tip_of_day(), gui::dialog_frame::draw_title(), draw_wrapped_text(), gui::menu::style::item_size(), map_editor::new_map_dialog(), map_editor::preferences_dialog(), display::refresh_report(), map_editor::resize_dialog(), loadscreen::set_progress(), about::show_about(), preferences::show_hotkeys_dialog(), show_intro_part(), show_intro_part_helper(), text_area(), the_end(), and default_map_generator::user_config().

SDL_Rect font::draw_text_line ( CVideo gui,
const SDL_Rect &  area,
int  size,
const SDL_Color &  colour,
const std::string &  text,
int  x,
int  y,
bool  use_tooltips,
int  style 
)

Definition at line 688 of file font.cpp.

References CVideo::getSurface().

SDL_Rect font::draw_text_line ( surface  gui_surface,
const SDL_Rect &  area,
int  size,
const SDL_Color &  colour,
const std::string &  text,
int  x,
int  y,
bool  use_tooltips,
int  style 
)

SDL_Rect font::draw_wrapped_text ( CVideo gui,
const SDL_Rect &  area,
int  font_size,
const SDL_Color &  colour,
const std::string &  text,
int  x,
int  y,
int  max_width 
)

Draw text on the screen, fit text to maximum width, no markup, no tooltips.

This method makes sure that the text fits within a given maximum width. If a line exceedes this width, it will be wrapped on a word basis if possible, otherwise on a char basis. This method is otherwise similar to the draw_text method, but it doesn't support special markup or tooltips.

Returns:
a bounding rectangle of the text.

Definition at line 481 of file marked-up_text.cpp.

References draw_text(), and word_wrap_text().

Referenced by mp::wait::leader_preview_pane::draw_contents().

SDL_Rect font::get_floating_label_rect ( int  handle  ) 

int font::get_max_height ( int  size  ) 

surface font::get_rendered_text ( const std::string &  str,
int  size,
const SDL_Color &  colour,
int  style 
)

bool font::is_format_char ( char  c  ) 

Determine if char is one of the special chars used as markup.

Return values:
true input-char is a markup-char
false input-char is a normal char

Definition at line 247 of file marked-up_text.cpp.

References BAD_TEXT, BLACK_TEXT, BOLD_TEXT, GOOD_TEXT, GRAY_TEXT, LARGE_TEXT, NORMAL_TEXT, NULL_MARKUP, and SMALL_TEXT.

Referenced by text_to_lines(), and word_wrap_text().

SDL_Rect font::line_size ( const std::string &  line,
int  font_size,
int  style = TTF_STYLE_NORMAL 
)

Determine the size of a line of text given a certain font size.

Similar to line_width, but for both coordinates.

Definition at line 717 of file font.cpp.

References cache, and line_size_cache.

Referenced by cut_word(), gui2::tcontrol::get_single_line_best_size(), line_width(), loadscreen::set_progress(), show_intro_part(), and word_wrap_text().

int font::line_width ( const std::string &  line,
int  font_size,
int  style = TTF_STYLE_NORMAL 
)

bool font::load_font_config (  ) 

std::string font::make_text_ellipsis ( const std::string &  text,
int  font_size,
int  max_width,
bool  with_tags = true 
)

If the text excedes the specified max width, end it with an ellipsis (.

..) The with_tags can probably always be set to false

Definition at line 739 of file font.cpp.

References del_tags(), utils::utf8_iterator::end(), line_width(), and utils::utf8_iterator::substr().

Referenced by gui::button::calculate_size(), mp::gamebrowser::draw_row(), gui::menu::draw_row(), draw_text_line(), events::menu_handler::save_game(), and help::help_text_area::set_items().

void font::move_floating_label ( int  handle,
double  xmove,
double  ymove 
)

moves the floating label given by 'handle' by (xmove,ymove)

Definition at line 962 of file font.cpp.

Referenced by game_display::prune_chat_messages(), terrain_label::scroll(), CVideo::set_help_string(), and show_tooltip().

bool font::@122::no_break_after ( wchar_t  ch  )  [inline, static]

Definition at line 300 of file marked-up_text.cpp.

Referenced by break_after(), and word_wrap_text().

bool font::@122::no_break_before ( wchar_t  ch  )  [inline, static]

Definition at line 309 of file marked-up_text.cpp.

Referenced by break_before(), and word_wrap_text().

std::string font::nullify_markup ( const std::string &  text  ) 

Copy string, but with NULL MARKUP tag at the beginning of each line.

Definition at line 146 of file marked-up_text.cpp.

References utils::join(), NULL_MARKUP, and utils::split().

static std::string::const_iterator font::parse_markup ( std::string::const_iterator  i1,
std::string::const_iterator  i2,
int *  font_size,
SDL_Color *  colour,
int *  style 
) [static]

Parses the markup-tags at the front of a string.

Definition at line 39 of file marked-up_text.cpp.

References BAD_COLOUR, BAD_TEXT, BLACK_COLOUR, BLACK_TEXT, BOLD_TEXT, COLOR_TEXT, GOOD_COLOUR, GOOD_TEXT, GRAY_COLOUR, GRAY_TEXT, LARGE_TEXT, lexical_cast(), NORMAL_COLOUR, NORMAL_TEXT, NULL_MARKUP, and SMALL_TEXT.

Referenced by del_tags(), draw_text(), and word_wrap_text().

int font::relative_size ( int  size  )  [inline]

void font::remove_floating_label ( int  handle  ) 

static surface font::render_text ( const std::string &  text,
int  fontsize,
const SDL_Color &  colour,
int  style 
) [static]

void font::scroll_floating_labels ( double  xmove,
double  ymove 
)

moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP

Definition at line 970 of file font.cpp.

Referenced by display::scroll().

static void font::set_font_list ( const std::vector< subset_descriptor > &  fontlist  )  [static]

Definition at line 284 of file font.cpp.

References clear_fonts(), file_exists(), font_map, font_names, game_config::path, subset, and WRN_FT.

Referenced by load_font_config().

void font::show_floating_label ( int  handle,
bool  value 
)

hides or shows a floating label

Definition at line 991 of file font.cpp.

Referenced by terrain_label::calculate_shroud().

SDL_Rect font::text_area ( const std::string &  text,
int  size,
int  style 
)

size_t font::text_to_lines ( std::string &  message,
size_t  max_length 
)

Chop up one long string of text into lines.

Definition at line 491 of file marked-up_text.cpp.

References is_format_char(), and push_back().

void font::undraw_floating_labels ( surface  screen  ) 

std::string font::word_wrap_text ( const std::string &  unwrapped_text,
int  font_size,
int  max_width,
int  max_height,
int  max_lines 
)


Variable Documentation

const SDL_Color font::BAD_COLOUR = {0xFF,0x00,0x00,0}

const char font::BAD_TEXT = '#'

const SDL_Color font::BIGMAP_COLOUR = {0xFF,0xFF,0xFF,0}

Definition at line 339 of file font.cpp.

Referenced by show_intro_part().

const SDL_Color font::BLACK_COLOUR = {0x00,0x00,0x00,0}

const char font::BLACK_TEXT = '}'

Definition at line 33 of file marked-up_text.cpp.

Referenced by is_format_char(), and parse_markup().

const char font::BOLD_TEXT = '~'

const SDL_Color font::BUTTON_COLOUR = {0xBC,0xB0,0x88,0}

Definition at line 335 of file font.cpp.

Referenced by gui::button::calculate_size(), and gui::button::draw_contents().

const char font::COLOR_TEXT = '<'

Definition at line 36 of file marked-up_text.cpp.

Referenced by parse_markup().

const SDL_Color font::DISABLED_COLOUR = inverse(STONED_COLOUR)

Definition at line 340 of file font.cpp.

Referenced by gui::slider::draw_contents(), and gui::label::get_colour().

const SDL_Color font::GOOD_COLOUR = {0x00,0xFF,0x00,0}

const char font::GOOD_TEXT = '@'

Definition at line 34 of file marked-up_text.cpp.

Referenced by is_format_char(), and parse_markup().

const SDL_Color font::GRAY_COLOUR = {0x77,0x77,0x77,0}

Definition at line 329 of file font.cpp.

Referenced by gui::button::draw_contents(), mp::gamebrowser::draw_row(), and parse_markup().

const char font::GRAY_TEXT = '|'

Definition at line 33 of file marked-up_text.cpp.

Referenced by reports::generate_report(), is_format_char(), and parse_markup().

const char font::GREEN_TEXT = '@'

Definition at line 35 of file marked-up_text.cpp.

Referenced by events::menu_handler::unit_list().

const char font::IMAGE = '&'

const SDL_Color font::LABEL_COLOUR = {0x6B,0x8C,0xFF,0}

Definition at line 338 of file font.cpp.

Referenced by events::menu_handler::label_terrain(), and terrain_label::read().

const char font::LARGE_TEXT = '*'

Standard markups for color, size, font, images.

Definition at line 30 of file marked-up_text.cpp.

Referenced by is_format_char(), parse_markup(), events::menu_handler::recruit(), and about::show_about().

const SDL_Color font::LOBBY_COLOUR = {0xBB,0xBB,0xBB,0}

Definition at line 330 of file font.cpp.

const size_t font::max_text_line_width = 4096 [static]

Definition at line 344 of file font.cpp.

const SDL_Color font::NORMAL_COLOUR = {0xDD,0xDD,0xDD,0}

const char font::NORMAL_TEXT = '{'

const char font::NULL_MARKUP = '^'

const char font::RED_TEXT = '#'

Definition at line 35 of file marked-up_text.cpp.

Referenced by events::menu_handler::unit_list().

const int font::SIZE_15 = relative_size(15)

Definition at line 68 of file font.hpp.

const int font::SIZE_LARGE = relative_size(18)

const int font::SIZE_NORMAL = 14

const int font::SIZE_PLUS = relative_size(16)

const int font::SIZE_SMALL = relative_size(12)

const int font::SIZE_TINY = relative_size(10)

Definition at line 65 of file font.hpp.

Referenced by draw_background().

const int font::SIZE_XLARGE = relative_size(24)

const char font::SMALL_TEXT = '`'

Definition at line 30 of file marked-up_text.cpp.

Referenced by is_format_char(), parse_markup(), and about::show_about().

const SDL_Color font::STONED_COLOUR = {0xA0,0xA0,0xA0,0}

Definition at line 336 of file font.cpp.

const SDL_Color font::TITLE_COLOUR = {0xBC,0xB0,0x88,0}

Definition at line 337 of file font.cpp.

Referenced by gui::dialog_frame::draw_title().

const SDL_Color font::YELLOW_COLOUR = {0xFF,0xFF,0x00,0}

const char font::YELLOW_TEXT


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