ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Menu.cpp
Go to the documentation of this file.
1#include "Menu.h"
2
3// Define static member variables
7
12float Menu::rotation;
14
15const uint8_t Menu::menuLength;
16const uint8_t Menu::menuRows;
17const uint8_t Menu::menuCountEng;
19uint8_t Menu::faceCount;
20uint8_t Menu::currentMenu = 0;
21float Menu::wiggleRatio = 1.0f;
22float Menu::wiggleSpeedX = 1.0f;
23float Menu::wiggleSpeedY = 1.0f;
24float Menu::wiggleSpeedR = 1.0f;
25bool Menu::isSecondary = 0;
26
27uint8_t Menu::faceState = 0;
28uint8_t Menu::bright = 0;
29uint8_t Menu::accentBright = 0;
30uint8_t Menu::microphone = 0;
31uint8_t Menu::micLevel = 0;
32uint8_t Menu::boopSensor = 0;
33uint8_t Menu::spectrumMirror = 0;
34uint8_t Menu::faceSize = 0;
35uint8_t Menu::color = 0;
36uint8_t Menu::huef = 0;
37uint8_t Menu::hueb = 0;
38uint8_t Menu::effect = 0;
39uint8_t Menu::fanSpeed = 0;
40
41// 111111111111222222222222333333333333444444444444555555555555666666666666777777777777888888888888999999999999111111111111222222222222333333333333444444444444
42String Menu::line1 = " BRIGHT SDE BRIGHT MIC MIC LEVEL BOOP SPEC SIZE COLOR HUE F HUE B EFFECT FAN SPEED ";
43String Menu::line2 = " a b c d e f 12^45 12^45 ON off 123456|8 on OFF ON off 12^45 123456|8 123456|8 123456|8 123456|8 123456|8 ";
44
46float Menu::effectStrength = 0.0f;
47uint8_t Menu::previousMenu = 0;
48
61
82
101
102void Menu::Initialize(uint8_t faceCount, uint8_t pin, uint16_t holdingTime, Vector2D size) {
104
105 dampedSpringX.SetConstants(1.0f, 0.5f);
106 dampedSpringShow.SetConstants(1.0f, 0.5f);
107
108 SetSize(size);
109
110 textEngine.SetMaterial(&material);
111 textEngine.SetPositionOffset(position);
112 textEngine.SetBlinkTime(200);
113
114#ifndef NEOTRELLISMENU
115 if (!MenuHandler<menuCount>::Initialize(pin, holdingTime)) {
117 }
118#endif
119
121
122#ifndef NEOTRELLISMENU
124#endif
125 isSecondary = false;
126
127 effectChange.AddParameter(&effectStrength);
128}
129
132
133 dampedSpringX.SetConstants(1.0f, 0.5f);
134 dampedSpringShow.SetConstants(1.0f, 0.5f);
135
136 SetSize(size);
137
138 textEngine.SetMaterial(&material);
139 textEngine.SetPositionOffset(position);
140 textEngine.SetBlinkTime(200);
141
142#ifdef NEOTRELLISMENU
145 }
146
147 isSecondary = false;
148#else
149 isSecondary = true;
150#endif
151
153}
154
156 return &textEngine;
157}
158
160 switch (GetEffectS()) {
161 case 0:
162 return &passthrough;
163 break;
164 case 1:
165 return &phaseY;
166 break;
167 case 2:
168 return &phaseX;
169 break;
170 case 3:
171 return &phaseR;
172 break;
173 case 4:
174 return &glitchX;
175 break;
176 case 5:
177 return &passthrough;//&magnet;
178 break;
179 case 6:
180 return &passthrough;//&fisheye;
181 break;
182 case 7:
183 return &passthrough;//&blurH;
184 break;
185 case 8:
186 return &passthrough;//&blurV;
187 break;
188 case 9:
189 return &passthrough;//&blurR
190 default:
191 return &passthrough;
192 break;
193 }
194}
195
199
203
207
208void Menu::Update(float ratio) {
209#if defined NEOTRELLISMENU || defined MORSEBUTTON
211#endif
212
213 float target = 0.0f;
214 float menuTarget = 0.0f;
215
216 if (isSecondary) {
217 target = (1.0f - float(currentMenu + 1) / float(menuCount)) * size.X + 25.0f;
218 menuTarget = currentMenu != 0 ? 0.0f : 100.0f;
219 } else {
220 target = (1.0f - float(MenuHandler<menuCount>::GetCurrentMenu() + 1) / float(menuCount)) * size.X + 25.0f;
221 menuTarget = MenuHandler<menuCount>::GetCurrentMenu() != 0 ? 0.0f : 100.0f;
222 }
223
224 float xPosition = dampedSpringX.Calculate(target, 0.25f);
225
226 showMenuRatio = dampedSpringShow.Calculate(menuTarget, 0.25f);
227 material.Update(ratio);
228
229 float ratioX = sinf(ratio * Mathematics::MPI * 2.0f * wiggleSpeedX) * 4.0f;
230 float ratioY = sinf(ratio * Mathematics::MPI * 2.0f * wiggleSpeedY) * 4.0f;
231 float ratioR = sinf(ratio * Mathematics::MPI * 2.0f * wiggleSpeedR) * 4.0f;
232
233 Menu::SetPosition(Vector2D(-xPosition + ratioX * wiggleRatio, ratioY * wiggleRatio + 40.0f + showMenuRatio * 3.0f));
234 Menu::SetRotationOffset(Vector2D(200.0f / 2, 100.0f / 2));
235 Menu::SetRotation(ratioR);
236
238
239 if (GetFaceState() != previousMenu) {
240 effectChange.RestartTime();
242 }
243
244 effectChange.Update();
245
247}
248
252
258
260 size.X = size.X * menuCount;
261
263
264 textEngine.SetSize(size);
265}
266
270
275
279
284
286 return Menu::rotation;
287}
288
291 textEngine.SetRotationAngle(rotation);
292}
293
294char Menu::IntToBlink(char value) {
295 switch (value) {
296 case '0':
297 return '[';
298 case '1':
299 return '\\';
300 case '2':
301 return ']';
302 case '3':
303 return '^';
304 case '4':
305 return '_';
306 case '5':
307 return '`';
308 case '6':
309 return '{';
310 case '7':
311 return '|';
312 case '8':
313 return '}';
314 case '9':
315 return '~';
316 default:
317 return ' ';
318 }
319}
320
321String Menu::GenerateLine(uint8_t options, uint8_t selection) {
322 String text;
323 uint8_t spacing = options >= 5 ? 3 : (menuLength - options) / 2;
324
325 for (uint8_t i = 0; i < spacing; i++) {
326 text += " ";
327 }
328
329 for (uint8_t i = 0; i < 5; i++) {
330 if (selection < 5 && i < options) {
331 char value = '0' + i;
332
333 if (i == selection) {
334 text += IntToBlink(value);
335 } else {
336 text += value;
337 }
338 } else if (selection >= 5 && i + 5 < options) {
339 char value = '5' + i;
340
341 if (i + 5 == selection) {
342 text += IntToBlink(value);
343 } else {
344 text += value;
345 }
346 }
347 }
348
349 while (text.length() < menuLength) {
350 text += " ";
351 }
352
353 return text;
354}
355
357 textEngine.SetText(0, line1, false);
358
359 line2 = " ";
360
363 line2 += UseMicrophone() ? " on OFF " : " ON off ";
365 line2 += UseBoopSensor() ? " on OFF " : " ON off ";
366 line2 += MirrorSpectrumAnalyzer() ? " on OFF " : " ON off ";
369 line2 += GenerateLine(10, GetHueF());
370 line2 += GenerateLine(10, GetHueB());
371 line2 += GenerateLine(10, GetEffectS());
373
374 textEngine.SetText(1, line2, false);
375}
376
380
382 if (isSecondary) return faceState;
384}
385
388}
389
391 if (isSecondary) return bright;
393}
394
398
403
407
412
416
418 if (isSecondary) return micLevel;
420}
421
425
430
434
439
443
445 if (isSecondary) return faceSize;
447}
448
451}
452
454 if (isSecondary) return color;
456}
457
458void Menu::SetHueF(uint8_t huef) {
460}
461
462uint8_t Menu::GetHueF() {
463 if (isSecondary) return huef;
465}
466
467void Menu::SetHueB(uint8_t hueb) {
469}
470
471uint8_t Menu::GetHueB() {
472 if (isSecondary) return hueb;
474}
475
478}
479
481 if (isSecondary) return effect;
483}
484
488
490 if (isSecondary) return fanSpeed;
492}
493
495 return showMenuRatio / 100.0f;
496}
Provides the Menu class for controlling various parameters of the program.
Simulates the motion of a damped spring.
A template class for animating effect transitions using keyframes.
Abstract base class for applying visual effects to pixel groups.
Definition Effect.h:26
void SetRatio(float ratio)
Sets the scaling ratio for the effect.
Definition Effect.cpp:5
Implements a fisheye distortion effect for pixel groups.
Definition Fisheye.h:26
Implements a glitch effect along the X-axis for pixel groups.
Definition GlitchX.h:26
Implements a horizontal blur effect for pixel groups.
Implements a magnetic distortion effect for pixel groups.
Definition Magnet.h:25
Abstract base class for rendering materials.
Definition Material.h:27
static const float MPI
Mathematical constant (3.14159265358979323846...).
Definition Mathematics.h:42
static void SetInitialized()
Marks the menu system as initialized.
static void SetMenuMax(uint8_t menu, uint8_t maxValue)
Sets the maximum value for a specific menu.
static void Update()
Updates the menu state and processes user interactions.
static uint8_t GetMenuValue(uint8_t menu)
Retrieves the current value of a specific menu.
static void Begin()
Begins the menu handling process, setting up necessary states.
static uint8_t GetCurrentMenu()
Retrieves the index of the currently active menu.
static bool Initialize()
Initializes the MenuHandler and sets up the NeoTrellis keypad.
static void SetDefaultValue(uint16_t menu, uint8_t value)
Sets a default value for a specific menu.
static float GetRotation()
Gets the current menu rotation angle.
Definition Menu.cpp:285
static Magnet magnet
Definition Menu.h:177
static float wiggleSpeedY
Speed of vertical wiggle.
Definition Menu.h:131
static void SetMirrorSpectrumAnalyzer(uint8_t spectrumMirror)
Sets whether the spectrum analyzer should be mirrored if in isSecondary mode.
Definition Menu.cpp:431
static void SetUseMicrophone(uint8_t microphone)
Sets whether to use the microphone if in isSecondary mode.
Definition Menu.cpp:404
static void SetDefaultEntries()
Sets default values for each menu parameter (e.g., on initial load).
Definition Menu.cpp:83
static float rotation
Rotation angle (in degrees or radians, depending on usage).
Definition Menu.h:97
static Overflow overflow
Definition Menu.h:183
static PhaseOffsetR phaseR
Definition Menu.h:181
static uint8_t GetCurrentMenuValue()
Gets the current value of the active menu parameter from the MenuHandler.
Definition Menu.cpp:200
static char IntToBlink(char value)
Converts a digit character into a "blink" character for visual emphasis.
Definition Menu.cpp:294
static uint8_t GetFaceState()
Retrieves the current face state. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:381
static Vector2D position
The current position of the menu.
Definition Menu.h:94
static void SetFanSpeed(uint8_t fanSpeed)
Sets the fan speed if in isSecondary mode.
Definition Menu.cpp:485
static uint8_t previousMenu
Tracks a previous face state to detect changes.
Definition Menu.h:167
static uint8_t GetEffectS()
Gets the currently selected effect index.
Definition Menu.cpp:480
static ShiftR shiftR
Definition Menu.h:182
static void SetRotation(float rotation)
Sets the rotation angle for the menu (in degrees or radians, based on usage).
Definition Menu.cpp:289
static void SetHueB(uint8_t hueb)
Sets the back hue value if in isSecondary mode.
Definition Menu.cpp:467
static PhaseOffsetX phaseX
Definition Menu.h:179
static Fisheye fisheye
Definition Menu.h:173
static uint8_t boopSensor
Boop sensor usage toggle.
Definition Menu.h:147
static RainbowNoise material
A RainbowNoise material (used for text styling, if desired).
Definition Menu.h:82
static uint8_t currentMenu
Tracks the currently active menu index (if using isSecondary mode).
Definition Menu.h:124
static uint8_t GetFaceColor()
Gets the current face color index.
Definition Menu.cpp:453
static uint8_t GetMicLevel()
Gets the current microphone level.
Definition Menu.cpp:417
static void SetPositionOffset(Vector2D positionOffset)
Sets an additional offset to be added on top of the base position.
Definition Menu.cpp:276
static void SetUseBoopSensor(uint8_t boopSensor)
Sets the boop sensor usage if in isSecondary mode.
Definition Menu.cpp:422
static VerticalBlur blurV
Definition Menu.h:176
static float ShowMenu()
Returns how much of the menu is shown, typically normalized (0.0 to 1.0).
Definition Menu.cpp:494
static EffectChangeTrack< 1 > effectChange
EffectChangeTrack for smoothly transitioning the effect strength.
Definition Menu.h:165
static DampedSpring dampedSpringX
DampedSpring objects used for smooth transitions in the X-direction and for menu visibility.
Definition Menu.h:87
static String line2
Definition Menu.h:160
static Vector2D positionOffset
Additional offset to apply to the menu's position.
Definition Menu.h:95
static void SetHueF(uint8_t huef)
Sets the front hue value if in isSecondary mode.
Definition Menu.cpp:458
static void GenerateText()
Generates the textual representation of the menu (two lines) and updates the TextEngine with that tex...
Definition Menu.cpp:356
static const uint8_t menuCountEng
Total "expanded" count for text engine usage.
Definition Menu.h:109
static uint8_t spectrumMirror
Spectrum mirroring toggle.
Definition Menu.h:148
static void SetWiggleSpeed(float wiggleSpeedX, float wiggleSpeedY, float wiggleSpeedR)
Sets the speed multipliers for X-axis, Y-axis, and rotational wiggle.
Definition Menu.cpp:253
static void SetFaceColor(uint8_t color)
Sets the face color index if in isSecondary mode.
Definition Menu.cpp:449
static const uint8_t menuCount
Total number of menu items.
Definition Menu.h:77
static void SetMaxEntries()
Defines the maximum allowed values for each menu parameter.
Definition Menu.cpp:62
static uint8_t GetFanSpeed()
Gets the current fan speed index.
Definition Menu.cpp:489
static void SetFaceState(uint8_t faceState)
Manually sets the face state (active face index) if in isSecondary mode.
Definition Menu.cpp:377
static Material * GetMaterial()
Provides a pointer to the material used for rendering the menu text.
Definition Menu.cpp:155
static void SetAccentBrightness(uint8_t accentBright)
Sets the accent brightness level if in isSecondary mode.
Definition Menu.cpp:395
static RadialBlur blurR
Definition Menu.h:178
static uint8_t MirrorSpectrumAnalyzer()
Checks if the spectrum analyzer mirroring is toggled on or off.
Definition Menu.cpp:435
static uint8_t GetFaceSize()
Gets the current face size.
Definition Menu.cpp:444
static void SetCurrentMenu(uint8_t currentMenu)
Manually sets the current menu index (used in isSecondary mode).
Definition Menu.cpp:204
static void Initialize(uint8_t faceCount, uint8_t pin, uint16_t holdingTime, Vector2D size=Vector2D(240, 50))
Initializes the Menu using a face count, input pin, holding time, and size.
Definition Menu.cpp:102
static uint8_t accentBright
Accent brightness level.
Definition Menu.h:144
static String line1
Raw string lines for the textual interface (line1 as label row, line2 as value row).
Definition Menu.h:159
static float wiggleRatio
Wiggle effect parameters for the menu's animation.
Definition Menu.h:129
static uint8_t bright
Brightness level.
Definition Menu.h:143
static const uint8_t menuRows
Number of rows in the text display.
Definition Menu.h:104
static uint8_t GetHueF()
Gets the front hue value.
Definition Menu.cpp:462
static void SetRotationOffset(Vector2D rotationOffset)
Sets the pivot or rotation offset for the text engine.
Definition Menu.cpp:280
static Passthrough passthrough
Various post-processing effects instantiated.
Definition Menu.h:172
static uint8_t GetCurrentMenu()
Gets the currently selected menu index from the MenuHandler (if in hardware mode).
Definition Menu.cpp:196
static PhaseOffsetY phaseY
Definition Menu.h:180
static void SetSize(Vector2D size)
Sets the overall menu size and updates the text engine accordingly.
Definition Menu.cpp:259
static uint8_t faceCount
Face count for how many faces are selectable in this project.
Definition Menu.h:119
@ Color
Controls the face color selection.
Definition Menu.h:66
@ EffectS
Controls which post-processing effect is active.
Definition Menu.h:69
@ SpectrumMirror
Toggles mirror effect for SpectrumAnalyzer (on/off).
Definition Menu.h:64
@ FaceSize
Controls the size of the face mesh or display.
Definition Menu.h:65
@ MicLevel
Controls microphone level (gain).
Definition Menu.h:62
@ Bright
Controls the overall brightness.
Definition Menu.h:59
@ Microphone
Toggles microphone usage (on/off).
Definition Menu.h:61
@ AccentBright
Controls the accent brightness.
Definition Menu.h:60
@ BoopSensor
Toggles boop sensor usage (on/off).
Definition Menu.h:63
@ HueB
Controls the back hue value.
Definition Menu.h:68
@ HueF
Controls the front hue value.
Definition Menu.h:67
@ FanSpeed
Controls the fan speed.
Definition Menu.h:70
@ Faces
Controls the current face index.
Definition Menu.h:58
static void SetWiggleRatio(float wiggleRatio)
Sets the amplitude of the wiggle effect.
Definition Menu.cpp:249
static uint8_t faceState
Stored state for each menu item (if isSecondary is true).
Definition Menu.h:142
static uint8_t UseMicrophone()
Checks if the microphone usage is toggled on or off.
Definition Menu.cpp:408
static float showMenuRatio
Normalized ratio (0.0 to 100.0) controlling how much the menu is shown.
Definition Menu.h:98
static uint8_t micLevel
Microphone level setting.
Definition Menu.h:146
static const uint8_t menuLength
Dimensions for the internal text layout, e.g., number of columns/rows.
Definition Menu.h:103
static uint8_t color
Current color setting.
Definition Menu.h:150
static GlitchX glitchX
Definition Menu.h:174
static uint8_t faceSize
Face size setting.
Definition Menu.h:149
static float effectStrength
The current strength ratio for the applied effect.
Definition Menu.h:166
static void SetMicLevel(uint8_t micLevel)
Sets the microphone level (gain) if in isSecondary mode.
Definition Menu.cpp:413
static uint8_t UseBoopSensor()
Checks if the boop sensor usage is toggled on or off.
Definition Menu.cpp:426
static TextEngine< menuRows, menuLength *menuCountEng > textEngine
Text engine for rendering menu lines.
Definition Menu.h:114
static float wiggleSpeedX
Speed of horizontal wiggle.
Definition Menu.h:130
static float wiggleSpeedR
Speed of rotational wiggle.
Definition Menu.h:132
static uint8_t microphone
Microphone usage toggle.
Definition Menu.h:145
static void Update(float ratio)
Updates the menu each frame, handling transitions, wiggle effects, and text generation.
Definition Menu.cpp:208
static uint8_t huef
Front hue setting.
Definition Menu.h:151
static uint8_t GetHueB()
Gets the back hue value.
Definition Menu.cpp:471
static void SetEffectS(uint8_t effect)
Sets which effect is selected if in isSecondary mode.
Definition Menu.cpp:476
static Vector2D rotationOffset
Offset for pivoting the menu (e.g., around its center).
Definition Menu.h:96
static uint8_t fanSpeed
Fan speed setting.
Definition Menu.h:154
static HorizontalBlur blurH
Definition Menu.h:175
static bool isSecondary
Indicates whether this Menu is in "secondary" mode (no hardware input, used externally).
Definition Menu.h:137
static void SetFaceSize(uint8_t faceSize)
Sets the face size if in isSecondary mode.
Definition Menu.cpp:440
static String GenerateLine(uint8_t options, uint8_t selection)
Generates a line of characters for displaying available options (0-9), visually highlighting the curr...
Definition Menu.cpp:321
static uint8_t GetBrightness()
Gets the current brightness level. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:390
static Effect * GetEffect()
Retrieves the current effect (post-processing) based on the menu setting.
Definition Menu.cpp:159
static DampedSpring dampedSpringShow
Controls the show/hide ratio of the menu.
Definition Menu.h:88
static void SetPosition(Vector2D position)
Sets the base position of the menu (plus any existing offsets).
Definition Menu.cpp:271
static Vector2D GetPosition()
Returns the current screen-space position of the menu.
Definition Menu.cpp:267
static uint8_t GetAccentBrightness()
Gets the current accent brightness level.
Definition Menu.cpp:399
static void SetBrightness(uint8_t bright)
Sets the brightness level if in isSecondary mode.
Definition Menu.cpp:386
static Vector2D size
UI geometry: size, position, offsets, and rotation.
Definition Menu.h:93
static uint8_t hueb
Back hue setting.
Definition Menu.h:152
static uint8_t effect
Current effect index.
Definition Menu.h:153
Implements an overflow distortion effect for pixel groups.
Definition Overflow.h:24
A no-operation effect that leaves pixel groups unchanged.
Definition Passthrough.h:24
Applies rotational phase offsets to pixel groups.
Applies horizontal phase offsets to pixel groups.
Applies vertical phase offsets to pixel groups.
Applies a radial blur effect to pixel groups.
Definition RadialBlur.h:26
A dynamic material that creates a rainbow effect using simplex noise.
Radially shifts the red, green, and blue channels of the pixels.
Definition ShiftR.h:26
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
An effect that applies a vertical blur to a pixel group.