summaryrefslogtreecommitdiff
path: root/src/interface/Label.cpp
blob: 6fc47e201be7941da073eac47c64c0381a133349 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <string>
#include "Config.h"
#include "Global.h"
#include "Point.h"
#include "Label.h"

using namespace ui;

Label::Label(Window* parent_state, std::string labelText):
	Component(parent_state),
	text(labelText),
	textPosition(ui::Point(0, 0)),
	textVAlign(AlignMiddle),
	textHAlign(AlignCentre)
{
	TextPosition();
}

Label::Label(Point position, Point size, std::string labelText):
	Component(position, size),
	text(labelText),
	textPosition(ui::Point(0, 0)),
	textVAlign(AlignMiddle),
	textHAlign(AlignCentre)
{
	TextPosition();
}

Label::Label(std::string labelText):
	Component(),
	text(labelText),
	textPosition(ui::Point(0, 0)),
	textVAlign(AlignMiddle),
	textHAlign(AlignCentre)
{
	TextPosition();
}

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(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, text, 255, 255, 255, 255);
}