YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
WidgetBackground.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/Gui/WidgetBackground.hpp
"
2
#include "
YAPOG/Graphics/IDrawingContext.hpp
"
3
4
namespace
yap
5
{
6
WidgetBackground::WidgetBackground
()
7
: background_ ()
8
, tm_ (nullptr)
9
, resize_ (true)
10
, isInit (false)
11
, fixed_ (false)
12
{
13
}
14
15
WidgetBackground::WidgetBackground
(
String
file,
bool
resize)
16
: background_ ()
17
, tm_ (nullptr)
18
, resize_ (resize)
19
, isInit (false)
20
, fixed_ (false)
21
{
22
background_
.
LoadFromFile
(file);
23
}
24
25
bool
WidgetBackground::IsFocusable
()
const
26
{
27
return
false
;
28
}
29
30
Vector2
WidgetBackground::HandleGetSize
()
const
31
{
32
return
background_
.
GetSize
();
33
}
34
void
WidgetBackground::SetFixed
(
bool
state)
35
{
36
fixed_
= state;
37
}
38
39
40
WidgetBackground::~WidgetBackground
()
41
{
42
}
43
44
void
WidgetBackground::HandleDraw
(
IDrawingContext
& context)
45
{
46
if
(
isInit
)
47
{
48
if
(
resize_
)
49
background_
.
Draw
(context);
50
else
51
tm_
->
Draw
(context);
52
}
53
}
54
55
void
WidgetBackground::HandleShow
(
bool
isVisible)
56
{
57
}
58
59
void
WidgetBackground::HandleMove
(
const
Vector2
& offset)
60
{
61
if
(
isInit
)
62
{
63
if
(
resize_
)
64
background_
.
Move
(offset);
65
else
66
tm_
->
Move
(offset);
67
}
68
}
69
70
void
WidgetBackground::HandleScale
(
const
Vector2
& factor)
71
{
72
Vector2
base =
background_
.
GetSize
();
73
Vector2
neo (base.x * factor.x, base.y * factor.y);
74
75
if
(
isInit
)
76
{
77
if
(
resize_
)
78
background_
.
SetSize
(neo);
79
else
80
tm_
->
SetSize
(neo);
81
}
82
}
83
84
void
WidgetBackground::HandleUpdate
(
const
Time
& dt)
85
{
86
}
87
88
void
WidgetBackground::HandleChangeColor
(
const
sf::Color& color)
89
{
90
if
(
isInit
)
91
{
92
if
(
resize_
)
93
background_
.
ChangeColor
(color);
94
else
95
tm_
->
ChangeColor
(color);
96
}
97
}
98
99
bool
WidgetBackground::GetFixed
()
const
100
{
101
return
fixed_
;
102
}
103
104
const
Texture
&
WidgetBackground::GetBackground
()
const
105
{
106
return
background_
;
107
}
108
109
void
WidgetBackground::SetBackground
(
Vector2
size)
110
{
111
background_
.
SetPosition
(
GetPosition
());
112
if
(
resize_
)
113
background_
.
SetSize
(size);
114
else
115
{
116
tm_
=
new
TextureManager
(
background_
, size.x, size.y);
117
tm_
->
SetPosition
(
GetPosition
());
118
tm_
->
Init
();
119
}
120
OnBackgroundSet
(*
this
,
EventArgsTexture
(
background_
));
121
isInit
=
true
;
122
}
123
124
void
WidgetBackground::SetBackground
(
String
file
125
,
uint
width
126
,
uint
height
127
,
bool
resize)
128
{
129
resize_
= resize;
130
background_
.
LoadFromFile
(file);
131
background_
.
SetPosition
(
GetPosition
());
132
if
(resize)
133
background_
.
SetSize
(
Vector2
(width, height));
134
else
135
{
136
tm_
=
new
TextureManager
(
background_
, width, height);
137
tm_
->
SetPosition
(
GetPosition
());
138
tm_
->
Init
();
139
}
140
OnBackgroundSet
(*
this
,
EventArgsTexture
(
background_
));
141
isInit
=
true
;
142
}
143
}
//namespace yap
YAPOG
src
YAPOG
Graphics
Gui
WidgetBackground.cpp
Generated on Mon Sep 17 2012 22:24:26 for YAPOG by
1.8.1.1