-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewList.cpp
63 lines (47 loc) · 1.3 KB
/
ViewList.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
#include "ViewList.h"
namespace dxco {
ViewList::ViewList(float x, float y, float width, float height) : Container(x, y, width, height) {
this->elementsHeight = 0;
this->distance = 0;
this->yMoved = 0;
cocos2d::CCSize visibleSize =
cocos2d::CCDirector::sharedDirector()->getVisibleSize();
this->visibleHeight = visibleSize.height;
this->loaded = false;
}
void ViewList::addElement(ViewListElement* element) {
if (element) {
element->move(0, this->getHeight() - this->elementsHeight - element->getHeight());
this->elementsHeight += element->getHeight() + this->distance;
this->elements.push_back(element);
this->addChild(element);
}
}
int ViewList::getSize() {
return this->elements.size();
}
void ViewList::move(float deltaY) {
if (elements.size()) {
float move = deltaY;
if (yMoved + deltaY < 0) {
move = 0;
} else if (yMoved + deltaY > (this->elementsHeight - (this->visibleHeight / 2))) {
move = 0;
}
yMoved += move;
for (int i = 0; i < this->elements.size(); i++) {
ViewListElement* element = this->elements[i];
element->move(0, move);
}
}
}
void ViewList::setDistance(float distance) {
this->distance = distance;
}
bool ViewList::isLoaded() {
return this->loaded;
}
bool ViewList::setLoaded(bool loaded) {
this->loaded = loaded;
}
} /* namespace dxco */