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

Detailed Description

Design Philosophy

TextEntry serves as a method to create strings for a multitude of cases. It should be easy to see, easy to customize and as intuitive to use as possible. Several customization options are available.

Usage

Text entry in initialize with textEntryInit(), where the font used, max string length, and string pointer are provided. By default, a blank, black background is used with white text and no emphasis color.

Once initalized, additional commands can be run to customize the text entry screen:

The text entry is re-drawn from scratch every cycle. The above commands can be run between cycles if desired, though it is strongly discouraged to keep the text entry easy for the end user to navigate and utilize.

textEntryInit() can be called once during initialization or just before the text entry is required, but cannot be inside the loop or it will not function.

After all of the initialization is done, use textEntryDraw() to draw the current text entry box and textEntryInput() to send inputs to the tent entry. textEntryInput() returns true until enter/okay is selected.

The controls are as follows: Directions: navigate the keyboard A button: Select currently highlighted symbol B button: Backspace Start button: Move cursor to the enter key

Example

// Variables required
font fnt;
font fnt2;
int strLen = 32;
char createdString[strlen];
wsg bg_test;
const char promptStr[] "Enter your name:";
// Text Entry initialization
textEntryInit(&fnt, strLen, kbTest->typedText);
// Examples: Each of the following would overwrite the others
// Blue background, gray text, red emphasis text, and dark gray shadowboxes
// WSG background, pink shadowboxes, a new font and a prompt string
textEntrySetPrompt(promptStr);
// Transparent BG with caps lock and enter variations, and with the starting mode set to "Proper noun"
main loop(int64_t elapsedUs)
{
buttonEvt_t evt = {0};
{
done = !textEntryInput(evt.down, evt.button);
}
if (done)
{
// Text entry is done, createdString contains the text and can be used elsewhere
}
// Draw backgrounds for transparent mode here.
textEntryDraw(elapsedUs);
}
buttonBit_t button
The button that caused this event.
Definition hdw-btn.h:119
bool down
True if the button was pressed, false if it was released.
Definition hdw-btn.h:120
A button event containing the button that triggered the event, whether it was pressed or released,...
Definition hdw-btn.h:117
@ c433
r = 4, g = 3, b = 3
Definition palette.h:189
@ c111
r = 1, g = 1, b = 1
Definition palette.h:67
@ c444
r = 4, g = 4, b = 4
Definition palette.h:196
@ c003
r = 0, g = 0, b = 3
Definition palette.h:27
@ c500
r = 5, g = 0, b = 0
Definition palette.h:204
bool checkButtonQueueWrapper(buttonEvt_t *evt)
Service the queue of button events that caused interrupts This only returns a single event,...
Definition swadge2024.c:740
void textEntrySetShadowboxColor(bool active, uint8_t color)
Sets the color of the shadowbox.
Definition textEntry.c:435
void textEntrySetEmphasisColor(uint8_t color)
Set the emphasis color for the text.
Definition textEntry.c:430
void textEntrySetBgWsg(wsg_t *BG)
Sets a background image and sets the BG Mode to use the WSG.
Definition textEntry.c:404
void textEntrySetFont(font_t *newFont)
A new font to load into the text entry screen.
Definition textEntry.c:398
void textEntrySetNounMode()
Sets the starting mode to Porper Nouns (Auto capitalizes first letter after a space)
Definition textEntry.c:481
void textEntrySetNewEnterStyle(bool newStyle)
Sets the style of the Enter key.
Definition textEntry.c:441
void textEntrySetPrompt(char *prompt)
Sets the prompt text to be displayed. Use an empty string ("") to disable.
Definition textEntry.c:461
void textEntryInit(font_t *useFont, int max_len, char *buffer)
Initialize the text entry with prettier graphics.
Definition textEntry.c:156
void textEntrySetBGTransparent()
Sets the background to be transparent.
Definition textEntry.c:416
void textEntrySetTextColor(uint8_t color, bool emphasis)
Set the main text color for the keyboard and entry text.
Definition textEntry.c:421
bool textEntryDraw(int64_t elapsedUs)
Draw the text entry UI.
Definition textEntry.c:184
void textEntrySetBGColor(uint8_t color)
Sets the background to use a solid color.
Definition textEntry.c:410
bool textEntryInput(uint8_t down, uint8_t button)
Handle button input for text entry.
Definition textEntry.c:214
void textEntrySetNewCapsStyle(bool newStyle)
Sets the style of the caps lock key.
Definition textEntry.c:446

