-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimerView.js
38 lines (28 loc) · 830 Bytes
/
TimerView.js
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
function TimerView (length) {
this.length = length;
this.percent = 1;
var timerView = this;
var time = 0;
this.timer = setInterval( function() {
time += 50;
var timeSeconds = time / 1000;
timerView.percent = 1 - (timeSeconds / length);
if (timeSeconds >= length) {
clearInterval(timerView.timer);
if (timerView.onComplete) {
timerView.onComplete();
}
}
}, 50);
}
TimerView.prototype = new View();
TimerView.prototype.cancel = function() {
clearInterval(this.timer);
}
TimerView.prototype.drawAtPosition = function(ctx, x, y) {
ctx.fillStyle = 'rgba(0, 0, 0, 1)';
ctx.fillRect(x, y, this.frame.width, this.frame.height);
ctx.fillStyle = 'rgba(0, 225, 0, 1)';
ctx.fillRect(x, y, this.frame.width * this.percent, this.frame.height);
View.prototype.drawAtPosition.call(this, ctx, x, y);
};