-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_help.h
123 lines (101 loc) · 4.73 KB
/
view_help.h
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
#pragma once // Please format this file with clang before check-in to GitHub
/*
File: view_help.h
Software: Barry Hansen, K7BWH, barry@k7bwh.com, Seattle, WA
Hardware: John Vanderbeck, KM7O, Seattle, WA
Purpose: This is a brief screen displayed at startup to
remind the user about the controls on the main
screen. They are not outlined or shown and you
will need to simply remember where they are.
+-Hint:-------+-----------------------------+
| | |
| Settings | Tap for next view |
| | |
|-------------+-----------------------------|
| | |
| Reboot | Tap to change brightness |
| | |
+-------------+-----------------------------+
*/
#include <Adafruit_ILI9341.h> // TFT color display library
#include "constants.h" // Griduino constants and colors
#include "logger.h" // conditional printing to Serial port
#include "TextField.h" // Optimize TFT display text for proportional fonts
#include "view.h" // Base class for all views
// ========== extern ===========================================
extern Logger logger; // Griduino.ino
extern void showDefaultTouchTargets(); // Griduino.ino
// ========== class ViewHelp ===================================
class ViewHelp : public View {
public:
// ---------- public interface ----------
// This derived class must implement the public interface:
ViewHelp(Adafruit_ILI9341 *vtft, int vid) // ctor
: View{vtft, vid} {
background = cBACKGROUND; // every view can have its own background color
}
void updateScreen();
void startScreen();
bool onTouch(Point touch);
protected:
// ---------- local data for this derived class ----------
// color scheme: see constants.h
const int margin = 10; // slight margin between button border and edge of screen
const int radius = 10; // rounded corners on buttons
// ----- screen text
// names for the array indexes, must be named in same order as array below
enum txtIndex {
SETTINGS = 0,
NEXTVIEW,
REBOOT,
BRIGHTNESS,
VIEWNAME,
};
// ----- static screen text
// const int cl = gScreenWidth/2;
// clang-format off
#define nHelpButtons 3
Button helpButtons[nHelpButtons] = {
// text x,y w,h r color
{"Settings", margin, margin, 98, 105, radius, cBUTTONLABEL}, //[SETTINGS]
{"Next view", margin+108, margin, 192, 105, radius, cBUTTONLABEL}, //[NEXTVIEW]
{"Brightness", margin, 126, 300, 105, radius, cBUTTONLABEL}, //[BRIGHTNESS]
//{"Hint", cl-38, 4, 76, 26, radius/2, cHIGHLIGHT}, //[VIEWNAME]
};
// clang-format on
}; // end class ViewHelp
// ============== implement public interface ================
void ViewHelp::updateScreen() {
// called on every pass through main()
// nothing to do in the main loop - this screen has no dynamic items
} // end updateScreen
void ViewHelp::startScreen() {
// called once each time this view becomes active
this->clearScreen(this->background); // clear screen
// ----- draw buttons
setFontSize(eFONTSMALL);
for (int ii = 0; ii < nHelpButtons; ii++) {
Button item = helpButtons[ii];
tft->fillRoundRect(item.x, item.y, item.w, item.h, item.radius, cBUTTONFILL);
tft->drawRoundRect(item.x, item.y, item.w, item.h, item.radius, cBUTTONOUTLINE);
// ----- label on top of button
int xx = getOffsetToCenterTextOnButton(item.text, item.x, item.w);
tft->setCursor(xx, item.y + item.h / 2 + 7);
tft->setTextColor(item.color);
tft->print(item.text);
}
// on Help screen, draw these after (on top of) the hint boxes, since they're filled with non-background color
showDefaultTouchTargets(); // optionally draw box around default button-touch areas
showMyTouchTargets(0, 0); // no real buttons on this view
showScreenBorder(); // optionally outline visible area
showScreenCenterline(); // optionally draw visual alignment bar
updateScreen(); // update UI immediately, don't wait for the main loop to eventually get around to it
// ----- label this view in upper left corner
showNameOfView("Hint: ", cWARN, cBACKGROUND);
delay(2000); // give user time to read the hint screen
} // end startScreen()
bool ViewHelp::onTouch(Point touch) {
// do nothing - this screen does not respond to buttons
logger.info("->->-> Touched help screen.");
return false; // true=handled, false=controller uses default action
} // end onTouch()