Go to the source code of this file.

Macros

#define KB_LINES   5
 
#define ENTER_X   12
 
#define ENTER_Y   2
 
#define CORNER_MARGIN   20
 
#define SHADOWBOX_MARGIN   4
 
#define RETURN_WIDTH   16
 
#define KEY_SPACING   5
 
#define MAX_WIDTH_CHAR   32
 
#define BLINK_RATE   500000
 

Enumerations

enum  keyModifier_t {
  NO_SHIFT , SHIFT , CAPS_LOCK , PROPER_NOUN ,
  SPECIAL_DONE
}
 
enum  controlChar_t {
  KEY_SHIFT = 0x01 , KEY_CAPS_LOCK = 0x02 , KEY_BACKSPACE = 0x03 , KEY_SPACE = 0x20 ,
  KEY_EOL = 0x05 , KEY_TAB = 0x09 , KEY_ENTER = 0x0A
}
 
enum  bgMode_t { WSG_BG , COLOR_BG , CLEAR_BG }
 

Functions

void textEntryInit (font_t *useFont, int max_len, char *buffer)
 Initialize the text entry with prettier graphics.
 
bool textEntryDraw (int64_t elapsedUs)
 Draw the text entry UI.
 
bool textEntryInput (uint8_t down, uint8_t button)
 Handle button input for text entry.
 
void textEntrySetFont (font_t *newFont)
 A new font to load into the text entry screen.
 
void textEntrySetBgWsg (wsg_t *BG)
 Sets a background image and sets the BG Mode to use the WSG.
 
void textEntrySetBGColor (uint8_t color)
 Sets the background to use a solid color.
 
void textEntrySetBGTransparent (void)
 Sets the background to be transparent.
 
void textEntrySetTextColor (uint8_t color, bool emphasis)
 Set the main text color for the keyboard and entry text.
 
void textEntrySetEmphasisColor (uint8_t color)
 Set the emphasis color for the text.
 
void textEntrySetShadowboxColor (bool active, uint8_t color)
 Sets the color of the shadowbox.
 
void textEntrySetNewEnterStyle (bool newStyle)
 Sets the style of the Enter key.
 
void textEntrySetNewCapsStyle (bool newStyle)
 Sets the style of the caps lock key.
 
void textEntrySetMultiline (bool multiline)
 Sets the text entry mode from single line to multi-line.
 
void textEntrySoftReset (void)
 Allow the text box to continue without a full reset.
 
void textEntrySetPrompt (char *prompt)
 Sets the prompt text to be displayed. Use an empty string ("") to disable.
 
void textEntrySetCapMode (void)
 Sets the starting mode to capslock.
 
void textEntrySetNoShiftMode (void)
 Sets the starting mode to lowercase text.
 
void textEntrySetShiftMode (void)
 Sets the starting mode to Shift, does one capital letter.
 
void textEntrySetNounMode (void)
 Sets the starting mode to Porper Nouns (Auto capitalizes first letter after a space)
 

Macro Definition Documentation

◆ KB_LINES

#define KB_LINES   5

◆ ENTER_X

#define ENTER_X   12

◆ ENTER_Y

#define ENTER_Y   2

◆ CORNER_MARGIN

#define CORNER_MARGIN   20

◆ SHADOWBOX_MARGIN

#define SHADOWBOX_MARGIN   4

◆ RETURN_WIDTH

#define RETURN_WIDTH   16

◆ KEY_SPACING

#define KEY_SPACING   5

◆ MAX_WIDTH_CHAR

#define MAX_WIDTH_CHAR   32

◆ BLINK_RATE

#define BLINK_RATE   500000

Enumeration Type Documentation

