-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.cpp
More file actions
332 lines (315 loc) · 8.31 KB
/
Copy pathScreen.cpp
File metadata and controls
332 lines (315 loc) · 8.31 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
* This file is part of the Eclipse2024 project. It is subject to the GPLv3
* license terms in the LICENSE file found in the top-level directory of this
* distribution and at
* https://github.com/jjackowski/eclipse2024/blob/master/LICENSE.
* No part of the Eclipse2024 project, including this file, may be copied,
* modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*
* Copyright (C) 2024 Jeff Jackowski
*/
#include <duds/ui/graphics/BppFontPool.hpp>
#include "Screen.hpp"
extern duds::ui::graphics::BppFontPool FontPool;
Screen::Screen(
const duds::ui::graphics::BppImageArchiveSptr &iconArc,
const duds::ui::graphics::ImageDimensions &dim
) :
/* disp(d),*/ dateP(DatePanel::make()), timeP(TimePanel::make()),
titleP(TextPanel::make(FontPool.getStringCache("Title"))),
infoP(TextPanel::make(FontPool.getStringCache("Text"))),
warnP(ImagePanel::make(iconArc->get("Warning"))),
sepP(ImagePanel::make(iconArc->get("Separator"))),
pinP(ImagePanel::make(iconArc->get("Pin"))),
menuP(ImagePanel::make())
{
pgl.renderFill(dim);
pgl.add(dateP, dateP->suggestedLayout(), PanelDatePriority);
pgl.add(timeP, timeP->suggestedLayout(), PanelTimePriority);
pgl.add(warnP, duds::ui::graphics::GridLayoutConfig {
{ // sizes
{ // a size-step
warnP->image()->dimensions(),
{
15, 0
}
}
},
duds::ui::graphics::GridLayoutConfig::PanelHidden
}, PanelWarningPriority);
pgl.add(pinP, duds::ui::graphics::GridLayoutConfig {
{ // sizes
{ // a size-step
pinP->image()->dimensions(),
{
14, 0
}
}
},
duds::ui::graphics::GridLayoutConfig::PanelHidden
}, PanelPinPriority);
pgl.add(menuP, duds::ui::graphics::GridLayoutConfig {
{ // sizes
{ // a size-step
{
dim.w, dim.h - 8
},
{
0, 1
}
}
},
duds::ui::graphics::GridLayoutConfig::PanelHidden
}, PanelMenuPriority);
//pgl.panelConfig(PanelWarningPriority).hide();
// start with title layout
duds::ui::graphics::GridLayoutConfig titleGlc = {
{
{
{ // minimum dimensions
8 * 8, 8
},
{ // grid location
0, 0
}
}
},
// flags (default)
duds::ui::graphics::GridLayoutConfig::PanelHidden |
duds::ui::graphics::GridLayoutConfig::PanelWidthExpand
};
pgl.add(titleP, titleGlc, PanelTitlePriority);
// text spots, 4 columns, 3 rows
int pri = PanelTextC0R0Priority;
for (int c = 0; c < 4; ++c) {
for (int r = 0; r < 3; ++r) {
textP[c][r] = TextPanel::make(FontPool.getStringCache("Text"));
// columns 0 & 2 for titles; will have at least 3 chars & expand
// columns 1 & 3 for numbers up to 5 chars; has space for separation
duds::ui::graphics::GridLayoutConfig textGlc = {
{
{
{ // minimum dimensions
(c & 1) ? ((c > 2) ? (5 * 8) : (9 * 8)) : (3 * 8 + 4), 8
},
{ // grid location
(c > 1) ? (c + 1) : c, r + 1
}
}
},
// flags (default)
duds::ui::graphics::GridLayoutConfig::PanelHidden |
((c & 1) ?
duds::ui::graphics::GridLayoutConfig::PanelJustifyRight :
(
duds::ui::graphics::GridLayoutConfig::PanelJustifyLeft |
duds::ui::graphics::GridLayoutConfig::PanelWidthExpand
)
)
};
pgl.add(textP[c][r], textGlc, pri++);
}
}
// text spacers
for (int r = 0; r < 3; ++r) {
pgl.add(
sepP,
{
{
{
{ // minimum dimensions
6, 8
},
{ // grid location
2, r + 1
}
}
},
duds::ui::graphics::GridLayoutConfig::PanelHidden |
duds::ui::graphics::GridLayoutConfig::PanelCenter
},
PanelSpacerR0Priority + r
);
}
// end with info message layout
duds::ui::graphics::GridLayoutConfig infoGlc = {
{
{
{ // minimum dimensions
dim.w, 8
},
{ // grid location
0, 4
},
}
},
// flags (default)
duds::ui::graphics::GridLayoutConfig::PanelHidden |
duds::ui::graphics::GridLayoutConfig::PanelCenter
};
pgl.add(infoP, infoGlc, PanelInfoMsgPriority);
pgl.layout();
}
void Screen::render(
duds::ui::graphics::BppImage &image,
const duds::data::Measurement::TimeSample &time
) {
if (doLayout) {
// check for need to expand or collapse text fields
for (int r = 0; r < 3; ++r) {
if (pgl.panelConfig(PanelTextC0R0Priority + r + 2 * 3).flags &
duds::ui::graphics::GridLayoutConfig::PanelHidden
) {
// expand text field in second column
pgl.panelConfig(PanelTextC0R0Priority + r + 1 * 3).
sizes[0].minDim.w = 9 * 8;
} else {
// collapse field in second column
pgl.panelConfig(PanelTextC0R0Priority + r + 1 * 3).
sizes[0].minDim.w = 5 * 8;
}
}
pgl.layout();
doLayout = false;
}
image.clearImage();
dateP->updateTime(time);
timeP->updateTime(time);
pgl.render(image);
}
bool Screen::changeLayoutFlags(
int pri,
duds::ui::graphics::GridLayoutConfig::Flags value,
duds::ui::graphics::GridLayoutConfig::Flags mask
) {
duds::ui::graphics::GridLayoutConfig &glc = pgl.panelConfig(pri);
duds::ui::graphics::GridLayoutConfig::Flags old = glc.flags;
glc.flags.setMasked(value, mask);
if (old == glc.flags) {
return false;
} else {
doLayout = true;
return true;
}
}
void Screen::largeTime(bool allow) {
duds::ui::graphics::GridLayoutConfig &glc = pgl.panelConfig(PanelTimePriority);
for (auto &step : glc.sizes) {
if (step.loc == duds::ui::graphics::GridLocation(1, 1)) {
duds::ui::graphics::GridLayoutConfig::Flags old = step.flags;
step.flags.setMasked(
allow ?
duds::ui::graphics::GridLayoutConfig::PanelShown :
duds::ui::graphics::GridLayoutConfig::PanelHidden,
duds::ui::graphics::GridLayoutConfig::PanelHidden
);
if (old != step.flags) {
doLayout = true;
}
}
}
}
void Screen::showTitle(const std::string &t) {
titleP->text(t);
changeLayoutFlags(
PanelTitlePriority,
duds::ui::graphics::GridLayoutConfig::PanelShown,
duds::ui::graphics::GridLayoutConfig::PanelHidden
);
}
void Screen::hideTitle() {
//pgl.panelConfig(PanelTitlePriority).hide();
changeLayoutFlags(
PanelTitlePriority,
duds::ui::graphics::GridLayoutConfig::PanelHidden,
duds::ui::graphics::GridLayoutConfig::PanelHidden
);
}
duds::ui::graphics::ImageDimensions Screen::titleSize() const {
return pgl.layoutDimensions(PanelTitlePriority);
}
void Screen::showInfoMsg(const std::string &m) {
infoP->text(m);
if (
changeLayoutFlags(
PanelInfoMsgPriority,
duds::ui::graphics::GridLayoutConfig::PanelShown,
duds::ui::graphics::GridLayoutConfig::PanelHidden
)
) {
pgl.panelConfig(PanelWarningPriority).show();
}
}
void Screen::hideInfoMsg() {
if (
changeLayoutFlags(
PanelInfoMsgPriority,
duds::ui::graphics::GridLayoutConfig::PanelHidden,
duds::ui::graphics::GridLayoutConfig::PanelHidden
)
) {
pgl.panelConfig(PanelWarningPriority).hide();
}
}
void Screen::showText(const std::string &t, int c, int r) {
assert((c >= 0) && (c < 4) && (r >= 0) && (r < 3));
textP[c][r]->text(t);
if (
changeLayoutFlags(
PanelTextC0R0Priority + r + c * 3,
duds::ui::graphics::GridLayoutConfig::PanelShown,
duds::ui::graphics::GridLayoutConfig::PanelHidden
) && (c > 1)
) {
pgl.panelConfig(PanelSpacerR0Priority + r).show();
}
}
void Screen::hideText(int c, int r) {
assert((c >= 0) && (c < 4) && (r >= 0) && (r < 3));
if (
changeLayoutFlags(
PanelTextC0R0Priority + r + c * 3,
duds::ui::graphics::GridLayoutConfig::PanelHidden,
duds::ui::graphics::GridLayoutConfig::PanelHidden
) && (c > 1)
) {
pgl.panelConfig(PanelSpacerR0Priority + r).hide();
}
}
// hides all text
void Screen::hideText() {
for (int pri = PanelSpacerR0Priority; pri < PanelTextC3R2Priority + 1; ++pri) {
pgl.panelConfig(pri).hide();
}
doLayout = false;
}
void Screen::showPin() {
changeLayoutFlags(
PanelPinPriority,
duds::ui::graphics::GridLayoutConfig::PanelShown,
duds::ui::graphics::GridLayoutConfig::PanelHidden
);
}
void Screen::hidePin() {
changeLayoutFlags(
PanelPinPriority,
duds::ui::graphics::GridLayoutConfig::PanelHidden,
duds::ui::graphics::GridLayoutConfig::PanelHidden
);
}
void Screen::showMenu(const duds::ui::graphics::ConstBppImageSptr &img) {
menuP->image(img);
changeLayoutFlags(
PanelMenuPriority,
duds::ui::graphics::GridLayoutConfig::PanelShown,
duds::ui::graphics::GridLayoutConfig::PanelHidden
);
}
void Screen::hideMenu() {
changeLayoutFlags(
PanelMenuPriority,
duds::ui::graphics::GridLayoutConfig::PanelHidden,
duds::ui::graphics::GridLayoutConfig::PanelHidden
);
}