00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_LINEEDIT_HPP_)
00012 #define _XRB_LINEEDIT_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include "xrb_characterfilter.hpp"
00017 #include "xrb_textwidget.hpp"
00018
00019 namespace Xrb
00020 {
00021
00022 class LineEdit : public TextWidget
00023 {
00024 public:
00025
00026 LineEdit (
00027 Uint32 character_limit,
00028 ContainerWidget *parent,
00029 std::string const &name = "LineEdit");
00030 virtual ~LineEdit () { }
00031
00032 inline Alignment GetAlignment () const { return m_alignment; }
00033 inline Uint32 CharacterLimit () const { return m_character_limit; }
00034 inline CharacterFilter &GetCharacterFilter () { return m_character_filter; }
00035 inline bool IsReadOnly () const { return m_is_read_only; }
00036
00037 virtual void SetText (std::string const &text);
00038 void SetAlignment (Alignment alignment);
00039 inline void SetCharacterFilter (CharacterFilter const &character_filter) { m_character_filter = character_filter; }
00040 inline void SetIsReadOnly (bool is_read_only) { m_is_read_only = is_read_only; }
00041
00042 inline SignalSender1<std::string const &> const *SenderTextUpdated () { return &m_sender_text_updated; }
00043 inline SignalSender1<std::string> const *SenderTextUpdatedV () { return &m_sender_text_updated_v; }
00044 inline SignalSender1<std::string const &> const *SenderTextSetByEnterKey () { return &m_sender_text_set_by_enter_key; }
00045 inline SignalSender1<std::string> const *SenderTextSetByEnterKeyV () { return &m_sender_text_set_by_enter_key_v; }
00046
00047 virtual void Draw (RenderContext const &render_context) const;
00048
00049 protected:
00050
00051 virtual void SetRenderFont (Resource<Font> const &render_font);
00052
00053 virtual void UpdateRenderBackground ();
00054
00055
00056 virtual void HandleChangedWidgetSkinWidgetBackground (
00057 WidgetSkin::WidgetBackgroundType widget_background_type);
00058
00059
00060 virtual void HandleFrame ();
00061
00062 virtual bool ProcessKeyEvent (EventKey const *e);
00063
00064 virtual bool ProcessMouseButtonEvent (EventMouseButton const *e);
00065
00066
00067 virtual void HandleFocus ();
00068
00069 virtual void HandleUnfocus ();
00070
00071 virtual void SignalTextUpdated ();
00072
00073 virtual void UpdateMinAndMaxSizesFromText ();
00074
00075 private:
00076
00077 ScreenCoord InitialPenPositionX () const;
00078 ScreenCoord CursorOffset (Uint32 cursor_position) const;
00079 ScreenCoord CursorWidth (Uint32 cursor_position) const;
00080
00081
00082
00083 void SetCursorPosition (Uint32 cursor_position);
00084
00085 void UpdateTextWidth ();
00086 void MakeCursorVisible ();
00087 void MoveCursorLeft ();
00088 void MoveCursorRight ();
00089 void TypeCharacter (char c);
00090 bool ShiftText (Uint32 position, Sint32 offset);
00091 void AssignFilteredString (std::string const &string);
00092
00093
00094 ScreenCoord m_text_width;
00095
00096 ScreenCoordVector2 m_text_offset;
00097
00098 Alignment m_alignment;
00099
00100 Uint32 m_character_limit;
00101
00102 Uint32 m_cursor_position;
00103
00104 bool m_does_cursor_overwrite;
00105
00106 bool m_is_cursor_visible;
00107
00108 Float m_cursor_blink_period;
00109
00110 Float m_next_cursor_blink_time;
00111
00112 std::string m_last_text_update;
00113
00114 CharacterFilter m_character_filter;
00115
00116 bool m_is_read_only;
00117
00118
00119
00120
00121
00122 SignalSender1<std::string const &> m_sender_text_updated;
00123 SignalSender1<std::string> m_sender_text_updated_v;
00124 SignalSender1<std::string const &> m_sender_text_set_by_enter_key;
00125 SignalSender1<std::string> m_sender_text_set_by_enter_key_v;
00126 };
00127
00128 }
00129
00130 #endif // !defined(_LINEEDITBOX_HPP_)