-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathParameterListScreen.h
199 lines (172 loc) · 6.8 KB
/
ParameterListScreen.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
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
#ifndef PARAMETERLISTSCREEN_H
#define PARAMETERLISTSCREEN_H
#include "IScreen.h"
#include "../Widgets/PushButton.h"
#include "../Widgets/ImageButton.h"
#include "../ButtonDefinitions.h"
#include "../MenuDefinitions.h"
#include "../IMenuSystem.h"
#include "../../GlobalSettings.h"
class IPainter;
class IUSBDevice;
class ParameterListScreen : public IScreen
{
char const* _header;
PushButton _cancelButton;
PushButton _setButton;
// Colors
uint16_t _backgroundColor;
uint16_t _textColor;
uint16_t _highlightColor;
uint16_t _highlightTextColor;
uint16_t _backgroundPressedColor;
uint16_t _textPressedColor;
int8_t _highlightIndex; // which item in parameter men is currently highlighted
int8_t _pressedIndex; // which item in parameter men is currently pressed
uint8_t _previousOptionIndex; // this item is the "old" selected choice but remains in effcet until the parameter
// menu select has been completed
uint8_t _optionCount; // number of parameter menu entries
char const* _optionLabels[64];
uint8_t _optionLineHeight;
public:
explicit ParameterListScreen(IUSBDevice* usbDevice) :
IScreen(usbDevice), _cancelButton("Cancel"), _setButton("Set"), _header("Parameter Menu"),
_previousOptionIndex(0), _highlightIndex(0), _optionLineHeight(35), _backgroundColor((uint16_t)Color565::White),
_textColor((uint16_t)Color565::Black), _highlightColor((uint16_t)Color565::AXIOM_Orange),
_highlightTextColor((uint16_t)Color565::White), _backgroundPressedColor(utils::RGB565(0, 128, 255)),
_textPressedColor((uint16_t)Color565::White), _pressedIndex(-1)
{
//_cancelButton.SetHandler(&CancelButtonHandler);
_bottomButtonBar.SetButton(ButtonPosition::Left, &_cancelButton);
// This is the primary button in this menu
//_setButton.SetHandler(&SetButtonHandler);
_setButton.SetColor(ButtonState::Default, PushButton::Colors::Background,
static_cast<uint16_t>(Color565::AXIOM_Orange));
_bottomButtonBar.SetButton(ButtonPosition::Right, &_setButton);
}
void SetOptions(const char* optionlabels[], uint8_t optioncount)
{
_optionCount = optioncount;
for (int8_t i = 0; i < optioncount; i++)
{
_optionLabels[i] = optionlabels[i];
//_parameterMenuItem[i].SetHorizontalTextMargin(_horizontalTextMargin);
}
}
void SetSetButtonPressed(bool pressed)
{
_setButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default);
}
void SetCancelButtonPressed(bool pressed)
{
_cancelButton.SetState(pressed ? ButtonState::Highlighted : ButtonState::Default);
}
void SetHighlighted(uint8_t highlightindex)
{
if (highlightindex < _optionCount)
{
_highlightIndex = highlightindex;
}
}
void SetPressed(uint8_t pressedindex)
{
if (pressedindex < _optionCount)
{
_pressedIndex = pressedindex;
}
}
void UnpressAll()
{
_pressedIndex = -1;
}
void UpdateChoice(uint8_t choiceindex)
{
if (choiceindex < _optionCount)
{
_previousOptionIndex = choiceindex;
}
}
uint8_t GetHighlightIndex()
{
return _highlightIndex;
}
void SetHeader(const char* value)
{
_header = value;
}
char const* GetHeader()
{
return _header;
}
void Draw(IPainter* painter) override
{
painter->Fill(_backgroundColor);
Drawheader(painter);
// draw options
painter->SetFont(Font::FreeSans12pt7b);
uint8_t heightcenter = GlobalSettings::LCDHeight / 2 - _optionLineHeight / 2;
uint8_t fontcenter = _optionLineHeight / 2 + painter->GetCurrentFontHeight() / 2;
for (int8_t i = 0; i < _optionCount; i++)
{
if (_pressedIndex == i)
{
painter->DrawFillRectangle(20, heightcenter, GlobalSettings::LCDWidth - 40, _optionLineHeight,
_backgroundPressedColor);
painter->DrawText(30, heightcenter + fontcenter, _optionLabels[i], _textPressedColor,
TextAlign::TEXT_ALIGN_LEFT, GlobalSettings::LCDWidth);
} else if (_highlightIndex == i)
{
painter->DrawFillRectangle(20, heightcenter, GlobalSettings::LCDWidth - 40, _optionLineHeight,
_highlightColor);
painter->DrawText(30, heightcenter + fontcenter, _optionLabels[i], _highlightTextColor,
TextAlign::TEXT_ALIGN_LEFT, GlobalSettings::LCDWidth);
} else if ((i - _highlightIndex <= 2) && (i - _highlightIndex >= -2))
{
painter->DrawText(30, heightcenter + (i - _highlightIndex) * _optionLineHeight + fontcenter,
_optionLabels[i], _textColor, TextAlign::TEXT_ALIGN_LEFT, GlobalSettings::LCDWidth);
}
// draw current (old) value indicator circle
if (_previousOptionIndex == i)
{
if (_highlightIndex == i)
{
painter->DrawFillCircle(25,
heightcenter + (i - _highlightIndex) * _optionLineHeight + fontcenter - 7,
3, _highlightTextColor);
} else
{
painter->DrawFillCircle(
25, heightcenter + (i - _highlightIndex) * _optionLineHeight + fontcenter - 7, 3, _textColor);
}
}
}
DrawBottomButtonBar(painter);
}
static void CancelButtonHandler(void* sender);
static void SetButtonHandler(void* sender);
void Drawheader(IPainter* painter)
{
// header background
painter->DrawFillRectangle(0, 0, GlobalSettings::LCDWidth, 30, (uint16_t)Color565::Black);
// header title
painter->SetFont(Font::FreeSans12pt7b);
painter->DrawText(0, 22, _header, (uint16_t)Color565::White, TextAlign::TEXT_ALIGN_CENTER,
GlobalSettings::LCDWidth);
// header separation lines
painter->DrawLine(0, 29, GlobalSettings::LCDWidth - 1, 29, (uint16_t)Color565::AXIOM_Orange);
}
/*void Update(Button button, int8_t knob, IMenuSystem* menuSystem)
{
switch (button)
{
case Button::E_1_UP:
_menuItem[_menuSelectionIndex]->SetPressed(false);
SelectionPress(menuSystem);
break;
case Button::E_1_DOWN:
_menuItem[_menuSelectionIndex]->SetPressed(true);
break;
}
}*/
};
#endif // PARAMETERLISTSCREEN_H