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 drawMenuBody (uint16_t topLeftX, uint16_t topLeftY, uint8_t expansionHeight, bool flipLR, menuMegaRenderer_t *renderer)
 Draw the menu body background.
 
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 setDrawBody (menuMegaRenderer_t *renderer, bool drawBody)
 Set whether or not to draw the sci-fi rectangle background body.
 
void setBodyHeight (menuMegaRenderer_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.
 
void recolorMenuMegaRenderer (menuMegaRenderer_t *renderer, paletteColor_t textFill, paletteColor_t textOutline, paletteColor_t hexaBackground, paletteColor_t bodyBackground, paletteColor_t bodyAccentDark, paletteColor_t bodyAccentLight, paletteColor_t bodyArrowBg, paletteColor_t rowUnselectedBg, paletteColor_t rowUnselectedShadow, paletteColor_t rowSelectedBg, paletteColor_t rowSelectedAccent, paletteColor_t rowSelectedOutline, paletteColor_t rowArrowBg, const paletteColor_t *bgColors, int32_t numBgColors)
 Recolor the Mega menu renderer.
 

Data Structure Documentation

◆ menuMegaRenderer_t

struct menuMegaRenderer_t
Data Fields
wsg_t bg The screen's background image with cutout hexagons.
wsg_t body_top The top part of the menu's background image.
wsg_t body_bottom The bottom part of the menu's 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 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.
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 yOff An offset to the hexagons to make them scroll smoothly.
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
bool drawBody true to draw the sci-fi rectangle body background, false to skip it
uint16_t bodyHeight the height of the middle portion of the body, between top and bottom decorated parts
bool conveyorBeltStyle true to draw a sliding background and sliding lights

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.

◆ drawMenuBody()

void drawMenuBody ( uint16_t topLeftX,
uint16_t topLeftY,
uint8_t expansionHeight,
bool flipLR,
menuMegaRenderer_t * renderer )

Draw the menu body background.

Parameters
topLeftXThe X coordinate of the top left corner of the body
topLeftYThe Y coordinate of the top left corner of the body
expansionHeightThe y distance of filler rectangle between the top and bottom parts of the body
flipLRtrue to flip the body horizontally
rendererThe renderer to draw a body with

◆ 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

◆ setDrawBody()

void setDrawBody ( menuMegaRenderer_t * renderer,
bool drawBody )

Set whether or not to draw the sci-fi rectangle background body.

Parameters
rendererThe renderer.
drawBodytrue to draw the body background, false to skip it

◆ setBodyHeight()

void setBodyHeight ( menuMegaRenderer_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.

Parameters
rendererThe renderer to adjust the body height for
heightThe new height. If the given value is negative, the default height will be set.

◆ recolorMenuMegaRenderer()

void recolorMenuMegaRenderer ( menuMegaRenderer_t * renderer,
paletteColor_t textFill,
paletteColor_t textOutline,
paletteColor_t hexaBackground,
paletteColor_t bodyBackground,
paletteColor_t bodyAccentDark,
paletteColor_t bodyAccentLight,
paletteColor_t bodyArrowBg,
paletteColor_t rowUnselectedBg,
paletteColor_t rowUnselectedShadow,
paletteColor_t rowSelectedBg,
paletteColor_t rowSelectedAccent,
paletteColor_t rowSelectedOutline,
paletteColor_t rowArrowBg,
const paletteColor_t * bgColors,
int32_t numBgColors )

Recolor the Mega menu renderer.

Parameters
rendererThe renderer to recolor
textFillThe color of the text fill, originally white
textOutlineThe color of the text outline, originally black
hexaBackgroundThe color of the hexagonal background
bodyBackgroundThe color of the background between hexagons and items
bodyAccentDarkThe dark accent color of the background
bodyAccentLightThe light accent color of the background
bodyArrowBgThe color of the up and down arrows
rowUnselectedBgThe color of the background of an unselected row
rowUnselectedShadowThe color of the shadow of an unselected row
rowSelectedBgThe color of the background of the selected row
rowSelectedAccentThe accent color of the selected row
rowSelectedOutlineThe outline color of the selected row
rowArrowBgThe background color of left and right arrows
bgColorsA list of colors to cycle through in the hexagonal background. May be NULL for no change.
numBgColorsThe length of bgColors