SDL 3.0
SDL_test_font.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * \file SDL_test_font.h
24 *
25 * Font related functions of SDL test framework.
26 *
27 * This code is a part of the SDL test library, not the main SDL library.
28 */
29
30#ifndef SDL_test_font_h_
31#define SDL_test_font_h_
32
33#include <SDL3/SDL_begin_code.h>
34/* Set up for C function definitions, even when using C++ */
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* Function prototypes */
40
41extern int FONT_CHARACTER_SIZE;
42
43#define FONT_LINE_HEIGHT (FONT_CHARACTER_SIZE + 2)
44
45/**
46 * Draw a string in the currently set font.
47 *
48 * \param renderer The renderer to draw on.
49 * \param x The X coordinate of the upper left corner of the character.
50 * \param y The Y coordinate of the upper left corner of the character.
51 * \param c The character to draw.
52 *
53 * \returns 0 on success, -1 on failure.
54 */
55int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c);
56
57/**
58 * Draw a UTF-8 string in the currently set font.
59 *
60 * The font currently only supports characters in the Basic Latin and Latin-1 Supplement sets.
61 *
62 * \param renderer The renderer to draw on.
63 * \param x The X coordinate of the upper left corner of the string.
64 * \param y The Y coordinate of the upper left corner of the string.
65 * \param s The string to draw.
66 *
67 * \returns 0 on success, -1 on failure.
68 */
69int SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s);
70
71/**
72 * Data used for multi-line text output
73 */
81
82/**
83 * Create a multi-line text output window
84 *
85 * \param x The X coordinate of the upper left corner of the window.
86 * \param y The Y coordinate of the upper left corner of the window.
87 * \param w The width of the window (currently ignored)
88 * \param h The height of the window (currently ignored)
89 *
90 * \returns the new window, or NULL on failure.
91 *
92 * \since This function is available since SDL 3.0.0.
93 */
94SDLTest_TextWindow *SDLTest_TextWindowCreate(float x, float y, float w, float h);
95
96/**
97 * Display a multi-line text output window
98 *
99 * This function should be called every frame to display the text
100 *
101 * \param textwin The text output window
102 * \param renderer The renderer to use for display
103 *
104 * \since This function is available since SDL 3.0.0.
105 */
107
108/**
109 * Add text to a multi-line text output window
110 *
111 * Adds UTF-8 text to the end of the current text. The newline character starts a
112 * new line of text. The backspace character deletes the last character or, if the
113 * line is empty, deletes the line and goes to the end of the previous line.
114 *
115 * \param textwin The text output window
116 * \param fmt A printf() style format string
117 * \param ... additional parameters matching % tokens in the `fmt` string, if any
118 *
119 * \since This function is available since SDL 3.0.0.
120 */
122
123/**
124 * Add text to a multi-line text output window
125 *
126 * Adds UTF-8 text to the end of the current text. The newline character starts a
127 * new line of text. The backspace character deletes the last character or, if the
128 * line is empty, deletes the line and goes to the end of the previous line.
129 *
130 * \param textwin The text output window
131 * \param text The text to add to the window
132 * \param len The length, in bytes, of the text to add to the window
133 *
134 * \since This function is available since SDL 3.0.0.
135 */
136void SDLTest_TextWindowAddTextWithLength(SDLTest_TextWindow *textwin, const char *text, size_t len);
137
138/**
139 * Clear the text in a multi-line text output window
140 *
141 * \param textwin The text output window
142 *
143 * \since This function is available since SDL 3.0.0.
144 */
146
147/**
148 * Free the storage associated with a multi-line text output window
149 *
150 * \param textwin The text output window
151 *
152 * \since This function is available since SDL 3.0.0.
153 */
155
156/**
157 * Cleanup textures used by font drawing functions.
158 */
160
161/* Ends C function definitions when using C++ */
162#ifdef __cplusplus
163}
164#endif
165#include <SDL3/SDL_close_code.h>
166
167#endif /* SDL_test_font_h_ */
struct SDL_Renderer SDL_Renderer
Definition SDL_render.h:134
#define SDL_PRINTF_FORMAT_STRING
Definition SDL_stdinc.h:315
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:326
uint32_t Uint32
Definition SDL_stdinc.h:173
int SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s)
void SDLTest_TextWindowAddText(SDLTest_TextWindow *textwin, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
void SDLTest_TextWindowClear(SDLTest_TextWindow *textwin)
void SDLTest_TextWindowDestroy(SDLTest_TextWindow *textwin)
SDLTest_TextWindow * SDLTest_TextWindowCreate(float x, float y, float w, float h)
int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
void SDLTest_TextWindowAddTextWithLength(SDLTest_TextWindow *textwin, const char *text, size_t len)
int FONT_CHARACTER_SIZE
void SDLTest_TextWindowDisplay(SDLTest_TextWindow *textwin, SDL_Renderer *renderer)
void SDLTest_CleanupTextDrawing(void)