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

Macros

#define BTWN(chr, l, u)   (l <= chr && chr <= u)
 Macro to check if a character is between two bounds.
 
#define IS_UPPER(chr)   BTWN(chr, 'A', 'Z')
 Macro to check if a character is an uppercase letter.
 
#define IS_LOWER(chr)   BTWN(chr, 'a', 'z')
 Macro to check if a character is a lowercase letter.
 
#define IS_NUMBER(chr)   BTWN(chr, '0', '9')
 Macro to check if a character is a decimal digit.
 
#define IS_SYMBOL(chr)   (BTWN(chr, '!', '/') || BTWN(chr, ':', '@') || BTWN(chr, '[', '`') || BTWN(chr, '{', '~'))
 Macro to check if a character is a symbol.
 
#define IS_WHITESPACE(chr)   (chr == '\n' || chr == ' ' || chr == '\t')
 Macro to check if a character is whitespace.
 
#define IS_PRINTABLE(chr)   BTWN(chr, ' ', '~')
 Macro to check if a character is printable.
 
#define MATCH_CHAR(chr, mask)
 Macro to match a character against any mask value.
 
#define SPIN_DEG_PER_CHAR   12
 The number of degrees of spin required to advance the character.
 
#define BLINK_TIME   400000
 The time of each blink half cycle (on-to-off or off-to-on)
 
#define REPEAT_DELAY   500000
 The time a button must be held before it starts repeating.
 
#define REPEAT_TIME   100000
 The time between each repeated button press.
 
#define REPEATABLE_BUTTONS   (PB_UP | PB_DOWN | PB_LEFT | PB_RIGHT | PB_B | PB_A)
 

Functions

textEntry_tinitTextEntry (uint16_t x, uint16_t y, uint16_t w, uint16_t length, const font_t *font, textEntryCharMask_t mask, textEntryCb cbFn)
 Allocate and return a new text entry. The text entry must be freed with freeTextEntry()
 
void freeTextEntry (textEntry_t *textEntry)
 Frees any memory associated with a text entry.
 
void textEntrySetData (textEntry_t *textEntry, void *data)
 Sets the data pointer to be passed along to the callback function.
 
void textEntrySetText (textEntry_t *textEntry, const char *text)
 Copy the given text into the text entry, replacing any text that was there and moving the cursor to the end of the new text.
 
void textEntryMainLoop (textEntry_t *textEntry, int64_t elapsedUs)
 Update timer logic and handle touchpad for a text entry.
 
void textEntryButton (textEntry_t *textEntry, const buttonEvt_t *evt)
 Handle a button event for a text entry to modify the text or confirm entry.
 
void drawTextEntry (textEntry_t *textEntry, paletteColor_t fg, paletteColor_t bg, bool drawBox)
 Draw a text entry box.
 

Macro Definition Documentation

◆ BTWN

#define BTWN ( chr,
l,
u )   (l <= chr && chr <= u)

Macro to check if a character is between two bounds.

◆ IS_UPPER

#define IS_UPPER ( chr)    BTWN(chr, 'A', 'Z')

Macro to check if a character is an uppercase letter.

◆ IS_LOWER

#define IS_LOWER ( chr)    BTWN(chr, 'a', 'z')

Macro to check if a character is a lowercase letter.

◆ IS_NUMBER

#define IS_NUMBER ( chr)    BTWN(chr, '0', '9')

Macro to check if a character is a decimal digit.

◆ IS_SYMBOL

#define IS_SYMBOL ( chr)    (BTWN(chr, '!', '/') || BTWN(chr, ':', '@') || BTWN(chr, '[', '`') || BTWN(chr, '{', '~'))

Macro to check if a character is a symbol.

◆ IS_WHITESPACE

#define IS_WHITESPACE ( chr)    (chr == '\n' || chr == ' ' || chr == '\t')

Macro to check if a character is whitespace.

◆ IS_PRINTABLE

#define IS_PRINTABLE ( chr)    BTWN(chr, ' ', '~')

Macro to check if a character is printable.

◆ MATCH_CHAR

