87 lines
2.2 KiB
C
87 lines
2.2 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "asset/asset.h"
|
|
#include "display/texture/texture.h"
|
|
#include "display/texture/tileset.h"
|
|
|
|
#define TEXT_CHAR_START '!'
|
|
|
|
extern texture_t DEFAULT_FONT_TEXTURE;
|
|
extern tileset_t DEFAULT_FONT_TILESET;
|
|
|
|
/**
|
|
* Initializes the text system.
|
|
*
|
|
* @return Either an error or success result.
|
|
*/
|
|
errorret_t textInit(void);
|
|
|
|
/**
|
|
* Disposes of the text system.
|
|
*
|
|
* @return Either an error or success result.
|
|
*/
|
|
errorret_t textDispose(void);
|
|
|
|
/**
|
|
* Draws a single character at the specified position.
|
|
*
|
|
* @param x The x-coordinate to draw the character at.
|
|
* @param y The y-coordinate to draw the character at.
|
|
* @param c The character to draw.
|
|
* @param color The color to draw the character in.
|
|
* @param tileset Font tileset to use for rendering.
|
|
* @param texture Texture containing the font tileset image.
|
|
* @return Either an error or success result.
|
|
*/
|
|
errorret_t textDrawChar(
|
|
const float_t x,
|
|
const float_t y,
|
|
const char_t c,
|
|
#if MESH_ENABLE_COLOR
|
|
const color_t color,
|
|
#endif
|
|
const tileset_t *tileset,
|
|
texture_t *texture
|
|
);
|
|
|
|
/**
|
|
* Draws a string of text at the specified position.
|
|
*
|
|
* @param x The x-coordinate to draw the text at.
|
|
* @param y The y-coordinate to draw the text at.
|
|
* @param text The null-terminated string of text to draw.
|
|
* @param color The color to draw the text in.
|
|
* @param tileset Font tileset to use for rendering.
|
|
* @param texture Texture containing the font tileset image.
|
|
* @return Either an error or success result.
|
|
*/
|
|
errorret_t textDraw(
|
|
const float_t x,
|
|
const float_t y,
|
|
const char_t *text,
|
|
const color_t color,
|
|
const tileset_t *tileset,
|
|
texture_t *texture
|
|
);
|
|
|
|
/**
|
|
* Measures the width and height of the given text string when rendered.
|
|
*
|
|
* @param text The null-terminated string of text to measure.
|
|
* @param tileset Font tileset to use for measurement.
|
|
* @param outWidth Pointer to store the measured width in pixels.
|
|
* @param outHeight Pointer to store the measured height in pixels.
|
|
*/
|
|
void textMeasure(
|
|
const char_t *text,
|
|
const tileset_t *tileset,
|
|
int32_t *outWidth,
|
|
int32_t *outHeight
|
|
); |