-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCSnapPage.cpp
More file actions
92 lines (75 loc) · 1.94 KB
/
TCSnapPage.cpp
File metadata and controls
92 lines (75 loc) · 1.94 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "TCSnapPage.h"
#include <float.h>
#define SLIDE_TOUCH_TH 5
using namespace Touched;
TCSnapPage::TCSnapPage() : TCPage(), TweenerListener() {
current_index = 0;
}
TCSnapPage::~TCSnapPage() {
}
void TCSnapPage::CalculateMovement() {
if(touch_address) {
position += force;
force = 0;
} else {
//tween
milli_seconds += 1.0/60.0 * 1000;
tweener.step(milli_seconds);
}
}
void TCSnapPage::GoPage(int _index, short ptransition) {
if(_index != current_index) {
current_index = _index;
}
if(current_index < 0)
current_index = 0;
if(current_index > GetPageLength() - 1)
current_index = GetPageLength() - 1;
ChangedIndex(current_index);
float _size = 0.0;
for(int i = 0; i < current_index; i++) {
_size += GetPageSize(0);
}
_size -= GetPageSize(current_index) * 0.5;
_size += GetSize() * 0.5;
milli_seconds = 0;
tweener = Tweener();
param = TweenerParam(600, ptransition, EASE_OUT);
param.addProperty(&position, -_size);
tweener.addTween(param);
}
void TCSnapPage::TouchEndOrCancel(void* _address, float _position) {
if(touch_address == _address) {
touch_address = NULL;
int nextIdx = current_index;
if(fabsf(force_delta) > SLIDE_TOUCH_TH) {
if(force_delta < 0) {
if(nextIdx < GetPageLength() - 1)
nextIdx++;
} else {
if(nextIdx > 0)
nextIdx--;
}
GoPage(nextIdx, QUART);
} else {
std::list<Page*>::iterator _it = page_list.begin();
float _half = GetSize() * 0.5;
while(page_list.end() != _it) {
Page* _page = *_it;
if(_half > _page->position && _half < _page->position + _page->size) {
nextIdx = _page->number;
break;
}
_it++;
}
GoPage(nextIdx, QUART);
}
}
}
void TCSnapPage::onStart(TweenerParam& param) {
}
void TCSnapPage::onStep(TweenerParam& param) {
}
void TCSnapPage::onComplete(TweenerParam& param) {
position = param.properties[0].finalValue;
}