#define MATCH_CHAR ( chr,
mask )
Value:
((((mask & ENTRY_UPPERCASE) == ENTRY_UPPERCASE) && IS_UPPER(chr)) \
|| (((mask & ENTRY_LOWERCASE) == ENTRY_LOWERCASE) && IS_LOWER(chr)) \
|| (((mask & ENTRY_NUMBERS) == ENTRY_NUMBERS) && IS_NUMBER(chr)) \
|| (((mask & ENTRY_SYMBOLS) == ENTRY_SYMBOLS) && IS_SYMBOL(chr)) \
|| (((mask & ENTRY_WHITESPACE) == ENTRY_WHITESPACE) && IS_WHITESPACE(chr)))
#define IS_WHITESPACE(chr)
Macro to check if a character is whitespace.
Definition touchTextEntry.c:32
#define IS_LOWER(chr)
Macro to check if a character is a lowercase letter.
Definition touchTextEntry.c:26
#define IS_NUMBER(chr)
Macro to check if a character is a decimal digit.
Definition touchTextEntry.c:28
#define IS_SYMBOL(chr)
Macro to check if a character is a symbol.
Definition touchTextEntry.c:30
#define IS_UPPER(chr)
Macro to check if a character is an uppercase letter.
Definition touchTextEntry.c:24
@ ENTRY_LOWERCASE
Mask for allowing lowercase alphabet characters.
Definition touchTextEntry.h:120
@ ENTRY_WHITESPACE
Mask for allowing whitespace characters (space)
Definition touchTextEntry.h:126
@ ENTRY_NUMBERS
Mask for allowing numeric characters.
Definition touchTextEntry.h:122
@ ENTRY_UPPERCASE
Mask for allowing uppercase alphabet characters.
Definition touchTextEntry.h:118
@ ENTRY_SYMBOLS
Mask for allowing symbol characters (printable, non-alphanumeric, and non-whitespace)
Definition touchTextEntry.h:124

Macro to match a character against any mask value.

◆ SPIN_DEG_PER_CHAR

#define SPIN_DEG_PER_CHAR   12

The number of degrees of spin required to advance the character.

◆ BLINK_TIME

#define BLINK_TIME   400000

The time of each blink half cycle (on-to-off or off-to-on)

◆ REPEAT_DELAY

#define REPEAT_DELAY   500000

The time a button must be held before it starts repeating.

◆ REPEAT_TIME

#define REPEAT_TIME   100000

The time between each repeated button press.

◆ REPEATABLE_BUTTONS

#define REPEATABLE_BUTTONS   (PB_UP | PB_DOWN | PB_LEFT | PB_RIGHT | PB_B | PB_A)

Function Documentation

◆ initTextEntry()

textEntry_t * initTextEntry ( uint16_t x,
uint16_t y,
uint16_t w,
uint16_t length,
const font_t * font,
textEntryCharMask_t mask,
textEntryCb cbFn )

Allocate and return a new text entry. The text entry must be freed with freeTextEntry()

Parameters
xThe X coordinate of the left edge of the text box
yThe Y coordinate of the top of the text box
wThe width of the text box, in pixels
lengthThe maximum text length, or 0 for no limit
fontThe font to use when drawing the text entry
maskThe mask of allowable character types, or 0 for all characters
cbFnThe function to call once text entry is complete
Returns
textEntry_t*

◆ freeTextEntry()

void freeTextEntry ( textEntry_t * textEntry)

Frees any memory associated with a text entry.

Parameters
textEntryThe text entry to be deallocated

◆ textEntrySetData()

void textEntrySetData ( textEntry_t * textEntry,
void * data )

Sets the data pointer to be passed along to the callback function.

Parameters
textEntryThe text entry to update the data for
dataThe void pointer to be passed when the callback is called

◆ textEntrySetText()

void textEntrySetText ( textEntry_t * textEntry,
const char * text )

Copy the given text into the text entry, replacing any text that was there and moving the cursor to the end of the new text.

Parameters
textEntryThe text entry to update the text for
textThe text to set as the text entry's value

◆ textEntryMainLoop()

void textEntryMainLoop ( textEntry_t * textEntry,
int64_t elapsedUs )

Update timer logic and handle touchpad for a text entry.

Parameters
textEntryThe text entry to update
elapsedUsThe number of nanoseconds elapsed since the last call

◆ textEntryButton()

void textEntryButton ( textEntry_t * textEntry,
const buttonEvt_t * evt )

Handle a button event for a text entry to modify the text or confirm entry.

Parameters
textEntryThe text entry to handle the button event
evtA pointer to the button event to be handled

◆ drawTextEntry()

void drawTextEntry ( textEntry_t * textEntry,
paletteColor_t fg,
paletteColor_t bg,
bool drawBox )

Draw a text entry box.

Parameters
textEntryThe text entry to draw
fgThe color to use for drawing text and "more" dots
bgThe color to use for drawing inverted text and, if drawBox is enabled, the background
drawBoxWhether to fill the text entry box area's background