-
-
Notifications
You must be signed in to change notification settings - Fork 665
/
layout.c
137 lines (129 loc) · 4.3 KB
/
layout.c
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (C) 2014 Pavol Rusnak <[email protected]>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "layout.h"
#include "oled.h"
void layoutButtonNo(const char *btnNo, const BITMAP *icon) {
int icon_width = 0;
if (icon) {
oledDrawBitmap(1, OLED_HEIGHT - 8, icon);
icon_width = icon->width;
}
oledDrawString(3 + icon_width, OLED_HEIGHT - 8, btnNo, FONT_STANDARD);
oledInvert(0, OLED_HEIGHT - 9,
icon_width + oledStringWidth(btnNo, FONT_STANDARD) + 4,
OLED_HEIGHT - 1);
}
void layoutButtonYes(const char *btnYes, const BITMAP *icon) {
int icon_width = 0;
if (icon) {
oledDrawBitmap(OLED_WIDTH - 8 - 1, OLED_HEIGHT - 8, icon);
icon_width = icon->width;
}
oledDrawStringRight(OLED_WIDTH - icon_width - 3, OLED_HEIGHT - 8, btnYes,
FONT_STANDARD);
oledInvert(
OLED_WIDTH - oledStringWidth(btnYes, FONT_STANDARD) - icon_width - 4,
OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
}
void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes,
const char *desc, const char *line1, const char *line2,
const char *line3, const char *line4, const char *line5,
const char *line6) {
layoutDialogEx(icon, btnNo, btnYes, desc, line1, line2, line3, line4, line5,
line6, FONT_STANDARD);
}
inline void layoutDialogEx(const BITMAP *icon, const char *btnNo,
const char *btnYes, const char *desc,
const char *line1, const char *line2,
const char *line3, const char *line4,
const char *line5, const char *line6, uint8_t font) {
int left = 0;
oledClear();
if (icon) {
oledDrawBitmap(0, 0, icon);
left = icon->width + 4;
}
if (line1) oledDrawString(left, 0 * 9, line1, font);
if (line2) oledDrawString(left, 1 * 9, line2, font);
if (line3) oledDrawString(left, 2 * 9, line3, font);
if (line4) oledDrawString(left, 3 * 9, line4, font);
if (desc) {
oledDrawStringCenter(OLED_WIDTH / 2, OLED_HEIGHT - 2 * 9 - 1, desc,
FONT_STANDARD);
if (btnYes || btnNo) {
oledHLine(OLED_HEIGHT - 21);
}
} else {
if (line5) oledDrawString(left, 4 * 9, line5, font);
if (line6) oledDrawString(left, 5 * 9, line6, font);
if (btnYes || btnNo) {
oledHLine(OLED_HEIGHT - 13);
}
}
if (btnNo) {
layoutButtonNo(btnNo, &bmp_btn_cancel);
}
if (btnYes) {
layoutButtonYes(btnYes, &bmp_btn_confirm);
}
oledRefresh();
}
void layoutProgressUpdate(bool refresh) {
static uint8_t step = 0;
switch (step) {
case 0:
oledDrawBitmap(40, 0, &bmp_gears0);
break;
case 1:
oledDrawBitmap(40, 0, &bmp_gears1);
break;
case 2:
oledDrawBitmap(40, 0, &bmp_gears2);
break;
case 3:
oledDrawBitmap(40, 0, &bmp_gears3);
break;
}
step = (step + 1) % 4;
if (refresh) {
oledRefresh();
}
}
void layoutProgress(const char *desc, int permil) {
oledClear();
layoutProgressUpdate(false);
// progressbar
oledFrame(0, OLED_HEIGHT - 8, OLED_WIDTH - 1, OLED_HEIGHT - 1);
oledBox(1, OLED_HEIGHT - 7, OLED_WIDTH - 2, OLED_HEIGHT - 2, 0);
permil = permil * (OLED_WIDTH - 4) / 1000;
if (permil < 0) {
permil = 0;
}
if (permil > OLED_WIDTH - 4) {
permil = OLED_WIDTH - 4;
}
oledBox(2, OLED_HEIGHT - 6, 1 + permil, OLED_HEIGHT - 3, 1);
// text
oledBox(0, OLED_HEIGHT - 16, OLED_WIDTH - 1, OLED_HEIGHT - 16 + 7, 0);
if (desc) {
oledDrawStringCenter(OLED_WIDTH / 2, OLED_HEIGHT - 16, desc, FONT_STANDARD);
}
oledRefresh();
}