marked-up_text.hpp

Go to the documentation of this file.
00001 /* $Id: marked-up_text.hpp 23842 2008-02-16 08:47:16Z 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 
00015 //! @file marked-up_text.hpp 
00016 //!
00017 
00018 #ifndef MARKED_UP_TEXT_HPP_INCLUDED
00019 #define MARKED_UP_TEXT_HPP_INCLUDED
00020 
00021 class CVideo;
00022 
00023 #include <SDL_video.h>
00024 #include <string>
00025 
00026 namespace font {
00027 
00028 //! Standard markups for color, size, font, images.
00029 extern const char LARGE_TEXT, SMALL_TEXT, BOLD_TEXT, NORMAL_TEXT, NULL_MARKUP, BLACK_TEXT, GRAY_TEXT,
00030                   GOOD_TEXT, BAD_TEXT, GREEN_TEXT, RED_TEXT, COLOR_TEXT, YELLOW_TEXT, IMAGE;
00031 
00032 
00033 //Function to draw text on the screen. The text will be clipped to area.
00034 //If the text runs outside of area horizontally, an ellipsis will be displayed
00035 //at the end of it.
00036 //If use_tooltips is true, then text with an ellipsis will have a tooltip
00037 //set for it equivalent to the entire contents of the text.
00038 //
00039 //Some very basic 'markup' will be done on the text:
00040 // - any line beginning in # will be displayed in BAD_COLOUR  (red)
00041 // - any line beginning in @ will be displayed in GOOD_COLOUR (green)
00042 // - any line beginning in + will be displayed with size increased by 2
00043 // - any line beginning in - will be displayed with size decreased by 2
00044 // - any line beginning with 0x0n will be displayed in the colour of side n
00045 //
00046 //The above special characters can be quoted using a C-style backslash.
00047 //
00048 //A bounding rectangle of the text is returned. If gui is NULL, then the
00049 //text will not be drawn, and a bounding rectangle only will be returned.
00050 
00051 SDL_Rect draw_text(CVideo* gui, const SDL_Rect& area, int size,
00052                    const SDL_Color& colour, const std::string& text,
00053                    int x, int y, bool use_tooltips = false, int style = 0);
00054 
00055 //- Calculate the size of a text (in pixels) if it were to be drawn.
00056 SDL_Rect text_area(const std::string& text, int size, int style=0);
00057 
00058 // Copy string, but without tags at the beginning 
00059 std::string del_tags(const std::string& text);
00060 
00061 // Copy string, but with NULL MARKUP tag at the beginning of each line
00062 std::string nullify_markup(const std::string& text);
00063 
00064 //- Determine if char is one of the special chars used as markup.
00065 bool is_format_char(char c);
00066 
00067 //- Create string of color-markup, such as "<255,255,0>" for yellow.
00068 std::string color2markup(const SDL_Color color);
00069 
00070 
00071 //- Wrap text.
00072 //- If the text exceedes the specified max width, wrap it one a word basis.
00073 //- If this is not possible, e.g. the word is too big to fit, wrap it on a
00074 //- char basis.
00075 std::string word_wrap_text(const std::string& unwrapped_text, int font_size, int max_width, int max_height=-1, int max_lines=-1);
00076 
00077 //- Draw text on the screen, fit text to maximum width, no markup, no tooltips.
00078 SDL_Rect draw_wrapped_text(CVideo* gui, const SDL_Rect& area, int font_size,
00079                  const SDL_Color& colour, const std::string& text,
00080                  int x, int y, int max_width);
00081 
00082 //- Chop up one long string of text into lines.
00083 size_t text_to_lines(std::string& text, size_t max_length);
00084 
00085 } // end namespace font 
00086 
00087 #endif // MARKED_UP_TEXT_HPP_INCLUDED
00088 

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