-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofxTimer.cpp
51 lines (42 loc) · 1.17 KB
/
ofxTimer.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
#include "ofxTimer.h"
ofEvent<ofVec2f> ofxTimer::timerFin = ofEvent<ofVec2f>();
ofxTimer::ofxTimer() {
startTime = ofGetElapsedTimeMillis();
endTime = ofGetElapsedTimeMillis() +100;
TimerReached = true;
mappedTime = 255;
}
//--------------------------
ofxTimer::~ofxTimer() {
startTime = 0;
endTime = 0;
TimerReached = true;
mappedTime = 255;
}
void ofxTimer::timer(float start,bool fade,bool _sel){
sel = _sel;
startTime = ofGetElapsedTimeMillis(); // get the start time
endTime = start;
TimerReached = false;
fadeUpDown = fade;
}
float ofxTimer::update(){
if(!TimerReached){
float timerZ = ofGetElapsedTimeMillis() - startTime;
if(timerZ >= endTime && !TimerReached) {
TimerReached = true;
if(sel){
ofVec2f temp = ofVec2f(0,0);
ofNotifyEvent(timerFin, temp);
sel = false;
}
}
if(fadeUpDown){
mappedTime = ofMap(ofGetElapsedTimeMillis(), startTime, startTime + endTime , 255, 0,true);
}
else{
mappedTime = ofMap(ofGetElapsedTimeMillis(), startTime, startTime + endTime , 0, 255,true);
}
}
return mappedTime;
}