WidgetTextInput.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROCKETCONTROLSWIDGETTEXTINPUT_H
00029 #define ROCKETCONTROLSWIDGETTEXTINPUT_H
00030
00031 #include <Rocket/Core/EventListener.h>
00032 #include <Rocket/Core/Geometry.h>
00033 #include <Rocket/Core/WString.h>
00034 #include <Rocket/Core/Vertex.h>
00035
00036 namespace Rocket {
00037 namespace Core {
00038
00039 class ElementText;
00040
00041 }
00042
00043 namespace Controls {
00044
00045 class ElementFormControl;
00046
00053 class WidgetTextInput : public Core::EventListener
00054 {
00055 public:
00056 WidgetTextInput(ElementFormControl* parent);
00057 virtual ~WidgetTextInput();
00058
00061 virtual void SetValue(const Core::String& value);
00062
00065 void SetMaxLength(int max_length);
00068 int GetMaxLength() const;
00069
00071 void UpdateSelectionColours();
00072
00074 void OnUpdate();
00076 void OnRender();
00078 void OnLayout();
00079
00081 Core::ElementText* GetTextElement();
00083 const Rocket::Core::Vector2f& GetTextDimensions() const;
00084
00085 protected:
00088 virtual void ProcessEvent(Core::Event& event);
00089
00093 bool AddCharacter(Rocket::Core::word character);
00097 bool DeleteCharacter(bool back);
00101 virtual bool IsCharacterValid(Rocket::Core::word character) = 0;
00103 virtual void LineBreak() = 0;
00104
00106 int GetCursorIndex() const;
00107
00109 Core::Element* GetElement();
00110
00112 void DispatchChangeEvent();
00113
00114 private:
00118 void MoveCursorHorizontal(int distance, bool select);
00122 void MoveCursorVertical(int distance, bool select);
00123
00125 void UpdateAbsoluteCursor();
00127 void UpdateRelativeCursor();
00128
00132 int CalculateLineIndex(float position);
00137 int CalculateCharacterIndex(int line_index, float position);
00138
00142 void ShowCursor(bool show, bool move_to_cursor = true);
00143
00145 void FormatElement();
00148 Rocket::Core::Vector2f FormatText();
00149
00151 void GenerateCursor();
00153 void UpdateCursorPosition();
00154
00157 void UpdateSelection(bool selecting);
00159 void ClearSelection();
00161 void DeleteSelection();
00163 void CopySelection();
00164
00171 void GetLineSelection(Core::WString& pre_selection, Core::WString& selection, Core::WString& post_selection, const Core::WString& line, int line_begin);
00172
00173 struct Line
00174 {
00175
00176 Core::WString content;
00177
00178 int content_length;
00179
00180
00181
00182 int extra_characters;
00183 };
00184
00185 ElementFormControl* parent;
00186
00187 Core::ElementText* text_element;
00188 Core::ElementText* selected_text_element;
00189 Rocket::Core::Vector2f internal_dimensions;
00190 Rocket::Core::Vector2f scroll_offset;
00191
00192 typedef std::vector< Line > LineList;
00193 LineList lines;
00194
00195 int max_length;
00196
00197 int edit_index;
00198
00199 int absolute_cursor_index;
00200 int cursor_line_index;
00201 int cursor_character_index;
00202
00203
00204 Core::Element* selection_element;
00205 int selection_anchor_index;
00206 int selection_begin_index;
00207 int selection_length;
00208
00209
00210 Rocket::Core::Colourb selection_colour;
00211
00212 Core::Geometry selection_geometry;
00213
00214
00215 float cursor_timer;
00216 bool cursor_visible;
00217
00218 float last_update_time;
00219
00220
00221 float ideal_cursor_position;
00222 Rocket::Core::Vector2f cursor_position;
00223 Rocket::Core::Vector2f cursor_size;
00224 Core::Geometry cursor_geometry;
00225 };
00226
00227 }
00228 }
00229
00230 #endif