Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
menuMegaRenderer.h File Reference

Detailed Description

Design Philosophy

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.

Usage

First a menu_t data structure must be created. For that usage, see menu.h.

The menu renderer is initialized with initmenuMegaRenderer() and deinitialized with deinitmenuMegaRenderer(). 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 drawMenuMega(). This will both draw over the entire display and light LEDs. The menu may be drawn on top of later.

Example

See menu.h for examples on how to use menuMegaRenderer

Go to the source code of this file.

Data Structures

struct  menuMegaRenderer_t
 A struct containing all the state data to render a mega-style menu and LEDs. More...
 

Functions

menuMegaRenderer_tinitMenuMegaRenderer (font_t *titleFont, font_t *titleFontOutline, font_t *menuFont)
 Initialize a and return a menu renderer.
 
void deinitMenuMegaRenderer (menuMegaRenderer_t *renderer)
 Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuMegaRenderer()
 
void drawMenuMega (menu_t *menu, menuMegaRenderer_t *renderer, int64_t elapsedUs)
 Draw a themed menu to the display and control the LEDs.
 
void setMegaLedsOn (menuMegaRenderer_t *renderer, bool ledsOn)
 Set the renderer's LEDs to be on or off.
 
void recolorMenuMegaRenderer (menuMegaRenderer_t *renderer, paletteColor_t textFill, paletteColor_t textOutline, paletteColor_t c1, paletteColor_t c2, paletteColor_t c3, paletteColor_t c4, paletteColor_t c5, paletteColor_t c6, paletteColor_t c7, paletteColor_t c8, const paletteColor_t *bgColors, int32_t numBgColors)
 Recolor the Mega menu renderer. Arguments c1 through c8 should get progressively lighter.
 

Data Structure Documentation

◆ menuMegaRenderer_t

struct menuMegaRenderer_t
Data Fields
wsg_t bg The screen's background image with cutout hexagons.
wsg_t body The menu's solid background image.
wsg_t item Background image for non-selected items.
wsg_t item_sel Background image for the selected item.
wsg_t up A single up arrow (previous page)
wsg_t down A single down arrow (next page)
wsg_t next A single right arrow (next option)
wsg_t prev A single left arrow (previous option)
wsg_t submenu A double right arrow (enter submenu)
wsg_t back A double left arrow (exit submenu)
wsg_t batt[4] Images for the battery levels.
wsgPalette_t palette A palette to recolor menu images with.
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 * titleFontOutline The font to render the title outline 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 deinitMenuMegaRenderer()

bool titleFontOutlineAllocated

true if this font was allocated by the renderer and should be freed by deinitMenuMegaRenderer()

bool menuFontAllocated

true if this font was allocated by the renderer and should be freed by deinitMenuMegaRenderer()

int32_t selectedMarqueeTimer 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.
const paletteColor_t * bgColors A list of colors to cycle through for the background hexagons.
int32_t numBgColors The number of colors in bgColors.
int32_t bgColorTimer A timer to increment bgColorDeg in order to cycle through bgColors.
int32_t bgColorDeg

When cycling through bgColors, a sine wave is followed. This counts the degrees into the sine wave, 0 to 180

int32_t bgColorIdx The current index into bgColors.
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

Function Documentation

◆ initMenuMegaRenderer()

menuMegaRenderer_t * initMenuMegaRenderer ( font_t * titleFont,
font_t * titleFontOutline,
font_t * menuFont )

Initialize a and return a menu renderer.

Parameters
titleFontThe font used to draw the title, preferably RIGHTEOUS_150_FONT. If this is NULL it will be allocated by the renderer in SPIRAM.
titleFontOutlineThe outline font used to draw the title. If this is NULL it will be allocated by the renderer in SPIRAM.
menuFontThe font used to draw this menu, preferably RODIN_EB_FONT. If this is NULL it will be allocated by the renderer in SPIRAM.
Returns
A pointer to the menu renderer. This memory is allocated and must be freed with deinitMenuMegaRenderer() when done

◆ deinitMenuMegaRenderer()

void deinitMenuMegaRenderer ( menuMegaRenderer_t * renderer)

Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuMegaRenderer()

Parameters
rendererThe renderer to deinitialize. It must not be used after deinitialization.

◆ drawMenuMega()

void drawMenuMega ( menu_t * menu,
menuMegaRenderer_t * renderer,
int64_t elapsedUs )

Draw a themed menu to the display and control the LEDs.

Parameters
menuThe menu to draw
rendererThe renderer to draw with
elapsedUsThe time elapsed since this function was last called, for LED animation

◆ setMegaLedsOn()

void setMegaLedsOn ( menuMegaRenderer_t * renderer,
bool ledsOn )

Set the renderer's LEDs to be on or off.

Parameters
rendererThe renderer to set
ledsOntrue to animate the LEDs, false to keep them off

◆ recolorMenuMegaRenderer()

void recolorMenuMegaRenderer ( menuMegaRenderer_t * renderer,
paletteColor_t textFill,
paletteColor_t textOutline,
paletteColor_t c1,
paletteColor_t c2,
paletteColor_t c3,
paletteColor_t c4,
paletteColor_t c5,
paletteColor_t c6,
paletteColor_t c7,
paletteColor_t c8,
const paletteColor_t * bgColors,
int32_t numBgColors )

Recolor the Mega menu renderer. Arguments c1 through c8 should get progressively lighter.

Parameters
rendererThe renderer to recolor
textFillThe color of the text fill, originally white
textOutlineThe color of the text outline, originally black
c1Replacement for Darkest blue
c2Replacement for Very dark blue
c3Replacement for Dark blue
c4Replacement for Dark moderate blue
c5Replacement for Dark strong blue
c6Replacement for Light strong blue
c7Replacement for Pure cyan
c8Replacement for Very pale cyan
bgColorsA list of colors to cycle through in the hexagonal background. May be NULL for no change.
numBgColorsThe length of bgColors