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 | |
| 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')
| -rw-r--r-- | src/interface/Label.h | 5 | ||||
| -rw-r--r-- | src/interface/SaveButton.cpp | 4 | ||||
| -rw-r--r-- | src/interface/Spinner.cpp | 36 | ||||
| -rw-r--r-- | src/interface/Spinner.h | 29 | ||||
| -rw-r--r-- | src/interface/Textblock.cpp | 76 | ||||
| -rw-r--r-- | src/interface/Textblock.h | 33 |
6 files changed, 179 insertions, 4 deletions
diff --git a/src/interface/Label.h b/src/interface/Label.h index b925140..4f7ce7f 100644 --- a/src/interface/Label.h +++ b/src/interface/Label.h @@ -11,6 +11,7 @@ namespace ui { class Label : public Component { + protected: std::string text; ui::Point textPosition; HorizontalAlignment textHAlign; @@ -23,8 +24,8 @@ namespace ui //Label(std::string labelText); virtual ~Label(); - void TextPosition(); - void SetText(std::string text); + virtual void TextPosition(); + virtual void SetText(std::string text); HorizontalAlignment GetHAlignment() { return textHAlign; } VerticalAlignment GetVAlignment() { return textVAlign; } void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); } diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp index fa848bf..c251434 100644 --- a/src/interface/SaveButton.cpp +++ b/src/interface/SaveButton.cpp @@ -103,8 +103,8 @@ void SaveButton::Draw(const Point& screenPos) g->drawrect(screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255); g->drawrect(screenPos.X-3+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 6, thumbBoxSize.Y, 180, 180, 180, 255); - int voteBar = max(10.0f, ((float)(thumbBoxSize.Y))*voteRatio); - g->fillrect(screenPos.X-3+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(thumbBoxSize.Y-voteBar)+(Size.Y-21-thumbBoxSize.Y)/2, 6, voteBar, voteColour.Red, voteColour.Green, voteColour.Blue, 255); + int voteBar = max(10.0f, ((float)(thumbBoxSize.Y-2))*voteRatio); + g->fillrect(1+screenPos.X-3+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, 1+(screenPos.Y-2)+(thumbBoxSize.Y-voteBar)+(Size.Y-21-thumbBoxSize.Y)/2, 4, voteBar, voteColour.Red, voteColour.Green, voteColour.Blue, 255); } else { diff --git a/src/interface/Spinner.cpp b/src/interface/Spinner.cpp new file mode 100644 index 0000000..1ecad8d --- /dev/null +++ b/src/interface/Spinner.cpp @@ -0,0 +1,36 @@ +/* + * Spinner.cpp + * + * Created on: Feb 11, 2012 + * Author: Simon + */ + + +#include <math.h> +#include <iostream> +#include "Spinner.h" + +using namespace ui; + +Spinner::Spinner(Point position, Point size): + Component(position, size), cValue(0) +{ +} +void Spinner::Tick(float dt) +{ + cValue += 0.05f; +} +void Spinner::Draw(const Point& screenPos) +{ + Graphics * g = ui::Engine::Ref().g; + int baseX = screenPos.X+(Size.X/2); + int baseY = screenPos.Y+(Size.Y/2); + for(float t = 0.0f; t < 1.0f; t+=0.05f) + { + g->drawblob(baseX+(sin(cValue+t)*(Size.X/2)), baseY+(cos(cValue+t)*(Size.X/2)), t*255, t*255, t*255); + } +} +Spinner::~Spinner() +{ + +} diff --git a/src/interface/Spinner.h b/src/interface/Spinner.h new file mode 100644 index 0000000..089b0b5 --- /dev/null +++ b/src/interface/Spinner.h @@ -0,0 +1,29 @@ +/* + * Spinner.h + * + * Created on: Feb 11, 2012 + * Author: Simon + */ + +#ifndef SPINNER_H_ +#define SPINNER_H_ + +#include "Component.h" + +namespace ui +{ + +class Spinner: public Component +{ + float cValue; +public: + Spinner(Point position, Point size); + virtual void Tick(float dt); + virtual void Draw(const Point& screenPos); + virtual ~Spinner(); +}; + +} + + +#endif /* SPINNER_H_ */ 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 +} + diff --git a/src/interface/Textblock.h b/src/interface/Textblock.h new file mode 100644 index 0000000..99b79e6 --- /dev/null +++ b/src/interface/Textblock.h @@ -0,0 +1,33 @@ +/* + * Textblock.h + * + * Created on: Jan 29, 2012 + * Author: Simon + */ + +#ifndef TEXTBLOCK_H_ +#define TEXTBLOCK_H_ + +#include <vector> +#include <string> +#include <sstream> +#include "Label.h" + +namespace ui +{ + +class Textblock: public ui::Label +{ + bool autoHeight; + void updateMultiline(); + std::string textLines; +public: + Textblock(Point position, Point size, std::string textboxText); + virtual void TextPosition() {} + virtual void SetText(std::string text); + virtual void Draw(const Point& screenPos); + virtual ~Textblock(); +}; +} + +#endif /* TEXTBLOCK_H_ */ |
