-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolvesBar.cpp
More file actions
65 lines (56 loc) · 1.86 KB
/
Copy pathSolvesBar.cpp
File metadata and controls
65 lines (56 loc) · 1.86 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
#include "SolvesBar.h"
SolvesBar::SolvesBar() {
height = NUM_SHOWN_SOLVES + 2;
width = MIN_WIDTH;
barPtr = newwin(height, width, 4, 0);
}
SolvesBar::~SolvesBar() {
delwin(barPtr);
barPtr = nullptr;
}
void SolvesBar::redrawSolves(std::deque<Solve> &solves, unsigned highlightIndex,
int offset) {
Solve toDraw;
unsigned counter = 0, maxSolveLength = 0;
std::string solveString;
unsigned startPos = 0;
if (solves.size() > NUM_SHOWN_SOLVES) {
startPos = solves.size() - NUM_SHOWN_SOLVES - offset;
} else {
// having an offset doesn't make sense if all solves can fit in the
// display
offset = 0;
}
// get maximum solve display length for width
for (unsigned i = startPos; i < solves.size() - offset; i++) {
solveString = solves.at(i).toString();
if (solveString.length() > maxSolveLength) {
maxSolveLength = solveString.length();
}
}
// change width of window if needed
// TODO: this leaves the outline of the previous box if it resizes to get
// smaller. How to fix?
if (maxSolveLength + 4 != width && maxSolveLength + 4 >= MIN_WIDTH) {
width = maxSolveLength + 4;
wresize(barPtr, height, width);
}
wclear(barPtr);
box(barPtr, 0, 0);
wrefresh(barPtr);
for (unsigned i = solves.size() - offset;
i > 0 && counter < NUM_SHOWN_SOLVES; i--) {
// have to traverse deque backwards to get newest solve at top of box
toDraw = solves.at(i - 1);
solveString = toDraw.toString();
if (i - 1 == highlightIndex) {
wattron(barPtr, A_REVERSE);
}
mvwprintw(barPtr, counter + 1, 2, solveString.c_str());
if (i - 1 == highlightIndex) {
wattroff(barPtr, A_REVERSE);
}
counter++;
}
wrefresh(barPtr);
}