YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
PartialLayoutManager.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/Gui/LayoutBox.hpp
"
2
#include "
YAPOG/Graphics/Gui/PartialLayoutManager.hpp
"
3
#include "
YAPOG/System/MathHelper.hpp
"
4
5
namespace
yap
6
{
7
8
PartialLayoutManager::PartialLayoutManager
(
LayoutBox
& layout)
9
: cursorCurSel_ (0)
10
, itemCount_ (0)
11
, size_ (0)
12
, layout_ (&layout)
13
, stock_ ()
14
, itemz_ ()
15
, isEnable_ (true)
16
, widthItem_ (0)
17
{
18
}
19
20
PartialLayoutManager::~PartialLayoutManager
()
21
{
22
}
23
24
void
PartialLayoutManager::SetEnable
(
bool
state)
25
{
26
isEnable_
= state;
27
}
28
void
PartialLayoutManager::Refresh
()
29
{
30
if
(
isEnable_
)
31
{
32
uint
countItem = 0;
33
34
layout_
->
Clear
();
35
uint
itemBeforeCount = (
itemCount_
- 1) / 2;
36
uint
itemAfterCount =
itemCount_
- itemBeforeCount - 1;
37
int
endListHandle = itemAfterCount - (
itemz_
.
Count
() - 1 -
cursorCurSel_
) +1;
38
endListHandle = (endListHandle >= 0) ? endListHandle : 0;
39
uint
it = MathHelper::Clamp<int>(
cursorCurSel_
- itemBeforeCount - endListHandle, 0,
cursorCurSel_
);
40
41
while
(it <
itemz_
.
Count
() && it <
cursorCurSel_
)
42
{
43
layout_
->
AddChild
(*
itemz_
[it], yap::LayoutBox::Align::LEFT);
44
it++;
45
countItem++;
46
}
47
48
it =
cursorCurSel_
;
49
50
while
(it <
itemz_
.
Count
() && countItem <=
itemCount_
)
51
{
52
layout_
->
AddChild
(*
itemz_
[it], yap::LayoutBox::Align::LEFT);
53
it++;
54
countItem++;
55
}
56
}
57
}
58
59
void
PartialLayoutManager::AddItem
(
IWidget
* items)
60
{
61
itemz_
.
Add
(items);
62
}
63
64
void
PartialLayoutManager::SetCurrentSel
(
uint
curr)
65
{
66
cursorCurSel_
= curr;
67
Refresh
();
68
}
69
void
PartialLayoutManager::SetSize
(
float
size)
70
{
71
widthItem_
=
layout_
->
GetWidthItem
() + (
layout_
->
GetInnerPadding
().
top
* 2);
72
size_
= size;
73
itemCount_
= size /
widthItem_
;
74
Refresh
();
75
}
76
uint
PartialLayoutManager::GetSize
()
const
77
{
78
return
size_
;
79
}
80
81
void
PartialLayoutManager::Clear
()
82
{
83
itemz_
.
Clear
();
84
}
85
86
}
//namespace yap
YAPOG
src
YAPOG
Graphics
Gui
PartialLayoutManager.cpp
Generated on Mon Sep 17 2012 22:24:26 for YAPOG by
1.8.1.1