Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
menuSimpleRenderer.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 initMenuSimpleRenderer() and deinitialized with deinitMenuSimpleRenderer(). 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 drawMenuSimple(). 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 menuSimpleRenderer

Go to the source code of this file.

Data Structures

struct  menuSimpleRenderer_t
 A struct containing all the state data to render a simple menu. More...
 

Functions

menuSimpleRenderer_tinitMenuSimpleRenderer (font_t *font, paletteColor_t border, paletteColor_t bg, paletteColor_t text, int32_t rows)
 Initialize a and return a menu renderer.
 
void deinitMenuSimpleRenderer (menuSimpleRenderer_t *renderer)
 Deinitialize a menu renderer and free associated memory. This will not free the font passed into initMenuSimpleRenderer()
 
void drawMenuSimple (menu_t *menu, menuSimpleRenderer_t *renderer)
 Draw a themed menu to the display and control the LEDs.
 

Data Structure Documentation

◆ menuSimpleRenderer_t

struct menuSimpleRenderer_t
Data Fields
font_t * font The font to render the title with.
int32_t numRows
paletteColor_t borderColor The color of the background border.
paletteColor_t bgColor The color of the screen background.
paletteColor_t rowTextColor The color of the row text.

Function Documentation

◆ initMenuSimpleRenderer()

menuSimpleRenderer_t * initMenuSimpleRenderer ( font_t * font,
paletteColor_t border,
paletteColor_t bg,
paletteColor_t text,
int32_t rows )

Initialize a and return a menu renderer.

Parameters
fontThe font used to draw this menu
borderThe color for the background border
bgThe color for the background
textThe color for the text
rowsThe number of rows to display
Returns
A pointer to the menu renderer. This memory is allocated and must be freed with deinitMenuSimpleRenderer()

◆ deinitMenuSimpleRenderer()

void deinitMenuSimpleRenderer ( menuSimpleRenderer_t * renderer)

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

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

◆ drawMenuSimple()

void drawMenuSimple ( menu_t * menu,
menuSimpleRenderer_t * renderer )

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

Parameters
menuThe menu to draw
rendererThe renderer to draw with