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 initMenuManiaRenderer() and deinitialized with deinitMenuManiaRenderer(). 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 drawMenuMania(). 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 menuManiaRenderer
Go to the source code of this file.
Data Structures | |
struct | maniaRing_t |
struct | menuManiaRenderer_t |
A struct containing all the state data to render a mania-style menu and LEDs. More... | |
Macros | |
#define | Y_SECTION_MARGIN 14 |
#define | TITLE_BG_HEIGHT 40 |
#define | MANIA_TITLE_HEIGHT (TITLE_BG_HEIGHT + Y_SECTION_MARGIN) |
The height of the title section, from the top of the TFT to the bottom of the title block. | |
#define | MANIA_BODY_HEIGHT (TFT_HEIGHT - MANIA_TITLE_HEIGHT) |
The height of the body section, from the bottom of the title block to the bottom of the TFT. | |
Functions | |
menuManiaRenderer_t * | initMenuManiaRenderer (font_t *titleFont, font_t *titleFontOutline, font_t *menuFont) |
Initialize a and return a menu renderer. | |
void | deinitMenuManiaRenderer (menuManiaRenderer_t *renderer) |
Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuManiaRenderer() | |
void | drawMenuMania (menu_t *menu, menuManiaRenderer_t *renderer, int64_t elapsedUs) |
Draw a themed menu to the display and control the LEDs. | |
void | setManiaLedsOn (menuManiaRenderer_t *renderer, bool ledsOn) |
Set the renderer's LEDs to be on or off. | |
void | recolorMenuManiaRenderer (menuManiaRenderer_t *renderer, paletteColor_t titleBgColor, paletteColor_t titleTextColor, paletteColor_t textOutlineColor, paletteColor_t bgColor, paletteColor_t outerRingColor, paletteColor_t innerRingColor, paletteColor_t rowColor, paletteColor_t rowTextColor, const paletteColor_t *shadowColors, int32_t shadowColorsLen, led_t baseLedColor) |
Recolor a menu renderer. | |
struct maniaRing_t |
Data Fields | ||
---|---|---|
int16_t | orbitAngle | Angle for the orbit circles. |
int32_t | orbitTimer | Timer to rotate the orbit circles. |
int32_t | orbitUsPerDegree | Number of microseconds to wait before rotating by one degree. |
int32_t | orbitDirection | The direction to rotate, +1 or -1. |
int16_t | diameterAngle | Angle to grow and shrink the orbit circles. |
int32_t | diameterTimer | Timer to grow and shrink the orbit circles. |
paletteColor_t | color | The color of this ring. |
struct menuManiaRenderer_t |
Data Fields | ||
---|---|---|
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 deinitMenuManiaRenderer() |
bool | titleFontOutlineAllocated |
true if this font was allocated by the renderer and should be freed by deinitMenuManiaRenderer() |
bool | menuFontAllocated |
true if this font was allocated by the renderer and should be freed by deinitMenuManiaRenderer() |
led_t | leds[CONFIG_NUM_LEDS] | An array with the RGB LED state to be output. |
wsg_t | batt[4] | Images for the battery levels. |
maniaRing_t | rings[2] | |
int32_t | ledDecayTimer | Timer to decay LEDs. |
int32_t | ledExciteTimer | Timer to excite LEDs. |
int16_t | currentLed | The current LED being excited. |
bool | ledsOn | true to use the LEDs, false to keep them off |
menuItem_t * | selectedItem | Reference to the selected item to tell when it changes. |
int16_t | selectedShadowIdx | The index to the color offset for the selected drop shadow. |
int32_t | selectedShadowTimer | The timer to change the color for the selected drop shadow. |
int16_t | selectedBounceIdx | The index to the bounce offset for the selected item. |
int32_t | selectedBounceTimer | The timer to bounce the offset for the selected item. |
int32_t | selectedValue | The option index or setting value to tell when it changes. |
int32_t | selectedMarqueeTimer | The timer for marquee-ing the selected item text, if too long to fit. |
paletteColor_t | titleBgColor | The color of the title background. |
paletteColor_t | titleTextColor | The color of the title text. |
paletteColor_t | textOutlineColor | The color of the title text outline. |
paletteColor_t | bgColor | The color of the screen background. |
paletteColor_t | outerRingColor | The color of the outer rotating ring. |
paletteColor_t | innerRingColor | The color of the inner rotating ring. |
paletteColor_t | rowColor | The color of the row background. |
paletteColor_t | rowTextColor | The color of the row text. |
const paletteColor_t * | shadowColors | The colors cycled through as the selected shadow. |
int32_t | shadowColorsLen | The number of selected shadow colors to cycle through. |
led_t | baseLedColor | The base color of the LED rotation. |
#define Y_SECTION_MARGIN 14 |
#define TITLE_BG_HEIGHT 40 |
#define MANIA_TITLE_HEIGHT (TITLE_BG_HEIGHT + Y_SECTION_MARGIN) |
The height of the title section, from the top of the TFT to the bottom of the title block.
#define MANIA_BODY_HEIGHT (TFT_HEIGHT - MANIA_TITLE_HEIGHT) |
The height of the body section, from the bottom of the title block to the bottom of the TFT.
menuManiaRenderer_t * initMenuManiaRenderer | ( | 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 deinitMenuManiaRenderer | ( | menuManiaRenderer_t * | renderer | ) |
Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuManiaRenderer()
renderer | The renderer to deinitialize. It must not be used after deinitialization. |
void drawMenuMania | ( | menu_t * | menu, |
menuManiaRenderer_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 setManiaLedsOn | ( | menuManiaRenderer_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 recolorMenuManiaRenderer | ( | menuManiaRenderer_t * | renderer, |
paletteColor_t | titleBgColor, | ||
paletteColor_t | titleTextColor, | ||
paletteColor_t | textOutlineColor, | ||
paletteColor_t | bgColor, | ||
paletteColor_t | outerRingColor, | ||
paletteColor_t | innerRingColor, | ||
paletteColor_t | rowColor, | ||
paletteColor_t | rowTextColor, | ||
const paletteColor_t * | shadowColors, | ||
int32_t | shadowColorsLen, | ||
led_t | baseLedColor ) |
Recolor a menu renderer.
renderer | The menu renderer to recolor |
titleBgColor | The color of the title background |
titleTextColor | The color of the title text |
textOutlineColor | The color of the title text outline |
bgColor | The color of the screen background |
outerRingColor | The color of the outer rotating ring |
innerRingColor | The color of the inner rotating ring |
rowColor | The color of the row background |
rowTextColor | The color of the row text |
shadowColors | The colors cycled through as the selected shadow |
shadowColorsLen | The number of selected shadow colors to cycle through |
baseLedColor | The color of the LED illumination |