forked from devmario/CppTweener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tween.cpp
76 lines (66 loc) · 1.91 KB
/
tween.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
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// tween.cpp
// CppTweener
//
// Created by wonhee jang on 13. 5. 14..
// Copyright (c) 2013년 vanillabreeze. All rights reserved.
//
#include "tween.h"
bool tween_manager::update_animation(std::list<animation>::iterator _it, long _milli_seconds) {
(*_it).tick += _milli_seconds;
(*_it).tween.step((*_it).tick);
if((*_it).tween.tweens.size() == 0) {
return false;
} else {
return true;
}
}
tween_manager::tween_manager() {
}
tween_manager* _local_tween_manager = NULL;
tween_manager* tween_manager::share() {
if(!_local_tween_manager)
_local_tween_manager = new tween_manager();
return _local_tween_manager;
}
void tween_manager::start(std::string _tag, long _time, float* _src, float _dst, short _equation, short _transition, TweenerListener* _listener, short _delay) {
animation _animation = animation();
_animation.tag = _tag;
TweenerParam _param = TweenerParam(_time, _transition, _equation, _delay);
_param.tag = _tag;
if(_src)
_param.addProperty(_src, _dst);
_animation.tween.addTween(_param);
if(_listener)
_animation.tween.addListener(_listener);
list_animation.push_back(_animation);
}
void tween_manager::update(float _tick) {
long _milli_seconds = _tick * 1000;
std::vector<std::list<animation>::iterator> vec_remove;
std::list<animation>::iterator _it = list_animation.begin();
while (_it != list_animation.end()) {
if(!update_animation(_it, _milli_seconds)) {
vec_remove.push_back(_it);
}
_it++;
}
while (!vec_remove.empty()) {
list_animation.remove(*vec_remove.back());
vec_remove.pop_back();
}
}
void tween_manager::stop(std::string _tag) {
std::vector<std::list<animation>::iterator> vec_remove;
std::list<animation>::iterator _it = list_animation.begin();
while (_it != list_animation.end()) {
if((*_it).tag == _tag) {
vec_remove.push_back(_it);
}
_it++;
}
while (!vec_remove.empty()) {
list_animation.remove(*vec_remove.back());
vec_remove.pop_back();
}
}