◆ keyModifier_t

Enumerator
NO_SHIFT 
SHIFT 
CAPS_LOCK 
PROPER_NOUN 
SPECIAL_DONE 

◆ controlChar_t

Enumerator
KEY_SHIFT 
KEY_CAPS_LOCK 
KEY_BACKSPACE 
KEY_SPACE 
KEY_EOL 
KEY_TAB 
KEY_ENTER 

◆ bgMode_t

enum bgMode_t
Enumerator
WSG_BG 
COLOR_BG 
CLEAR_BG 

Function Documentation

◆ textEntryInit()

void textEntryInit ( font_t * useFont,
int max_len,
char * buffer )

Initialize the text entry with prettier graphics.

Parameters
useFontThe font to use
max_lenThe length of buffer
bufferA char* to store the entered text in

◆ textEntryDraw()

bool textEntryDraw ( int64_t elapsedUs)

Draw the text entry UI.

Returns
true if text entry is still being used false if text entry is finished

◆ textEntryInput()

bool textEntryInput ( uint8_t down,
uint8_t button )

Handle button input for text entry.

Parameters
downtrue if the button was pressed, false if it was released
buttonThe button that was pressed
Returns
true if text entry is still ongoing false if the enter key was pressed and text entry is done

◆ textEntrySetFont()

void textEntrySetFont ( font_t * newFont)

A new font to load into the text entry screen.

Parameters
newFontpointer to a font file

◆ textEntrySetBgWsg()

void textEntrySetBgWsg ( wsg_t * BG)

Sets a background image and sets the BG Mode to use the WSG.

Parameters
BGPointer to Background image to set

◆ textEntrySetBGColor()

void textEntrySetBGColor ( uint8_t color)

Sets the background to use a solid color.

Parameters
colorColor to set the background

◆ textEntrySetBGTransparent()

void textEntrySetBGTransparent ( void )

Sets the background to be transparent.

◆ textEntrySetTextColor()

void textEntrySetTextColor ( uint8_t color,
bool emphasis )

Set the main text color for the keyboard and entry text.

Parameters
colorColor to set the text to.
emphasisWhether emphasis color should also be set to the same color

◆ textEntrySetEmphasisColor()

void textEntrySetEmphasisColor ( uint8_t color)

Set the emphasis color for the text.

Parameters
colorColor for the emphasis text

◆ textEntrySetShadowboxColor()

void textEntrySetShadowboxColor ( bool active,
uint8_t color )

Sets the color of the shadowbox.

Parameters
activeWhether these boxes should be drawn
colorColor for the shadowboxes

◆ textEntrySetNewEnterStyle()

void textEntrySetNewEnterStyle ( bool newStyle)

Sets the style of the Enter key.

Parameters
newStyleif true, use the new style

◆ textEntrySetNewCapsStyle()

void textEntrySetNewCapsStyle ( bool newStyle)

Sets the style of the caps lock key.

Parameters
newStyleif true, use the new style

◆ textEntrySetMultiline()

void textEntrySetMultiline ( bool multiline)

Sets the text entry mode from single line to multi-line.

Parameters
multilineTrue if using multi-line, false if not
Note
cursor does not draw in multiline due to drawTextWordWrap not exposing the end position of the text.

◆ textEntrySoftReset()

void textEntrySoftReset ( void )

Allow the text box to continue without a full reset.

◆ textEntrySetPrompt()

void textEntrySetPrompt ( char * prompt)

Sets the prompt text to be displayed. Use an empty string ("") to disable.

Parameters
promptText string to use

◆ textEntrySetCapMode()

void textEntrySetCapMode ( void )

Sets the starting mode to capslock.

◆ textEntrySetNoShiftMode()

void textEntrySetNoShiftMode ( void )

Sets the starting mode to lowercase text.

◆ textEntrySetShiftMode()

void textEntrySetShiftMode ( void )

Sets the starting mode to Shift, does one capital letter.

◆ textEntrySetNounMode()

void textEntrySetNounMode ( void )

Sets the starting mode to Porper Nouns (Auto capitalizes first letter after a space)