00001 #ifndef GUI_EDITBOX_HPP
00002 #define GUI_EDITBOX_HPP
00003
00004 #include <utils.hpp>
00005 #include <utils_string.hpp>
00006 #include "gui_focusframe.hpp"
00007 #include "gui_color.hpp"
00008
00009 #include <deque>
00010
00011 namespace gui
00012 {
00013 class font_string;
00014 class texture;
00015
00017
00021 class periodic_timer
00022 {
00023 public :
00024
00025 enum start_type
00026 {
00028 START_PAUSED,
00030 START_NOW,
00032 START_FIRST_TICK
00033 };
00034
00036
00040 periodic_timer(const double& dDuration, start_type mType, bool bTicks);
00041
00043
00045 const double& get_elapsed();
00046
00048
00050 const double& get_period() const;
00051
00053
00055 bool is_paused() const;
00056
00058
00060 bool ticks();
00061
00063 void stop();
00064
00066 void start();
00067
00069 void pause();
00070
00072 void zero();
00073
00075
00077 void update(double dDelta);
00078
00079 private :
00080
00081 double dElapsed_;
00082 double dDuration_;
00083 bool bPaused_;
00084 bool bFirstTick_;
00085
00086 start_type mType_;
00087 };
00088
00090 class edit_box : public focus_frame
00091 {
00092 public :
00093
00095 explicit edit_box(manager* pManager);
00096
00098 virtual ~edit_box();
00099
00101
00103 virtual void copy_from(uiobject* pObj);
00104
00106 virtual void update(float fDelta);
00107
00109
00111 virtual void on_event(const event& mEvent);
00112
00114
00117 virtual void on(const std::string& sScriptName, event* pEvent = nullptr);
00118
00120
00123 virtual bool can_use_script(const std::string& sScriptName) const;
00124
00126
00128 virtual void enable_keyboard(bool bIsKeyboardEnabled);
00129
00131
00133 void set_text(const std::string& sText);
00134
00136
00138 const std::string& get_text() const;
00139
00141
00146 void highlight_text(uint uiStart = 0u, uint uiEnd = uint(-1), bool bForceUpdate = false);
00147
00149 void unlight_text();
00150
00152
00154 void set_highlight_color(const color& mColor);
00155
00157
00159 void insert_after_cursor(const std::string& sText);
00160
00162
00164 void set_max_letters(uint uiMaxLetters);
00165
00167
00169 uint get_max_letters() const;
00170
00172
00174 uint get_num_letters() const;
00175
00177
00179 void set_blink_speed(const double& dBlinkSpeed);
00180
00182
00184 const double& get_blink_speed() const;
00185
00187
00189 void set_numeric_only(bool bNumericOnly);
00190
00192
00195 void set_positive_only(bool bPositiveOnly);
00196
00198
00201 void set_integer_only(bool bIntegerOnly);
00202
00204
00206 bool is_numeric_only() const;
00207
00209
00211 bool is_positive_only() const;
00212
00214
00216 bool is_integer_only() const;
00217
00219
00223 void enable_password_mode(bool bEnable);
00224
00226
00228 bool is_password_mode_enabled() const;
00229
00231
00238 void set_multi_line(bool bMultiLine);
00239
00241
00243 bool is_multi_line() const;
00244
00246
00248 void set_max_history_lines(uint uiMaxHistoryLines);
00249
00251
00253 uint get_max_history_lines() const;
00254
00256
00259 void add_history_line(const std::string& sHistoryLine);
00260
00262
00265 const std::deque<std::string>& get_history_lines() const;
00266
00268
00270 void set_arrows_ignored(bool bArrowsIgnored);
00271
00273
00280 void set_text_insets(int iLeft, int iRight, int iTop, int iBottom);
00281
00283
00287 void set_text_insets(const std::array<int,4>& lInsets);
00288
00290
00292 const std::array<int,4>& get_text_insets() const;
00293
00295
00297 font_string* get_font_string();
00298
00300
00303 virtual void notify_focus(bool bFocus);
00304
00306 virtual void create_glue();
00307
00309
00311 virtual void parse_block(xml::block* pBlock);
00312
00314 static void register_glue(utils::wptr<lua::state> pLua);
00315
00316 protected :
00317
00318 void notify_invisible_(bool bTriggerEvents = true);
00319
00320 void parse_font_string_block_(xml::block* pBlock);
00321 void parse_highlight_color_block_(xml::block* pBlock);
00322 void parse_text_insets_block_(xml::block* pBlock);
00323
00324 font_string* create_font_string_();
00325 void create_highlight_();
00326 void create_carret_();
00327
00328 void check_text_();
00329 void update_displayed_text_();
00330 void update_font_string_();
00331 void update_carret_position_();
00332
00333 bool add_char_(char32_t sChar);
00334 bool remove_char_();
00335 uint get_letter_id_at_(int iX, int iY);
00336 bool move_carret_at_(int iX, int iY);
00337 bool move_carret_horizontally_(bool bForward = true);
00338 bool move_carret_vertically_(bool bDown = true);
00339
00340 void process_key_(uint uiKey);
00341
00342 std::string sText_;
00343 utils::ustring sUnicodeText_;
00344 utils::ustring sDisplayedText_;
00345 utils::ustring::iterator iterCarretPos_;
00346
00347 uint uiDisplayPos_;
00348 uint uiNumLetters_;
00349 uint uiMaxLetters_;
00350 bool bNumericOnly_;
00351 bool bPositiveOnly_;
00352 bool bIntegerOnly_;
00353 bool bPasswordMode_;
00354 bool bMultiLine_;
00355 bool bArrowsIgnored_;
00356
00357 std::string sComboKey_;
00358
00359 texture* pHighlight_;
00360 color mHighlightColor_;
00361 uint uiSelectionStartPos_;
00362 uint uiSelectionEndPos_;
00363 bool bSelectedText_;
00364
00365 texture* pCarret_;
00366 double dBlinkSpeed_;
00367 periodic_timer mCarretTimer_;
00368
00369 std::deque<std::string> lHistoryLineList_;
00370 uint uiMaxHistoryLines_;
00371
00372 font_string* pFontString_;
00373 std::array<int,4> lTextInsets_;
00374
00375 uint uiLastKeyPressed_;
00376 double dKeyRepeatSpeed_;
00377 periodic_timer mKeyRepeatTimer_;
00378 };
00379
00383 class lua_edit_box : public lua_focus_frame
00384 {
00385 public :
00386
00387 explicit lua_edit_box(lua_State* pLua);
00388
00389
00390 int _add_history_line(lua_State*);
00391 int _get_blink_speed(lua_State*);
00392 int _get_history_lines(lua_State*);
00393 int _get_max_letters(lua_State*);
00394 int _get_num_letters(lua_State*);
00395 int _get_number(lua_State*);
00396 int _get_text(lua_State*);
00397 int _get_text_insets(lua_State*);
00398 int _highlight_text(lua_State*);
00399 int _insert(lua_State*);
00400 int _is_multi_line(lua_State*);
00401 int _is_numeric(lua_State*);
00402 int _is_password(lua_State*);
00403 int _set_blink_speed(lua_State*);
00404 int _set_max_history_lines(lua_State*);
00405 int _set_max_letters(lua_State*);
00406 int _set_multi_line(lua_State*);
00407 int _set_number(lua_State*);
00408 int _set_numeric(lua_State*);
00409 int _set_password(lua_State*);
00410 int _set_text(lua_State*);
00411 int _set_text_insets(lua_State*);
00412
00413 static const char className[];
00414 static const char* classList[];
00415 static Lunar<lua_edit_box>::RegType methods[];
00416
00417 protected :
00418
00419 edit_box* pEditBoxParent_;
00420 };
00421
00424 }
00425
00426 #endif