YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Label.cpp
Go to the documentation of this file.
1
#include <SFML/Graphics/Text.hpp>
2
3
#include "
YAPOG/Graphics/Gui/Label.hpp
"
4
#include "
YAPOG/Graphics/IDrawingContext.hpp
"
5
#include "
YAPOG/Graphics/Gui/Padding.hpp
"
6
#include "
YAPOG/Graphics/Gui/WidgetBorder.hpp
"
7
#include "
YAPOG/Graphics/Gui/WidgetBackground.hpp
"
8
#include "
YAPOG/Content/ContentManager.hpp
"
9
10
namespace
yap
11
{
12
const
String
Label::DEFAULT_FONT
=
"pkmnemn.ttf"
;
13
14
Label::Label
()
15
: textContent_ ()
16
, drawableText_ ()
17
, isPosSet_ (false)
18
{
19
drawableText_
.setFont
20
(
ContentManager::Instance
().LoadFont (
DEFAULT_FONT
));
21
drawableText_
.setColor (
userColor_
);
22
}
23
24
Label::Label
(
String
content)
25
: textContent_ (content)
26
, drawableText_ (content)
27
, isPosSet_ (false)
28
{
29
/*drawableText_.setPosition (Vector2 (GetPosition ().x + padding_.left,
30
GetPosition ().y + padding_.top));*/
31
drawableText_
.setColor (
userColor_
);
32
drawableText_
.setPosition (
GetPosition
().x,
33
GetPosition
().y);
34
35
isPosSet_
=
true
;
36
37
drawableText_
.setFont
38
(
ContentManager::Instance
().LoadFont (
DEFAULT_FONT
));
39
}
40
41
Label::~Label
()
42
{
43
}
44
bool
Label::IsFocusable
()
const
45
{
46
return
false
;
47
}
48
49
float
Label::GetCharWidth
()
const
50
{
51
return
drawableText_
.getCharacterSize () / 1.5;
52
}
53
54
Vector2
Label::CharPos
(
uint
pos)
const
55
{
56
return
drawableText_
.findCharacterPos (pos);
57
}
58
59
void
Label::Refresh
()
60
{
61
drawableText_
.setPosition (
62
GetPosition
().x +
padding_
.
left
,
63
GetPosition
().y +
padding_
.
top
);
64
isPosSet_
=
false
;
65
}
66
67
void
Label::SetDefaultColor
(
const
sf::Color& color)
68
{
69
if
(!
isChangeColorCall_
)
70
drawableText_
.setColor (color);
71
}
72
uint
Label::Length
()
const
73
{
74
return
textContent_
.length ();
75
}
76
77
uint
Label::GetCharHeight
()
const
78
{
79
return
drawableText_
.getCharacterSize ();
80
}
81
82
Vector2
Label::HandleGetSize
()
const
83
{
84
if
(
userSize_
==
Vector2
(0, 0))
85
return
Vector2
(
padding_
.
left
86
+
drawableText_
.getGlobalBounds ().width
87
+
padding_
.
right
,
88
padding_
.
top
89
+
/*drawableText_.getGlobalBounds ().height*/
drawableText_
.getCharacterSize ()
90
+
padding_
.
bottom
)
91
+ ((
border_
!=
nullptr
) ?
Vector2
(
border_
->
GetWidth
()
92
* 2,
border_
->
GetWidth
() * 2) :
Vector2
());
93
else
94
return
GetUserSize
();
95
}
96
97
void
Label::HandleDraw
(
IDrawingContext
& context)
98
{
99
if
(
isVisible_
)
100
context.
Draw
(
drawableText_
);
101
}
102
103
void
Label::HandleShow
(
bool
isVisible)
104
{
105
}
106
107
void
Label::HandleMove
(
const
Vector2
& offset)
108
{
109
drawableText_
.move (offset);
110
//drawableText_.setPosition (GetPosition() + offset);
111
}
112
113
void
Label::SetTextSize
(
uint
size)
114
{
115
drawableText_
.setCharacterSize (size);
116
}
117
void
Label::HandleScale
(
const
Vector2
& factor)
118
{
119
drawableText_
.setScale (factor);
120
}
121
122
void
Label::HandleUpdate
(
const
Time
& dt)
123
{
124
}
125
126
void
Label::HandleChangeColor
(
const
sf::Color& color)
127
{
128
drawableText_
.setColor (color);
129
}
130
131
String
Label::GetText
()
const
132
{
133
return
textContent_
;
134
}
135
136
void
Label::SetBackground
(
WidgetBackground
& background)
137
{
138
background_
= &background;
139
background_
->
SetPosition
(
GetPosition
()
/* + Vector2 (0,
140
drawableText_.getGlobalBounds ().height
141
- drawableText_.getCharacterSize ())*/
);
142
background_
->
SetBackground
(
GetSize
());
143
}
144
145
void
Label::SetText
(
const
String
& content)
146
{
147
if
(content ==
textContent_
)
148
return
;
149
150
if
(!
isChangeColorCall_
)
151
drawableText_
.setColor (
userColor_
);
152
textContent_
= content;
153
drawableText_
.setString (content);
154
/*drawableText_.setPosition (Vector2 (GetPosition ().x + padding_.left,
155
GetPosition ().y + padding_.top));*/
156
157
if
(
isPosSet_
)
158
{
159
drawableText_
.setPosition (
160
GetPosition
().x +
padding_
.
left
,
161
GetPosition
().y +
padding_
.
top
);
162
isPosSet_
=
false
;
163
}
164
165
OnTextChanged
(*
this
,
EventArgsString
(content));
166
}
167
}
// namespace yap
YAPOG
src
YAPOG
Graphics
Gui
Label.cpp
Generated on Mon Sep 17 2012 22:24:26 for YAPOG by
1.8.1.1