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

Detailed Description

Design Philosophy

Help pages can be used to draw multiple pages of multi-line text. This is useful for drawing a help manual for a Swadge mode in a consistent manner. The pages are themed using menuMegaRenderer_t.

Usage

initHelpScreen() must be called to initialize the screen before handling buttons and drawing. deinitHelpScreen() must be called to free memory when it's no longer needed.

buttonHelp() must be called to handle button input. It will return a boolean indicating if the help screen should be exited.

drawHelp() must be called to draw the screen.

Example

// Declare constant help pages
static const helpPage_t helpPages[] = {
{
.title = "Page 1",
.text = "This is the first page of help text! Welcome!",
},
{
.title = "Page 2",
.text = "This is the second page of help text. It probably has more details or something.",
},
};
// Set up the help screen when entering the mode
// The menu must be empty
menu_t* bgMenu = initMenu("Mode Name", NULL);
menuMegaRenderer_t* menuRenderer = initMenuMegaRenderer(NULL, NULL, NULL);
helpPageVars_t* help = initHelpScreen(bgMenu, menuRenderer, helpPages, ARRAY_SIZE(helpPages));
// Call this in the mode's fnMainLoop function when checkButtonQueueWrapper() emits an event
{
// Exit the help menu
}
// Call this in the mode's fnMainLoop function to draw
drawHelp(help, elapsedUs);
// Deinitialize when exiting the mode
A button event containing the button that triggered the event, whether it was pressed or released,...
Definition hdw-btn.h:117
void deinitHelpScreen(helpPageVars_t *help)
Deinitialize a help screen.
Definition helpPages.c:50
bool buttonHelp(helpPageVars_t *help, buttonEvt_t *evt)
Handle a button event on the help screen.
Definition helpPages.c:127
void drawHelp(helpPageVars_t *help, int32_t elapsedUs)
Draw the help screen.
Definition helpPages.c:61
helpPageVars_t * initHelpScreen(menu_t *bgMenu, menuMegaRenderer_t *menuRenderer, const helpPage_t *pages, int32_t numPages)
Initialize a help screen.
Definition helpPages.c:34
All the variables required for a help screen.
Definition helpPages.h:77
A help page consisting of a title and text.
Definition helpPages.h:68
#define ARRAY_SIZE(arr)
Definition macros.h:66
menuMegaRenderer_t * initMenuMegaRenderer(font_t *titleFont, font_t *titleFontOutline, font_t *menuFont)
Initialize a and return a menu renderer.
Definition menuMegaRenderer.c:65
A struct containing all the state data to render a mega-style menu and LEDs.
Definition menuMegaRenderer.h:39
menu_t * initMenu(const char *title, menuCb cbFunc)
Initialize and return an empty menu. A menu is a collection of vertically scrollable rows....
Definition menu.c:49
struct _menu_t menu_t
The underlying data for a menu. This fundamentally is a list of menuItem_t.
Definition menu.h:153

Go to the source code of this file.

Data Structures

struct  helpPage_t
 A help page consisting of a title and text. More...
 
struct  helpPageVars_t
 All the variables required for a help screen. More...
 

Functions

helpPageVars_tinitHelpScreen (menu_t *bgMenu, menuMegaRenderer_t *menuRenderer, const helpPage_t *pages, int32_t numPages)
 Initialize a help screen.
 
void deinitHelpScreen (helpPageVars_t *help)
 Deinitialize a help screen.
 
bool buttonHelp (helpPageVars_t *help, buttonEvt_t *evt)
 Handle a button event on the help screen.
 
void drawHelp (helpPageVars_t *help, int32_t elapsedUs)
 Draw the help screen.
 

Data Structure Documentation

◆ helpPage_t

struct helpPage_t
Data Fields
const char * title The title for an individual help page.
const char * text The text to be displayed on a help page.

◆ helpPageVars_t

struct helpPageVars_t
Data Fields
menu_t * bgMenu A menu to render behind the help text. Must not have any entries.
menuMegaRenderer_t * menuRenderer A renderer to render the menu with.
const helpPage_t * pages All the help pages.
int32_t numPages The number of help pages in helpPageVars_t.pages.
int32_t helpIdx The index of the page currently being displayed.
int32_t arrowBlinkTimer A timer used to blink arrows indicating more pages.

Function Documentation

◆ initHelpScreen()

helpPageVars_t * initHelpScreen ( menu_t * bgMenu,
menuMegaRenderer_t * menuRenderer,
const helpPage_t * pages,
int32_t numPages )

Initialize a help screen.

Parameters
bgMenuA menu to draw behind the help screen. It should not have any entries!
menuRendererA renderer to draw the menu
pagesThe pages to be displayed on the help screen
numPagesThe total number of pages
Returns
An initialized helpPageVars_t*

◆ deinitHelpScreen()

void deinitHelpScreen ( helpPageVars_t * help)

Deinitialize a help screen.

Parameters
helpThe help screen to deinitialize

◆ buttonHelp()

bool buttonHelp ( helpPageVars_t * help,
buttonEvt_t * evt )

Handle a button event on the help screen.

Parameters
helpThe help screen state
evtThe button event to handle
Returns
true to exit the help screen, false to remain on it

◆ drawHelp()

void drawHelp ( helpPageVars_t * help,
int32_t elapsedUs )

Draw the help screen.

Parameters
helpThe help screen state
elapsedUsThe time elapsed since the last function call