00001 #ifndef GUI_TEXT_HPP
00002 #define GUI_TEXT_HPP
00003
00004 #include <utils.hpp>
00005 #include "gui_color.hpp"
00006
00007 #include <utils_string.hpp>
00008 #include <utils_refptr.hpp>
00009 #include <map>
00010 #include <array>
00011
00012 namespace gui
00013 {
00014 class manager;
00015 class font;
00016 class sprite;
00017 struct vertex;
00018
00020
00022 class text
00023 {
00024 public :
00025
00027 struct line
00028 {
00029 utils::ustring sCaption;
00030 float fWidth;
00031 };
00032
00033 enum color_action
00034 {
00035 COLOR_ACTION_NONE,
00036 COLOR_ACTION_SET,
00037 COLOR_ACTION_RESET
00038 };
00039
00041 struct format
00042 {
00043 format() : mColorAction(COLOR_ACTION_NONE)
00044 {}
00045
00046 color mColor;
00047 color_action mColorAction;
00048 };
00049
00050 enum alignment
00051 {
00052 ALIGN_LEFT,
00053 ALIGN_CENTER,
00054 ALIGN_RIGHT
00055 };
00056
00057 enum vertical_alignment
00058 {
00059 ALIGN_TOP,
00060 ALIGN_MIDDLE,
00061 ALIGN_BOTTOM
00062 };
00063
00065 struct letter
00066 {
00067 float fX1, fY1;
00068 float fX2, fY2;
00069 float fU1, fV1;
00070 float fU2, fV2;
00071 color mColor;
00072 bool bNoRender;
00073 };
00074
00076
00079 text(manager* pManager, const std::string& sFileName, float fSize);
00080
00082 ~text();
00083
00085
00087 const std::string& get_font_name() const;
00088
00090
00092 float get_font_size() const;
00093
00095
00097 float get_line_height() const;
00098
00100
00106 void set_text(const std::string& sText);
00107
00109
00112 const std::string& get_text() const;
00113
00115
00118 const utils::ustring& get_unicode_text() const;
00119
00121
00124 void set_color(const color& mColor, bool bForceColor = false);
00125
00127
00129 const color& get_color() const;
00130
00132
00136 void set_dimensions(float fW, float fH);
00137
00139
00142 void set_box_width(float fBoxW);
00143
00145
00148 void set_box_height(float fBoxH);
00149
00151
00154 float get_width();
00155
00157
00160 float get_height();
00161
00163
00165 float get_box_width() const;
00166
00168
00170 float get_box_height() const;
00171
00173
00176 float get_text_width() const;
00177
00179
00182 float get_string_width(const std::string& sString) const;
00183
00185
00188 float get_string_width(const utils::ustring& sString) const;
00189
00191
00194 float get_character_width(uint uiChar) const;
00195
00197
00205 float get_character_kerning(uint uiChar1, uint uiChar2) const;
00206
00208
00211 float get_text_height() const;
00212
00214
00216 void set_alignment(const alignment& mAlign);
00217
00219
00221 void set_vertical_alignment(const vertical_alignment& mVertAlign);
00222
00224
00226 const alignment& get_alignment() const;
00227
00229
00231 const vertical_alignment& get_vertical_alignment() const;
00232
00234
00238 void set_tracking(float fTracking);
00239
00241
00243 float get_tracking() const;
00244
00246
00251 void set_line_spacing(float fLineSpacing);
00252
00254
00256 float get_line_spacing() const;
00257
00259
00267 void set_remove_starting_spaces(bool bRemoveStartingSpaces);
00268
00270
00272 bool get_remove_starting_spaces() const;
00273
00275
00280 void enable_word_wrap(bool bWrap, bool bAddEllipsis);
00281
00283
00285 bool is_word_wrap_enabled() const;
00286
00288
00294 void enable_formatting(bool bFormatting);
00295
00297
00302 void render(float fX, float fY);
00303
00305
00309 void update();
00310
00312
00315 const std::vector<letter>& get_letter_cache();
00316
00318
00321 utils::refptr<sprite> create_sprite(uint uiChar) const;
00322
00323 private :
00324
00325 void update_lines_();
00326 void update_cache_();
00327
00328 manager* pManager_;
00329
00330 std::string sFileName_;
00331
00332 bool bReady_;
00333 float fSize_;
00334 float fTracking_;
00335 float fLineSpacing_;
00336 float fSpaceWidth_;
00337 bool bRemoveStartingSpaces_;
00338 bool bWordWrap_;
00339 bool bAddEllipsis_;
00340 color mColor_;
00341 bool bForceColor_;
00342 bool bFormattingEnabled_;
00343 float fW_, fH_;
00344 float fX_, fY_;
00345 float fBoxW_, fBoxH_;
00346
00347 std::string sText_;
00348 utils::ustring sUnicodeText_;
00349 alignment mAlign_;
00350 vertical_alignment mVertAlign_;
00351
00352 std::vector<line> lLineList_;
00353 std::map<uint, format> lFormatList_;
00354
00355 bool bUpdateCache_;
00356 std::vector<letter> lLetterCache_;
00357
00358 bool bUpdateQuads_;
00359 std::vector<std::array<vertex,4>> lQuadList_;
00360 utils::refptr<sprite> pSprite_;
00361
00362 utils::refptr<font> pFont_;
00363 };
00364 }
00365
00366 #endif