diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-11 16:08:59 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-11 16:08:59 (GMT) |
| commit | 9f7b06ff47e12076a261b6a209b27c558741eb8a (patch) | |
| tree | d0b4c8f53d976b1e2c1d771da47d7a9e4517db4d /src/interface/Textblock.cpp | |
| parent | 54741c79ef6169eda47745ea4f13e4e1d9982497 (diff) | |
| download | powder-9f7b06ff47e12076a261b6a209b27c558741eb8a.zip powder-9f7b06ff47e12076a261b6a209b27c558741eb8a.tar.gz | |
Comments on save preview and some minor changes for vote bars
Diffstat (limited to 'src/interface/Textblock.cpp')
| -rw-r--r-- | src/interface/Textblock.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/interface/Textblock.cpp b/src/interface/Textblock.cpp new file mode 100644 index 0000000..c378925 --- /dev/null +++ b/src/interface/Textblock.cpp @@ -0,0 +1,76 @@ +/* + * Textblock.cpp + * + * Created on: Jan 29, 2012 + * Author: Simon + */ + +#include <iostream> +#include "Textblock.h" + +using namespace ui; + +Textblock::Textblock(Point position, Point size, std::string textboxText): + Label(position, size, textboxText) +{ + if(size.Y==-1) + autoHeight = true; + else + autoHeight = false; + updateMultiline(); +} + +void Textblock::SetText(std::string text) +{ + this->text = text; + updateMultiline(); +} + +void Textblock::updateMultiline() +{ + char * rawText = (char*)malloc(text.length()+1); + memcpy(rawText, text.c_str(), text.length()); + rawText[text.length()] = 0; + + int lines = 1; + 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'; + lines++; + } + else + currentWidth += width; + if(nextSpace) + nextSpace[0] = ' '; + if(!(currentWord = strchr(currentWord+1, ' '))) + break; + } + if(autoHeight) + { + Size.Y = lines*12; + } + textLines = rawText; +} + +void Textblock::Draw(const Point &screenPos) +{ + Graphics * g = ui::Engine::Ref().g; + //g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, textColour.Red, textColour.Green, textColour.Blue, 255); + g->drawtext(screenPos.X+3, screenPos.Y+3, textLines, textColour.Red, textColour.Green, textColour.Blue, 255); +} + +Textblock::~Textblock() { + // TODO Auto-generated destructor stub +} + |
