diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-30 00:40:28 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-30 00:40:28 (GMT) |
| commit | 259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec (patch) | |
| tree | f0fe2c14499345121371bba0ecc3fe21d17e0953 /src/interface/Textarea.cpp | |
| parent | fe329e9127ebcb8c89c505c4c120e175810d280c (diff) | |
| download | powder-259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec.zip powder-259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec.tar.gz | |
ASCII for key events, save and Textarea (no caret, yet)
Diffstat (limited to 'src/interface/Textarea.cpp')
| -rw-r--r-- | src/interface/Textarea.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/interface/Textarea.cpp b/src/interface/Textarea.cpp new file mode 100644 index 0000000..fecc390 --- /dev/null +++ b/src/interface/Textarea.cpp @@ -0,0 +1,80 @@ +/* + * Textarea.cpp + * + * Created on: Jan 29, 2012 + * Author: Simon + */ + +#include <iostream> +#include "Textarea.h" + +using namespace ui; + +Textarea::Textarea(Point position, Point size, std::string textboxText): + Textbox(position, size, textboxText) +{ + updateMultiline(); +} + +void Textarea::SetText(std::string text) +{ + this->text = text; + updateMultiline(); +} + +void Textarea::updateMultiline() +{ + char * rawText = (char*)malloc(text.length()+1); + memcpy(rawText, text.c_str(), text.length()); + rawText[text.length()] = 0; + + int currentWidth = 0; + char * lastSpace = NULL; + char * currentWord = rawText; + char * nextSpace; + while(true) + { + nextSpace = strchr(currentWord+1, ' '); + if(nextSpace) + nextSpace[0] = 0; + int width = Graphics::textwidth(currentWord); + if(width+currentWidth > Size.X-6) + { + currentWidth = width; + currentWord[0] = '\n'; + } + else + currentWidth += width; + if(nextSpace) + nextSpace[0] = ' '; + if(!(currentWord = strchr(currentWord+1, ' '))) + break; + } + textLines = rawText; +} + +void Textarea::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +{ + Textbox::OnKeyPress(key, character, shift, ctrl, alt); + updateMultiline(); +} + +void Textarea::Draw(const Point &screenPos) +{ + Graphics * g = ui::Engine::Ref().g; + if(IsFocused()) + { + g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255); + g->drawtext(screenPos.X+3, screenPos.Y+3, textLines, 255, 255, 255, 255); + } + else + { + g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255); + g->drawtext(screenPos.X+3, screenPos.Y+3, textLines, 160, 160, 160, 255); + } +} + +Textarea::~Textarea() { + // TODO Auto-generated destructor stub +} + |
