00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00030 struct manager {
00031 manager();
00032 ~manager();
00033 struct error {};
00034 };
00035
00036
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
00042 #ifdef USE_TINY_GUI
00043
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
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
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
00087 int get_max_height(int size);
00088
00089
00090
00091
00092
00093 int line_width(const std::string& line, int font_size, int style=TTF_STYLE_NORMAL);
00094
00095
00096
00097
00098
00099 SDL_Rect line_size(const std::string& line, int font_size, int style=TTF_STYLE_NORMAL);
00100
00101
00102
00103
00104
00105 std::string make_text_ellipsis(const std::string& text, int font_size, int max_width, bool with_tags = true);
00106
00107
00108
00109
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
00121
00122
00123
00124
00125
00126
00127
00128
00129
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
00137 void move_floating_label(int handle, double xmove, double ymove);
00138
00139
00140 void scroll_floating_labels(double xmove, double ymove);
00141
00142
00143 void remove_floating_label(int handle);
00144
00145
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