YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Menu.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/Gui/Menu.hpp
"
2
#include "
YAPOG/Graphics/Gui/Padding.hpp
"
3
#include "
YAPOG/System/MathHelper.hpp
"
4
#include "
YAPOG/Graphics/Gui/WidgetBorder.hpp
"
5
#include "
YAPOG/Graphics/Gui/WidgetBackground.hpp
"
6
#include "
YAPOG/Graphics/Gui/HorizontalLayout.hpp
"
7
#include "
YAPOG/Graphics/Gui/VerticalLayout.hpp
"
8
#include "
YAPOG/System/Event/Event.hpp
"
9
10
namespace
yap
11
{
12
13
Menu::Menu
(
Type
type,
Padding
ext,
Padding
in,
bool
fixed)
14
: itemz_ ()
15
, currentSelec_ (0)
16
, layout_ (nullptr)
17
, selecBckgrd_ (nullptr)
18
, selecBrdr_ (nullptr)
19
, selecBrdSize_ (16)
20
, isFixed_ (fixed)
21
, type_ (type)
22
, layoutManager_ (nullptr)
23
{
24
if
(type == Type::HORIZONTAL)
25
layout_
=
new
HorizontalLayout
(ext, in, !fixed);
26
else
if
(type == Type::VERTICAL)
27
layout_
=
new
VerticalLayout
(ext, in, !fixed);
28
29
layoutManager_
=
new
PartialLayoutManager
(*
layout_
);
30
layoutManager_
->
SetEnable
(fixed);
31
BaseWidget::AddChild
(*
layout_
);
32
}
33
34
void
Menu::SetFixed
(
bool
state)
35
{
36
isFixed_
= state;
37
}
38
39
bool
Menu::IsFocusable
()
const
40
{
41
return
true
;
42
}
43
44
Menu::~Menu
()
45
{
46
}
47
48
void
Menu::SetSelectedBackground
(
WidgetBackground
& background)
49
{
50
selecBckgrd_
= &background;
51
}
52
53
void
Menu::SetSelectedBorder
(
WidgetBorder
& border)
54
{
55
selecBrdr_
= &border;
56
}
57
58
Vector2
Menu::HandleGetSize
()
const
59
{
60
if
(
isFixed_
)
61
return
GetUserSize
();
62
return
layout_
->
GetSize
() + ((
border_
!=
nullptr
) ?
border_
->
GetSize
() :
Vector2
());
63
}
64
65
void
Menu::SetFormItem
()
66
{
67
MenuItem
* curItem =
itemz_
[
currentSelec_
];
68
69
if
(
selecBckgrd_
!=
nullptr
)
70
curItem->
SetBackground
(*
selecBckgrd_
);
71
if
(
selecBrdr_
!=
nullptr
)
72
curItem->
SetBorder
(*
selecBrdr_
);
73
}
74
75
void
Menu::SetUnformItem
()
76
{
77
MenuItem
* curItem =
itemz_
[
currentSelec_
];
78
curItem->
UnsetBackground
();
79
curItem->
UnsetBorder
();
80
}
81
82
void
Menu::AddChild
(
MenuItem
& child,
LayoutBox::Align
align)
83
{
84
if
(
selecBrdr_
!=
nullptr
)
85
child.
SetBorder
(*
selecBrdr_
);
86
if
(
itemz_
.
Count
() == 0)
87
{
88
itemz_
.
Add
(&child);
89
child.
OnSelected
(child,
EmptyEventArgs
());
90
}
91
else
92
{
93
itemz_
.
Add
(&child);
94
}
95
96
layout_
->
AddChild
(child, align);
97
layoutManager_
->
AddItem
(&child);
98
99
/*
100
if (isFixed_ && type_ == Type::VERTICAL)
101
{
102
if (GetUserSize () != Vector2 (0, 0) && layout_->GetSize ().y > GetUserSize ().y)
103
layout_->RemoveChild (child);
104
}
105
else if (isFixed_ && type_ == Type::HORIZONTAL)
106
if (GetUserSize () != Vector2 (0, 0) && layout_->GetSize ().x > GetUserSize ().x)
107
layout_->RemoveChild (child);
108
*/
109
110
child.
UnsetBorder
();
111
112
SetFormItem
();
113
114
if
(
type_
== Menu::Type::HORIZONTAL)
115
layoutManager_
->
SetSize
(
layout_
->
GetSize
().x);
116
if
(
type_
== Menu::Type::VERTICAL)
117
layoutManager_
->
SetSize
(
layout_
->
GetSize
().y);
118
119
}
120
121
void
Menu::Clear
()
122
{
123
itemz_
.
Clear
();
124
currentSelec_
= 0;
125
layout_
->
Clear
();
126
layoutManager_
->
Clear
();
127
}
128
uint
Menu::GetCurrentSelect
()
const
129
{
130
return
currentSelec_
;
131
}
132
133
void
Menu::HandleDraw
(
IDrawingContext
& context)
134
{
135
//layout_->Draw (context);
136
}
137
138
bool
Menu::HandleOnEvent
(
const
GuiEvent
& guiEvent)
139
{
140
if
(guiEvent.type == sf::Event::KeyPressed)
141
{
142
if
(guiEvent.key.code ==
sf::Keyboard::Up
)
143
{
144
145
if
(
currentSelec_
<= 0)
146
return
true
;
147
148
SetUnformItem
();
149
currentSelec_
--;
150
layoutManager_
->
SetCurrentSel
(
currentSelec_
);
151
SetFormItem
();
152
itemz_
[
currentSelec_
]->OnSelected (*
itemz_
[
currentSelec_
],
EmptyEventArgs
());
153
HandleItemSelected
();
154
return
true
;
155
}
156
if
(guiEvent.key.code ==
sf::Keyboard::Down
)
157
{
158
if
(
itemz_
.
Count
() == 0 ||
currentSelec_
>=
itemz_
.
Count
() - 1)
159
return
true
;
160
161
SetUnformItem
();
162
currentSelec_
++;
163
layoutManager_
->
SetCurrentSel
(
currentSelec_
);
164
SetFormItem
();
165
itemz_
[
currentSelec_
]->OnSelected (*
itemz_
[
currentSelec_
],
EmptyEventArgs
());
166
HandleItemSelected
();
167
return
true
;
168
}
169
170
if
(guiEvent.key.code == sf::Keyboard::Return)
171
{
172
itemz_
[
currentSelec_
]->Do ();
173
itemz_
[
currentSelec_
]->OnActivated (*
itemz_
[
currentSelec_
],
EmptyEventArgs
());
174
HandleItemActivated
();
175
return
true
;
176
}
177
178
/*
179
if (guiEvent.key.code == sf::Keyboard::Escape)
180
{
181
OnDesactivated (*this, EmptyEventArgs ());
182
return true;
183
}
184
*/
185
186
// Menu captures every key pressed
187
//return true;
188
}
189
190
// Menu captures every key released
191
if
(guiEvent.type == sf::Event::KeyReleased)
192
return
true
;
193
194
return
false
;
195
}
196
197
void
Menu::HandleShow
(
bool
isVisible)
198
{
199
}
200
201
void
Menu::HandleMove
(
const
Vector2
& offset)
202
{
203
}
204
205
void
Menu::HandleScale
(
const
Vector2
& factor)
206
{
207
}
208
209
void
Menu::HandleUpdate
(
const
Time
& dt)
210
{
211
}
212
213
void
Menu::HandleChangeColor
(
const
sf::Color& color)
214
{
215
}
216
217
void
Menu::HandleItemActivated
()
218
{
219
}
220
221
void
Menu::HandleItemSelected
()
222
{
223
}
224
225
}
//namespace yap
YAPOG
src
YAPOG
Graphics
Gui
Menu.cpp
Generated on Mon Sep 17 2012 22:24:26 for YAPOG by
1.8.1.1