-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerBox.cpp
More file actions
69 lines (59 loc) · 2.05 KB
/
Copy pathTimerBox.cpp
File metadata and controls
69 lines (59 loc) · 2.05 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
#include "TimerBox.h"
TimerBox::TimerBox() {
int termWidth, termHeight;
getmaxyx(stdscr, termHeight, termWidth);
boxPtr = newwin(boxHeight, boxWidth, (termHeight - boxHeight) / 2,
(termWidth - boxWidth) / 2);
wrefresh(boxPtr);
}
TimerBox::~TimerBox() {
delwin(boxPtr);
boxPtr = nullptr;
}
void TimerBox::startSolveTime() {
solveStart = std::chrono::steady_clock::now();
wmove(boxPtr, 0, 0);
wclrtoeol(boxPtr);
mvwprintw(boxPtr, 0, (boxWidth - placeholder.length()) / 2,
placeholder.c_str());
wrefresh(boxPtr);
}
double TimerBox::endSolveTime() {
std::chrono::time_point<std::chrono::steady_clock> solveEnd =
std::chrono::steady_clock::now();
std::chrono::duration<double> rawSolveTime = solveEnd - solveStart;
return rawSolveTime.count();
}
void TimerBox::updateSolveDisplay(Solve newSolve, double shortAvg,
double longAvg, unsigned numShort,
unsigned numLong) {
std::string niceSolveTime = newSolve.toString();
std::string niceShortAvg;
std::string niceLongAvg;
if (shortAvg == 0) {
niceShortAvg = "-";
} else if (shortAvg == DNF_TIME_VALUE) {
niceShortAvg = "DNF";
} else {
niceShortAvg = Solve::timeToString(shortAvg);
}
if (longAvg == 0) {
niceLongAvg = "-";
} else if (longAvg == DNF_TIME_VALUE) {
niceLongAvg = "DNF";
} else {
niceLongAvg = Solve::timeToString(longAvg);
}
std::string shortAvgString =
"avg" + std::to_string(numShort) + ": " + niceShortAvg;
std::string longAvgString =
"avg" + std::to_string(numLong) + ": " + niceLongAvg;
wclear(boxPtr);
mvwprintw(boxPtr, 0, (boxWidth - niceSolveTime.length()) / 2,
niceSolveTime.c_str());
mvwprintw(boxPtr, 2, (boxWidth - shortAvgString.length()) / 2,
shortAvgString.c_str());
mvwprintw(boxPtr, 3, (boxWidth - longAvgString.length()) / 2,
longAvgString.c_str());
wrefresh(boxPtr);
}