|
Swadge 2024 2.0.0
APIs to develop games 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 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.
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_t * | initMenuMegaRenderer (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. | |
| 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 |
| menuMegaRenderer_t * initMenuMegaRenderer | ( | font_t * | titleFont, |
| font_t * | titleFontOutline, | ||
| font_t * | menuFont ) |
Initialize a and return a menu renderer.
| titleFont | The font used to draw the title, preferably RIGHTEOUS_150_FONT. If this is NULL it will be allocated by the renderer in SPIRAM. |
| titleFontOutline | The outline font used to draw the title. If this is NULL it will be allocated by the renderer in SPIRAM. |
| menuFont | The font used to draw this menu, preferably RODIN_EB_FONT. If this is NULL it will be allocated by the renderer in SPIRAM. |
| void deinitMenuMegaRenderer | ( | menuMegaRenderer_t * | renderer | ) |
Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuMegaRenderer()
| renderer | The renderer to deinitialize. It must not be used after deinitialization. |
| void drawMenuBody | ( | uint16_t | topLeftX, |
| uint16_t | topLeftY, | ||
| uint8_t | expansionHeight, | ||
| bool | flipLR, | ||
| menuMegaRenderer_t * | renderer ) |
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 |
| expansionHeight | The y distance of filler rectangle between the top and bottom parts of the body |
| flipLR | true to flip the body horizontally |
| renderer | The renderer to draw a body with |
| void drawMenuMega | ( | menu_t * | menu, |
| menuMegaRenderer_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 setMegaLedsOn | ( | menuMegaRenderer_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 setDrawBody | ( | menuMegaRenderer_t * | renderer, |
| bool | drawBody ) |
Set whether or not to draw the sci-fi rectangle background body.
| renderer | The renderer. |
| drawBody | true to draw the body background, false to skip it |
| 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.
| 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. |
| 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.
| renderer | The renderer to recolor |
| textFill | The color of the text fill, originally white |
| textOutline | The color of the text outline, originally black |
| hexaBackground | The color of the hexagonal background |
| bodyBackground | The color of the background between hexagons and items |
| bodyAccentDark | The dark accent color of the background |
| bodyAccentLight | The light accent color of the background |
| bodyArrowBg | The color of the up and down arrows |
| rowUnselectedBg | The color of the background of an unselected row |
| rowUnselectedShadow | The color of the shadow of an unselected row |
| rowSelectedBg | The color of the background of the selected row |
| rowSelectedAccent | The accent color of the selected row |
| rowSelectedOutline | The outline color of the selected row |
| rowArrowBg | The background color of left and right arrows |
| bgColors | A list of colors to cycle through in the hexagonal background. May be NULL for no change. |
| numBgColors | The length of bgColors |