00001
00002
00003
00004
00005
00006
00007
00009
00020 #ifndef __TEXTBOX_HEADER__
00021 #define __TEXTBOX_HEADER__
00022
00023 #include "defs.h"
00024 #include "utils.h"
00025 #include "gui.h"
00026
00027 namespace hoa_video {
00028
00029 namespace private_video {
00030
00032 const uint16 NEWLINE_CHARACTER = static_cast<uint16>('\n');
00033
00035 const uint32 CHARS_PER_LINE = 30;
00036
00037 }
00038
00048 enum TEXT_DISPLAY_MODE {
00049 VIDEO_TEXT_INSTANT = 0,
00050 VIDEO_TEXT_CHAR = 1,
00051 VIDEO_TEXT_FADELINE = 2,
00052 VIDEO_TEXT_FADECHAR = 3,
00053 VIDEO_TEXT_REVEAL = 4,
00054 VIDEO_TEXT_TOTAL = 5
00055 };
00056
00057
00071 class TextBox : public private_video::GUIControl {
00072 public:
00073 TextBox();
00074
00075 TextBox(float x, float y, float width, float height, const TEXT_DISPLAY_MODE &mode = VIDEO_TEXT_INSTANT);
00076
00077 ~TextBox();
00078
00080 void ClearText();
00081
00086 void Update(uint32 frame_time);
00087
00092 void Draw();
00093
00097 void ForceFinish()
00098 { if (_text.empty() == true) return; _finished = true; }
00099
00107 void SetDimensions(float w, float h);
00108
00113 void SetTextAlignment(int32 xalign, int32 yalign);
00114
00118 void SetFont(const std::string &font_name);
00119
00123 void SetDisplayMode(const TEXT_DISPLAY_MODE &mode);
00124
00132 void SetDisplaySpeed(float display_speed);
00133
00142 void SetDisplayText(const hoa_utils::ustring& text);
00143
00148 void SetDisplayText(const std::string& text);
00149
00156 void GetDimensions(float& w, float& h)
00157 { w = _width; h = _height; }
00158
00163 void GetTextAlignment(int32& xalign, int32& yalign)
00164 { xalign = _text_xalign; yalign = _text_yalign; }
00165
00169 std::string GetFont() const
00170 { return _font; }
00171
00173 TEXT_DISPLAY_MODE GetDisplayMode() const
00174 { return _mode; }
00175
00177 float GetDisplaySpeed() const
00178 { return _display_speed; }
00179
00181 void GetText(std::vector<hoa_utils::ustring>& text) const
00182 { text = _text; }
00183
00188 bool IsFinished() const
00189 { return _finished; }
00190
00192 bool IsEmpty() const
00193 { return _text.empty(); }
00194
00202 bool IsInitialized(std::string& errors);
00203
00204
00206 void SetTextColor(Color &color)
00207 { _text_color = color; }
00208
00209 private:
00211 float _width, _height;
00212
00214 float _display_speed;
00215
00217 int32 _text_xalign, _text_yalign;
00218
00220 uint32 _num_chars;
00221
00223 bool _finished;
00224
00226 uint32 _current_time;
00227
00229 uint32 _end_time;
00230
00232 std::string _font;
00233
00235 FontProperties* _font_properties;
00236
00238 TEXT_DISPLAY_MODE _mode;
00239
00241 std::vector<hoa_utils::ustring> _text;
00242
00244 hoa_utils::ustring _text_save;
00245
00247 Color _text_color;
00248
00253 int32 _CalculateTextHeight();
00254
00261 bool _IsBreakableChar(uint16 character);
00262
00268 void _AddLine(const hoa_utils::ustring &line);
00269
00275 void _DrawTextLines(float text_x, float text_y, ScreenRect scissor_rect);
00276
00279 void _ReformatText();
00280
00281 };
00282
00283 }
00284
00285 #endif // __TEXTBOX_HEADER__