-
Notifications
You must be signed in to change notification settings - Fork 6
/
TimerView.cpp
54 lines (43 loc) · 726 Bytes
/
TimerView.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
#include "TimerView.h"
#include <String.h>
TimerView::TimerView()
:
BTextView("timer"),
fRunning(false)
{
SetStylable(true);
MakeEditable(false);
MakeSelectable(false);
}
void TimerView::AttachedToWindow()
{
}
void TimerView::Start()
{
fRunning = true;
fStartTime = system_time();
}
bool TimerView::Running()
{
return fRunning;
}
void TimerView::Stop()
{
fRunning = false;
}
int TimerView::Elapsed()
{
return fRunning ? (system_time() - fStartTime) / 1000 / 1000 : 0;
}
void TimerView::Pulse()
{
if (!fRunning)
return;
bigtime_t elapsed = Elapsed();
int mins = elapsed / 60;
int secs = elapsed % 60;
BString str;
str.SetToFormat("%02d:%02d",mins,secs);
Delete(0,TextLength());
Insert(str);
}