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

Data Structures

struct  dialogDrawInfo_t
 Holds information about how and where to draw the dialog box and its main components. More...
 
struct  optionDrawInfo_t
 Holds information about how and where to draw a dialog box option. More...
 

Macros

#define DIALOG_MARGIN   5
 < The space between the dialog box and the edge of the screen
 
#define DIALOG_PADDING   5
 The space around the.
 
#define DIALOG_ICON_MARGIN   5
 The space between the edge of the button and the text or image inside.
 
#define OPTION_PADDING   2
 The space between each option.
 
#define OPTION_MARGIN   5
 The space between an option's icon and text.
 
#define OPTION_ICON_MARGIN   3
 The color of the dialog title text.
 
#define COL_TITLE   c000
 The color of the dialog detail text.
 
#define COL_DETAIL   c000
 The color of the dialog's background.
 
#define COL_DIALOG_BG   c555
 The color of the dialog border outline.
 
#define COL_DIALOG_BORDER   c000
 The background color of non-selected options.
 
#define COL_OPTION_BG   c333
 The background color of the selected option.
 
#define COL_OPTION_BG_SEL   c455
 The color of the dialog's border outline.
 
#define COL_OPTION_BORDER   c444
 

Functions

dialogBox_tinitDialogBox (const char *title, const char *detail, const wsg_t *icon, dialogBoxCbFn_t cbFn)
 Allocate and return a new dialogBox_t with the given settings.
 
void deinitDialogBox (dialogBox_t *dialogBox)
 Deallocate all memory associated with the given dialog box.
 
void dialogBoxAddOption (dialogBox_t *dialogBox, const char *label, const wsg_t *icon, dialogOptionHint_t hints)
 Add an option button to a dialog box.
 
void dialogBoxReset (dialogBox_t *dialogBox)
 Clear all options from the given dialog box.
 
void drawDialogBox (const dialogBox_t *dialogBox, const font_t *titleFont, const font_t *detailFont, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r)
 Draw the dialog box.
 
void dialogBoxButton (dialogBox_t *dialogBox, const buttonEvt_t *evt)
 Handle button presses for the dialog box.
 

Data Structure Documentation

◆ dialogDrawInfo_t

struct dialogDrawInfo_t
Data Fields
uint16_t x The X coordinate of left side of the dialog.
uint16_t y The Y coordinate of the top edge of the dialog.
uint16_t w The total width of the dialog box.
uint16_t h The total height of the dialog box.
uint16_t titleX The X coordinate to draw the dialog title text at.
uint16_t titleY The Y coordinate to draw the dialog title text at.
uint16_t ruleY The Y coordinate for the horizontal rule between the title and detail.
uint16_t detailX The X coordinate to draw the dialog detail text at.
uint16_t detailY The Y coordinate to draw the dialog detail text at.
uint16_t iconX The X coordinate to draw the dialog icon at.
uint16_t iconY The Y coordinate to draw the dialog icon at.

◆ optionDrawInfo_t

struct optionDrawInfo_t
Data Fields
uint16_t x The X coordinate of the option's left edge.
uint16_t y The Y coordinate of the option's top edge.
uint16_t w The total width of the option button.
uint16_t h The total height of the option button.
uint8_t row The row of buttons this option is in, starting at 0 for the top row.
bool disabled Whether this option button is disabled.
bool selected Whether this option button is currently selected.
bool pressed Whether this option button is currently being pressed.
const dialogBoxOption_t * option

Macro Definition Documentation

◆ DIALOG_MARGIN

#define DIALOG_MARGIN   5

< The space between the dialog box and the edge of the screen

The space between the edge of the dialog box and the content inside

◆ DIALOG_PADDING

#define DIALOG_PADDING   5

The space around the.

◆ DIALOG_ICON_MARGIN

#define DIALOG_ICON_MARGIN   5

The space between the edge of the button and the text or image inside.

◆ OPTION_PADDING

#define OPTION_PADDING   2

The space between each option.

◆ OPTION_MARGIN

#define OPTION_MARGIN   5

The space between an option's icon and text.

◆ OPTION_ICON_MARGIN

#define OPTION_ICON_MARGIN   3

The color of the dialog title text.

◆ COL_TITLE

#define COL_TITLE   c000

The color of the dialog detail text.

◆ COL_DETAIL

#define COL_DETAIL   c000

The color of the dialog's background.

◆ COL_DIALOG_BG

#define COL_DIALOG_BG   c555

The color of the dialog border outline.

◆ COL_DIALOG_BORDER

#define COL_DIALOG_BORDER   c000

The background color of non-selected options.

◆ COL_OPTION_BG

#define COL_OPTION_BG   c333

The background color of the selected option.

◆ COL_OPTION_BG_SEL

#define COL_OPTION_BG_SEL   c455

The color of the dialog's border outline.

◆ COL_OPTION_BORDER

#define COL_OPTION_BORDER   c444

Function Documentation

◆ initDialogBox()

dialogBox_t * initDialogBox ( const char * title,
const char * detail,
const wsg_t * icon,
dialogBoxCbFn_t cbFn )

Allocate and return a new dialogBox_t with the given settings.

The result must be deallocated with deinitDialogBox().

Parameters
titleThe title text of the dialog box
detailThe body text of the dialog box
iconThe icon to display in the dialog box, if not NULL
cbFnThe callback function to be called when an option is selected
Returns
dialogBox_t* The newly allocated dialog box

◆ deinitDialogBox()

void deinitDialogBox ( dialogBox_t * dialogBox)

Deallocate all memory associated with the given dialog box.

Parameters
dialogBoxThe dialog box to deinitialize

◆ dialogBoxAddOption()

void dialogBoxAddOption ( dialogBox_t * dialogBox,
const char * label,
const wsg_t * icon,
dialogOptionHint_t hints )

Add an option button to a dialog box.

Parameters
dialogBoxThe dialog box to add the button to
labelThe text of the option button
iconThe icon for this button, or NULL for no icon
hintsAny number of dialogOptionHint_t, combined with bitwise OR for multiple

◆ dialogBoxReset()

void dialogBoxReset ( dialogBox_t * dialogBox)

Clear all options from the given dialog box.

Parameters
dialogBoxThe dialog box to reset

◆ drawDialogBox()

void drawDialogBox ( const dialogBox_t * dialogBox,
const font_t * titleFont,
const font_t * detailFont,
uint16_t x,
uint16_t y,
uint16_t w,
uint16_t h,
uint16_t r )

Draw the dialog box.

Parameters
dialogBoxThe dialog box to draw
titleFontThe font to use for drawing the dialog box title text
detailFontThe font to use for drawing the dialog box detail text
xThe X coordinate of the left side of the dialog box, or DIALOG_CENTER to automatically center it
yThe Y coordinate of the top of the dialog box, or DIALOG_CENTER to automatically center it
wThe width of the dialog box, or if combined with DIALOG_AUTO, the maximum width of the dialog box
hThe height of the dialog box, or if combined with DIALOG_AUTO, the maximum height of the dialog box
rThe corner-radius of the dialog box

◆ dialogBoxButton()

void dialogBoxButton ( dialogBox_t * dialogBox,
const buttonEvt_t * evt )

Handle button presses for the dialog box.

Parameters
dialogBoxThe dialog box to update
evtThe button event to be handled by the dialog box