NightFox’s Lib
|
Text support functions of NFLIb. More...
Data Structures | |
struct | NF_TYPE_TEXT_INFO |
Struct that holds text layer information. More... | |
Macros | |
#define | NF_TEXT_FONT_CHARS 127 |
Number of characters available in a font. | |
#define | NF_TEXT_FONT_LAST_VALID_CHAR 113 |
Last valid character in a font. | |
Functions | |
void | NF_InitTextSys (int screen) |
Initialize the text engine for the selected screen. More... | |
void | NF_LoadTextFont (const char *file, const char *name, u32 width, u32 height, u32 rotation) |
Load font and palette files from the filesystem to RAM. More... | |
void | NF_UnloadTextFont (const char *name) |
Delete from RAM the font with the specified name. More... | |
void | NF_CreateTextLayer (int screen, u32 layer, u32 rotation, const char *name) |
Create a special tiled background to write text on it. More... | |
void | NF_DeleteTextLayer (int screen, u32 layer) |
Delete a text layer. More... | |
void | NF_WriteText (int screen, u32 layer, u32 x, u32 y, const char *text) |
Write text in a layer at the specified coordinates. More... | |
void | NF_UpdateTextLayers (void) |
Copy the temporary text buffers of both screens to VRAM. More... | |
void | NF_ClearTextLayer (int screen, u32 layer) |
Clears the contents of a text layer filling it with zeroes. More... | |
void | NF_DefineTextColor (int screen, u32 layer, u32 color, u32 r, u32 g, u32 b) |
Defines a RGB color to be used later as a text color. More... | |
Variables | |
NF_TYPE_TEXT_INFO | NF_TEXT [2][4] |
Information of all text layers. | |
Text support functions of NFLIb.
void NF_ClearTextLayer | ( | int | screen, |
u32 | layer | ||
) |
Clears the contents of a text layer filling it with zeroes.
Example:
screen | Screen (0 - 1) |
layer | Background layer (0 - 3) |
void NF_CreateTextLayer | ( | int | screen, |
u32 | layer, | ||
u32 | rotation, | ||
const char * | name | ||
) |
Create a special tiled background to write text on it.
You must select the screen and layer where the background will be created, the orientation of the text and the font you want to use.
Example:
screen | Screen (0 - 1) |
layer | Background layer (0 - 3) |
rotation | Rotation (0 - 2) |
name | Font name |
void NF_DefineTextColor | ( | int | screen, |
u32 | layer, | ||
u32 | color, | ||
u32 | r, | ||
u32 | g, | ||
u32 | b | ||
) |
Defines a RGB color to be used later as a text color.
The color is stored in the specified slot. To make this function work, the font palette must be indexed and it must have 2 colors (Magenta/White). Only color index 1 is updated by this function, so any other color in higher indices won't be updated.
Example:
screen | Screen (0 - 1) |
layer | Background layer (0 - 3) |
color | Color number (0 - 15) |
r | Red component (0 - 31) |
g | Green component (0 - 31) |
b | Blue component (0 - 31) |
void NF_DeleteTextLayer | ( | int | screen, |
u32 | layer | ||
) |
Delete a text layer.
You must specify the layer and screen of the text layer you want to delete.
Example:
screen | Screen (0 - 1) |
layer | Background layer (0 - 3) |
void NF_InitTextSys | ( | int | screen | ) |
Initialize the text engine for the selected screen.
You must also initialize the tiled background system of that screen before using the text engine. You can get more information about it in NF_InitTiledBgBuffers() and NF_InitTiledBgSys().
Use this function also to reset text system.
Example:
screen | Screen (0 - 1). |
void NF_LoadTextFont | ( | const char * | file, |
const char * | name, | ||
u32 | width, | ||
u32 | height, | ||
u32 | rotation | ||
) |
Load font and palette files from the filesystem to RAM.
You must specify the filename without extension and the name you want to give to the font and the size of the text layer you want to create, in pixels.
If the font includes the characters for rotated text, the values are:
The font uses two files, the tileset with extension ".fnt" and the palette with extension ".pal".
You must load the font for every text layer you want to create. Every font loaded uses a slot of tiled backgrounds of RAM.
There are many examples with custom fonts in the examples folder.
Example:
file | File name |
name | Font name |
width | Map width (in pixels) |
height | Map height (in pixels) |
rotation | Rotation (0 - 2) |
void NF_UnloadTextFont | ( | const char * | name | ) |
Delete from RAM the font with the specified name.
Example:
name | Font name |
void NF_UpdateTextLayers | ( | void | ) |
Copy the temporary text buffers of both screens to VRAM.
Buffers are only copied if the copy in VRAM is outdated.
Example:
void NF_WriteText | ( | int | screen, |
u32 | layer, | ||
u32 | x, | ||
u32 | y, | ||
const char * | text | ||
) |
Write text in a layer at the specified coordinates.
You must specify the screen and layer where you want to write the text. The text is not writen directly on the screen. It's stored in a temporary buffer and it's transferred to the screen when the function NF_UpdateTextLayers() is called. This is done to minimize the number of times VRAM is updated.
If you want to write variables or formated text, use snprintf().
Example 1:
Example 2:
screen | Screen (0 - 1) |
layer | Background layer (0 - 3) |
x | X coordinate |
y | Y coordinate |
text | String to write to the screen |