-
Notifications
You must be signed in to change notification settings - Fork 0
/
UILabel.cpp
111 lines (89 loc) · 2.36 KB
/
UILabel.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "Advanced2D.h"
namespace Freedom
{
UILabel::UILabel() : UIBase()
{
textcolor = 0xffffffff;
orient = LABEL_LEFT;
linesize = 1;
}
UILabel::~UILabel()
{
delete font;
}
int UILabel::init(Rect &r, std::string text, std::string fonttype, int fontsize)
{
rect = r;
font = new Font( fonttype, fontsize );
this->text = text;
//return the control ID for event tracking
return getID();
}
void UILabel::update()
{
}
void UILabel::draw()
{
//if (linesize > 0)
// shape->drawBox( rect, linesize, bordercolor ); // Shape is from GUIBase
g_engine->SetSpriteIdentity();
int x = (int)rect.left;
int y = (int)rect.top;
//for vertical positioning
int texth = (int)font->getTextHeight(text);
int centery = y + (int)rect.getHeight()/2 - texth/2;
//for horizontal positioning
int textw = font->getTextWidth(text);
int centerx = x + (int)rect.getWidth()/2 - textw/2;
int rightx = x + (int)rect.getWidth() - textw - 2;
switch(orient)
{
case LABEL_LEFT:
font->Print( x+2, centery, text, textcolor );
break;
case LABEL_CENTER:
font->Print( centerx, centery, text, textcolor );
break;
case LABEL_RIGHT:
font->Print( rightx, centery, text, textcolor );
break;
}
}
void UILabel::drawWithBox()
{
if (linesize > 0)
shape->drawBox( rect, linesize, bordercolor ); // Shape is from GUIBase
g_engine->SetSpriteIdentity();
int x = (int)rect.left;
int y = (int)rect.top;
//for vertical positioning
int texth = (int)font->getTextHeight(text);
int centery = y + (int)rect.getHeight()/2 - texth/2;
//for horizontal positioning
int textw = font->getTextWidth(text);
int centerx = x + (int)rect.getWidth()/2 - textw/2;
int rightx = x + (int)rect.getWidth() - textw - 2;
switch(orient)
{
case LABEL_LEFT:
font->Print( x+2, centery, text, textcolor );
break;
case LABEL_CENTER:
font->Print( centerx, centery, text, textcolor );
break;
case LABEL_RIGHT:
font->Print( rightx, centery, text, textcolor );
break;
}
}
/**
By overriding these base virtual methods, we eliminate the base events (if desired)
**/
void UILabel::OnMouseClick(int x,int y,int b)
{
UIBase::OnMouseClick(x, y, b);
//g_engine->message("label clicked");
}
void UILabel::OnMouseMove(int x,int y) {}
void UILabel::OnMouseDrag(int x,int y){}
}; // namespace