-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.cpp
78 lines (62 loc) · 2.4 KB
/
View.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "View.h"
namespace minimal {
View::View(const char* name) {
name_ = (char *)malloc(sizeof(char) * (strlen(name) + 1));
strcpy(name_, name);
}
void View::draw() {
uint8_t offset = (AD12864SPI::COLUMN_SIZE - strlen(name_) * Font::GLYPH_WIDTH) / 2;
uint8_t buffer[AD12864SPI::COLUMN_SIZE] = {0};
Font::getData(name_, buffer + offset, AD12864SPI::COLUMN_SIZE - offset, true);
AD12864SPI::write(0, 0, buffer, AD12864SPI::COLUMN_SIZE);
for (uint8_t i = 0; i < AD12864SPI::COLUMN_SIZE; ++i) buffer[i] = 128;
Font::getData(name_, buffer + offset, AD12864SPI::COLUMN_SIZE - offset, false);
AD12864SPI::write(1, 0, buffer, AD12864SPI::COLUMN_SIZE);
}
void View::forward() {
// do nothing.
}
void View::backward() {
// do nothing.
}
bool View::click() {
return true;
}
void View::drawOkButton(bool focused) {
uint8_t buffer[44] = {0};
uint8_t bufferSize = sizeof(buffer) / sizeof(uint8_t);
Font::getData("OK", buffer + bufferSize / 2 - Font::GLYPH_WIDTH, Font::GLYPH_WIDTH * 2, true);
for (int8_t i = 0; i < bufferSize - 0; ++i)
buffer[i] = focused ? ~buffer[i] : buffer[i] | 1;
buffer[0] = 254;
buffer[bufferSize - 1] = 254;
AD12864SPI::write(6, AD12864SPI::COLUMN_SIZE / 2 + 8, buffer, bufferSize);
memset(buffer, 0, sizeof(buffer));
Font::getData("OK", buffer + bufferSize / 2 - Font::GLYPH_WIDTH, Font::GLYPH_WIDTH * 2, false);
for (int8_t i = 0; i < bufferSize - 0; ++i)
buffer[i] = focused ? ~buffer[i] : buffer[i] | 128;
buffer[0] = 127;
buffer[bufferSize - 1] = 127;
AD12864SPI::write(7, AD12864SPI::COLUMN_SIZE / 2 + 8, buffer, bufferSize);
}
void View::drawCancelButton(bool focused) {
uint8_t buffer[56] = {0};
uint8_t bufferSize = sizeof(buffer) / sizeof(uint8_t);
Font::getData("Cancel", buffer + bufferSize / 2 - Font::GLYPH_WIDTH * 3, Font::GLYPH_WIDTH * 6, true);
for (int8_t i = 0; i < bufferSize; ++i)
buffer[i] = focused ? ~buffer[i] : buffer[i] | 1;
buffer[0] = 254;
buffer[bufferSize - 1] = 254;
AD12864SPI::write(6, 12, buffer, bufferSize);
memset(buffer, 0, sizeof(buffer));
Font::getData("Cancel", buffer + bufferSize / 2 - Font::GLYPH_WIDTH * 3, Font::GLYPH_WIDTH * 6, false);
for (int8_t i = 0; i < bufferSize; ++i)
buffer[i] = focused ? ~buffer[i] : buffer[i] | 128;
buffer[0] = 127;
buffer[bufferSize - 1] = 127;
AD12864SPI::write(7, 12, buffer, bufferSize);
}
const char* View::getName() const {
return name_;
}
}