summaryrefslogtreecommitdiff
path: root/src/interface/Label.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-20 22:07:49 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-20 22:07:49 (GMT)
commitc8073657fcbfd1bfa72538d7babe4964857e7101 (patch)
treef3488e993c9828121b2f89ed2f639d2ebbe54dc9 /src/interface/Label.cpp
parentc5e8b345219cd7d8ca4b0aa638f59a1fed2cd83b (diff)
downloadpowder-c8073657fcbfd1bfa72538d7babe4964857e7101.zip
powder-c8073657fcbfd1bfa72538d7babe4964857e7101.tar.gz
More stuff, need to fix memory leak
Diffstat (limited to 'src/interface/Label.cpp')
-rw-r--r--src/interface/Label.cpp63
1 files changed, 54 insertions, 9 deletions
diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp
index cf09d4e..6fc47e2 100644
--- a/src/interface/Label.cpp
+++ b/src/interface/Label.cpp
@@ -1,30 +1,39 @@
#include <string>
#include "Config.h"
#include "Global.h"
-#include "interface/Point.h"
-#include "interface/Label.h"
+#include "Point.h"
+#include "Label.h"
using namespace ui;
Label::Label(Window* parent_state, std::string labelText):
Component(parent_state),
- LabelText(labelText)
+ text(labelText),
+ textPosition(ui::Point(0, 0)),
+ textVAlign(AlignMiddle),
+ textHAlign(AlignCentre)
{
-
+ TextPosition();
}
Label::Label(Point position, Point size, std::string labelText):
Component(position, size),
- LabelText(labelText)
+ text(labelText),
+ textPosition(ui::Point(0, 0)),
+ textVAlign(AlignMiddle),
+ textHAlign(AlignCentre)
{
-
+ TextPosition();
}
Label::Label(std::string labelText):
Component(),
- LabelText(labelText)
+ text(labelText),
+ textPosition(ui::Point(0, 0)),
+ textVAlign(AlignMiddle),
+ textHAlign(AlignCentre)
{
-
+ TextPosition();
}
Label::~Label()
@@ -32,9 +41,45 @@ Label::~Label()
}
+void Label::TextPosition()
+{
+ //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 *)text.c_str()))/2;
+ break;
+ case AlignRight:
+ textPosition.X = (Size.X-Graphics::textwidth((char *)text.c_str()))-2;
+ break;
+ }
+}
+
+void Label::SetText(std::string text)
+{
+ this->text = text;
+ TextPosition();
+}
void Label::Draw(const Point& screenPos)
{
Graphics * g = Engine::Ref().g;
- g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)LabelText.c_str()))/2, Position.Y+(Size.Y-10)/2, LabelText, 255, 255, 255, 255);
+ g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, text, 255, 255, 255, 255);
}
+