|
Swadge ESP32-S2
APIs to develop for the Magfest Swadge
|
A menu renderer takes the data in the menu_t data structure and renders it to the display. The menu data structure is separated from the rendering logic so that it is possible to draw menus with differing themes.
First a menu_t data structure must be created. For that usage, see menu.h.
The menu renderer is initialized with initMenuZorldoRenderer() and deinitialized with deinitMenuZorldoRenderer(). Menu renderers must be deinitialized or they will leak memory. When initializing the menu, fonts may be passed in as an argument, or the arguments may be NULL. If the Swadge mode is loading fonts for itself, you can save RAM by using the same font in the menu renderer. If the Swadge mode isn't using the same fonts, it's easier to have the menu renderer manage it's own fonts. Either way, you should avoid loading the same font multiple times.
The menu is drawn with drawMenuZorldo(). This will both draw over the entire display and light LEDs. The menu may be drawn on top of later.
See menu.h for examples on how to use menuZorldoRenderer
Go to the source code of this file.
Data Structures | |
| struct | menuZorldoCloud_t |
| struct | menuZorldoRenderer_t |
| A struct containing all the state data to render a Zorldo-style menu and LEDs. More... | |
Functions | |
| menuZorldoRenderer_t * | initMenuZorldoRenderer (font_t *titleFont, font_t *menuFont) |
| Initialize a and return a menu renderer. | |
| void | deinitMenuZorldoRenderer (menuZorldoRenderer_t *renderer) |
| Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuZorldoRenderer(). | |
| void | drawMenuZorldoBody (uint16_t topLeftX, uint16_t topLeftY, menuZorldoRenderer_t *renderer, int64_t elapsedUs) |
| Draw the menu body background. | |
| void | drawMenuZorldo (menu_t *menu, menuZorldoRenderer_t *renderer, int64_t elapsedUs) |
| Draw a themed menu to the display and control the LEDs. | |
| void | setZorldoLedsOn (menuZorldoRenderer_t *renderer, bool ledsOn) |
| Set the renderer's LEDs to be on or off. | |
| void | setDrawMenuZorldoBody (menuZorldoRenderer_t *renderer, bool drawBody) |
| Set whether or not to draw the menu background. | |
| void | setMenuZorldoBodyHeight (menuZorldoRenderer_t *renderer, int16_t height) |
| Set the height of the body between top and bottom decorated parts If the given height is negative, it will be set to the default height. | |
| struct menuZorldoCloud_t |
| Data Fields | ||
|---|---|---|
| float | x | |
| int16_t | y | |
| float | speed | Speed in px/us. |
| wsg_t | wsg | |
| bool | mirrored | |
| struct menuZorldoRenderer_t |
| Data Fields | ||
|---|---|---|
| wsg_t | corner | The corner cap for the border. |
| wsg_t | ewi | Ewi Of Time. |
| wsg_t | battery | Battery container. |
| wsg_t | tomi | Hey! Listen! |
| wsg_t | arrowPageUp | A single up arrow (previous page). Mirror it for down. |
| wsg_t | arrowRight | A single right arrow (next option). Mirror it for left. |
| wsg_t | arrowSubmenu | A double right arrow (enter submenu). Mirror it for...you know. |
| paletteColor_t | textFillColor | The color to fill text with. |
| paletteColor_t | textOutlineColor | The color to outline text with. |
| font_t * | titleFont | The font to render the title with. |
| font_t * | menuFont | The font to render the menu with. |
| bool | titleFontAllocated |
true if this font was allocated by the renderer and should be freed by deinitMenuZorldoRenderer() |
| bool | menuFontAllocated |
true if this font was allocated by the renderer and should be freed by deinitMenuZorldoRenderer() |
| int32_t | selectedMarqueeTimer | The timer for marquee-ing the selected item text, if too long to fit. |
| int32_t | shadowMarqueeTimer | The timer for marquee-ing the selected item text, if too long to fit. |
| int32_t | pageArrowTimer | The timer for blinking page up/down arrows. |
| node_t * | currentItem | The currently selected menu item, resets ::selectedMarqueeTimer when changed. |
| menuZorldoCloud_t | clouds[4] | Clouds to drift behind the menu. |
| float | tomiYPos | Tomi's Y position. |
| float | tomiYTarget | Y position Tomi is moving towards. Will match the selected menu item. |
| float | tomiXDegrees | Sine degrees for Tomi's x offset. |
| float | tomiYDegrees | Sine degrees for Tomi's y offset. |
| led_t | leds[CONFIG_NUM_LEDS] | An array with the RGB LED state to be output. |
| bool | ledsOn | true if LEDs should be set by this renderer, false to leave LEDs alone |
| bool | drawBody | true to draw the body background, false to skip it |
| uint16_t | bodyHeight | the height of the middle portion of the body, between top and bottom decorated parts |
| menuZorldoRenderer_t * initMenuZorldoRenderer | ( | font_t * | titleFont, |
| font_t * | menuFont ) |
Initialize a and return a menu renderer.
| titleFont | The font used to draw the title, preferably PIX_ROMANA_FONT. If this is NULL it will be allocated by the renderer in SPIRAM. |
| menuFont | The font used to draw this menu, preferably MINISHCAP_FONT. If this is NULL it will be allocated by the renderer in SPIRAM. |
| void deinitMenuZorldoRenderer | ( | menuZorldoRenderer_t * | renderer | ) |
Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuZorldoRenderer().
| renderer | The renderer to deinitialize. It must not be used after deinitialization. |
| void drawMenuZorldoBody | ( | uint16_t | topLeftX, |
| uint16_t | topLeftY, | ||
| menuZorldoRenderer_t * | renderer, | ||
| int64_t | elapsedUs ) |
Draw the menu body background.
| topLeftX | The X coordinate of the top left corner of the body |
| topLeftY | The Y coordinate of the top left corner of the body |
| renderer | The renderer to draw a body with |
| elapsedUs | The time elapsed since this function was last called, for cloud animation |
| void drawMenuZorldo | ( | menu_t * | menu, |
| menuZorldoRenderer_t * | renderer, | ||
| int64_t | elapsedUs ) |
Draw a themed menu to the display and control the LEDs.
| menu | The menu to draw |
| renderer | The renderer to draw with |
| elapsedUs | The time elapsed since this function was last called, for LED animation |
| void setZorldoLedsOn | ( | menuZorldoRenderer_t * | renderer, |
| bool | ledsOn ) |
Set the renderer's LEDs to be on or off.
| renderer | The renderer to set |
| ledsOn | true to animate the LEDs, false to keep them off |
| void setDrawMenuZorldoBody | ( | menuZorldoRenderer_t * | renderer, |
| bool | drawBody ) |
Set whether or not to draw the menu background.
| renderer | The renderer. |
| drawBody | true to draw the body background, false to skip it |
| void setMenuZorldoBodyHeight | ( | menuZorldoRenderer_t * | renderer, |
| int16_t | height ) |
Set the height of the body between top and bottom decorated parts If the given height is negative, it will be set to the default height.
| renderer | The renderer to adjust the body height for |
| height | The new height. If the given value is negative, the default height will be set. |