77 lines
1.8 KiB
C
77 lines
1.8 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/text/font.h"
|
|
#include "display/spritebatch/spritebatch.h"
|
|
|
|
#define TEXT_CHAR_START '!'
|
|
|
|
extern font_t FONT_DEFAULT;
|
|
|
|
/**
|
|
* 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);
|
|
|
|
/**
|
|
* Builds a sprite for a single character at the given position.
|
|
*
|
|
* @param pos The (x, y) position of the character in screen/world space.
|
|
* @param c The character to build a sprite for.
|
|
* @param font Font to use for tile lookup.
|
|
* @return The populated sprite ready for spriteBatchBuffer.
|
|
*/
|
|
spritebatchsprite_t textGetSprite(
|
|
const vec2 pos,
|
|
const char_t c,
|
|
const font_t *font
|
|
);
|
|
|
|
/**
|
|
* 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 font Font to use for rendering.
|
|
* @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,
|
|
font_t *font
|
|
);
|
|
|
|
/**
|
|
* Measures the width and height of the given text string when rendered.
|
|
*
|
|
* @param text The null-terminated string of text to measure.
|
|
* @param font Font 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 font_t *font,
|
|
int32_t *outWidth,
|
|
int32_t *outHeight
|
|
);
|