#include <text_box.h>
Inheritance diagram for TextBox:
Public Member Functions | |
TextBox (const std::string &label, const Rectanglei &rect, Font &_font) | |
~TextBox () | |
void | SendKey (SDL_keysym key) |
void | Draw (const Point2i &mousePosition, Surface &surf) const |
void | SetText (std::string const &new_txt) |
void | SetCursor (std::string::size_type pos) |
Protected Attributes | |
std::string::size_type | cursor_pos |
Definition at line 28 of file text_box.h.
TextBox::TextBox | ( | const std::string & | label, | |
const Rectanglei & | rect, | |||
Font & | _font | |||
) |
Definition at line 26 of file text_box.cpp.
00026 : 00027 Label(label, rect, _font), 00028 cursor_pos(label.size()) 00029 { 00030 }
TextBox::~TextBox | ( | ) |
Reimplemented from Label.
Definition at line 108 of file text_box.cpp.
00109 { 00110 if (!hidden) 00111 { 00112 if(have_focus) 00113 surf.BoxColor(*this, highlightOptionColorBox); 00114 00115 surf.RectangleColor(*this, defaultOptionColorRect); 00116 00117 Label::Draw(mousePosition, surf); 00118 00119 //sort of a hacky way to get the cursor pos, but I couldn't find anything better... 00120 Text txt_before_cursor(*txt_label); 00121 txt_before_cursor.Set(GetText().substr(0, cursor_pos)); 00122 00123 surf.VlineColor(GetPositionX()+txt_before_cursor.GetWidth(), 00124 GetPositionY()+2, 00125 GetPositionY()+GetSizeY()-4, c_white); 00126 } 00127 }
Here is the call graph for this function:
void TextBox::SendKey | ( | SDL_keysym | key | ) | [virtual] |
Reimplemented from Widget.
Definition at line 53 of file text_box.cpp.
00054 { 00055 need_redrawing = true; 00056 00057 std::string new_txt = GetText(); 00058 00059 if (strcmp(SDL_GetKeyName(key.sym),"backspace")==0) 00060 { 00061 if(cursor_pos != 0) 00062 { 00063 while((new_txt[--cursor_pos] & 0xc0) == 0x80) 00064 { 00065 new_txt.erase(cursor_pos, 1); 00066 } 00067 new_txt.erase(cursor_pos, 1); 00068 Label::SetText(new_txt); 00069 } 00070 } 00071 else if(strcmp(SDL_GetKeyName(key.sym),"left")==0) 00072 { 00073 if(cursor_pos != 0) 00074 { 00075 while((new_txt[--cursor_pos] & 0xc0) == 0x80); 00076 } 00077 } 00078 else if(strcmp(SDL_GetKeyName(key.sym),"right")==0) 00079 { 00080 if(cursor_pos < new_txt.size()) 00081 { 00082 while((new_txt[++cursor_pos] & 0xc0) == 0x80); 00083 } 00084 } 00085 else 00086 { 00087 if(key.unicode > 0) 00088 { 00089 if(key.unicode < 0x80) { // 1 byte char 00090 new_txt.insert(cursor_pos++, 1, (char)key.unicode); 00091 } 00092 else if (key.unicode < 0x800) // 2 byte char 00093 { 00094 new_txt.insert(cursor_pos++, 1, (char)(((key.unicode & 0x7c0) >> 6) | 0xc0)); 00095 new_txt.insert(cursor_pos++, 1, (char)((key.unicode & 0x3f) | 0x80)); 00096 } 00097 else // if (key.unicode < 0x10000) // 3 byte char 00098 { 00099 new_txt.insert(cursor_pos++, 1, (char)(((key.unicode & 0xf000) >> 12) | 0xe0)); 00100 new_txt.insert(cursor_pos++, 1, (char)(((key.unicode & 0xfc0) >> 6) | 0x80)); 00101 new_txt.insert(cursor_pos++, 1, (char)((key.unicode & 0x3f) | 0x80)); 00102 } 00103 } 00104 Label::SetText(new_txt); 00105 } 00106 }
Here is the call graph for this function:
void TextBox::SetCursor | ( | std::string::size_type | pos | ) |
Definition at line 38 of file text_box.cpp.
00039 { 00040 if(pos > GetText().size()) 00041 { 00042 cursor_pos = GetText().size(); 00043 } 00044 else 00045 { 00046 cursor_pos = pos; 00047 } 00048 }
Here is the call graph for this function:
void TextBox::SetText | ( | std::string const & | new_txt | ) |
Reimplemented from Label.
Definition at line 32 of file text_box.cpp.
00033 { 00034 Label::SetText(new_txt); 00035 cursor_pos = new_txt.size(); 00036 }
Here is the call graph for this function:
Here is the caller graph for this function:
std::string::size_type TextBox::cursor_pos [protected] |
Definition at line 31 of file text_box.h.