diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-05-15 17:13:17 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-05-15 17:13:17 (GMT) |
| commit | 136675b56a8a1862afb41ccee5c14e93e483b964 (patch) | |
| tree | 8f679477c5e1c0984a5cb9c169e339c1ca0d6e0c /src/interface/Textbox.cpp | |
| parent | 45563e97e813cfd21724ad1111e5de3e04679e1a (diff) | |
| download | powder-136675b56a8a1862afb41ccee5c14e93e483b964.zip powder-136675b56a8a1862afb41ccee5c14e93e483b964.tar.gz | |
Move style into Component
Diffstat (limited to 'src/interface/Textbox.cpp')
| -rw-r--r-- | src/interface/Textbox.cpp | 53 |
1 files changed, 8 insertions, 45 deletions
diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 991ccac..8657e8e 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -12,14 +12,11 @@ Textbox::Textbox(Point position, Point size, std::string textboxText): Component(position, size), text(textboxText), textPosition(ui::Point(0, 0)), - textVAlign(AlignMiddle), - textHAlign(AlignCentre), actionCallback(NULL), masked(false), border(true) { SetText(textboxText); - TextPosition(); cursor = text.length(); } @@ -29,57 +26,19 @@ Textbox::~Textbox() delete actionCallback; } -void Textbox::TextPosition() -{ - if(cursor) - { - cursorPosition = Graphics::textnwidth((char *)displayText.c_str(), cursor); - } - else - { - cursorPosition = 0; - } - //Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2 - switch(textVAlign) - { - case AlignTop: - textPosition.Y = 3; - break; - case AlignMiddle: - textPosition.Y = (Size.Y-10)/2; - break; - case AlignBottom: - textPosition.Y = Size.Y-11; - break; - } - - switch(textHAlign) - { - case AlignLeft: - textPosition.X = 3; - break; - case AlignCentre: - textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))/2; - break; - case AlignRight: - textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))-2; - break; - } -} - void Textbox::SetText(std::string text) { cursor = text.length(); this->text = text; this->displayText = text; - TextPosition(); + TextPosition(displayText); } void Textbox::SetDisplayText(std::string text) { displayText = text; - TextPosition(); + TextPosition(displayText); } std::string Textbox::GetText() @@ -140,7 +99,6 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool if(cursor == text.length()) { text += character; - //std::cout << key << std::endl; } else { @@ -171,11 +129,16 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool if(actionCallback) actionCallback->TextChangedCallback(this); } - TextPosition(); + TextPosition(displayText); } void Textbox::Draw(const Point& screenPos) { + if(!drawn) + { + TextPosition(displayText); + drawn = true; + } Graphics * g = Engine::Ref().g; if(IsFocused()) { |
