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_stdinc.h>
34#include <SDL3/SDL_rect.h>
35#include <SDL3/SDL_render.h>
36
37#include <SDL3/SDL_begin_code.h>
38/* Set up for C function definitions, even when using C++ */
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* Function prototypes */
44
45extern int FONT_CHARACTER_SIZE;
46
47#define FONT_LINE_HEIGHT (FONT_CHARACTER_SIZE + 2)
48
49/*
50 * Draw a string in the currently set font.
51 *
52 * \param renderer The renderer to draw on.
53 * \param x The X coordinate of the upper left corner of the character.
54 * \param y The Y coordinate of the upper left corner of the character.
55 * \param c The character to draw.
56 *
57 * \returns SDL_TRUE on success, SDL_FALSE on failure.
58 */
59SDL_bool SDLCALL SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c);
60
61/*
62 * Draw a UTF-8 string in the currently set font.
63 *
64 * The font currently only supports characters in the Basic Latin and Latin-1 Supplement sets.
65 *
66 * \param renderer The renderer to draw on.
67 * \param x The X coordinate of the upper left corner of the string.
68 * \param y The Y coordinate of the upper left corner of the string.
69 * \param s The string to draw.
70 *
71 * \returns SDL_TRUE on success, SDL_FALSE on failure.
72 */
73SDL_bool SDLCALL SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s);
74
75/*
76 * Data used for multi-line text output
77 */
85
86/*
87 * Create a multi-line text output window
88 *
89 * \param x The X coordinate of the upper left corner of the window.
90 * \param y The Y coordinate of the upper left corner of the window.
91 * \param w The width of the window (currently ignored)
92 * \param h The height of the window (currently ignored)
93 *
94 * \returns the new window, or NULL on failure.
95 *
96 * \since This function is available since SDL 3.0.0.
97 */
98SDLTest_TextWindow * SDLCALL SDLTest_TextWindowCreate(float x, float y, float w, float h);
99
100/*
101 * Display a multi-line text output window
102 *
103 * This function should be called every frame to display the text
104 *
105 * \param textwin The text output window
106 * \param renderer The renderer to use for display
107 *
108 * \since This function is available since SDL 3.0.0.
109 */
111
112/*
113 * Add text to a multi-line text output window
114 *
115 * Adds UTF-8 text to the end of the current text. The newline character starts a
116 * new line of text. The backspace character deletes the last character or, if the
117 * line is empty, deletes the line and goes to the end of the previous line.
118 *
119 * \param textwin The text output window
120 * \param fmt A printf() style format string
121 * \param ... additional parameters matching % tokens in the `fmt` string, if any
122 *
123 * \since This function is available since SDL 3.0.0.
124 */
126
127/*
128 * Add text to a multi-line text output window
129 *
130 * Adds UTF-8 text to the end of the current text. The newline character starts a
131 * new line of text. The backspace character deletes the last character or, if the
132 * line is empty, deletes the line and goes to the end of the previous line.
133 *
134 * \param textwin The text output window
135 * \param text The text to add to the window
136 * \param len The length, in bytes, of the text to add to the window
137 *
138 * \since This function is available since SDL 3.0.0.
139 */
140void SDLCALL SDLTest_TextWindowAddTextWithLength(SDLTest_TextWindow *textwin, const char *text, size_t len);
141
142/*
143 * Clear the text in a multi-line text output window
144 *
145 * \param textwin The text output window
146 *
147 * \since This function is available since SDL 3.0.0.
148 */
150
151/*
152 * Free the storage associated with a multi-line text output window
153 *
154 * \param textwin The text output window
155 *
156 * \since This function is available since SDL 3.0.0.
157 */
159
160/*
161 * Cleanup textures used by font drawing functions.
162 */
163void SDLCALL SDLTest_CleanupTextDrawing(void);
164
165/* Ends C function definitions when using C++ */
166#ifdef __cplusplus
167}
168#endif
169#include <SDL3/SDL_close_code.h>
170
171#endif /* SDL_test_font_h_ */
struct SDL_Renderer SDL_Renderer
Definition SDL_render.h:119
#define SDL_PRINTF_FORMAT_STRING
Definition SDL_stdinc.h:532
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:543
uint32_t Uint32
Definition SDL_stdinc.h:353
bool SDL_bool
Definition SDL_stdinc.h:301
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)
SDL_bool SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s)
void SDLTest_TextWindowAddTextWithLength(SDLTest_TextWindow *textwin, const char *text, size_t len)
SDL_bool SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c)
int FONT_CHARACTER_SIZE
void SDLTest_TextWindowDisplay(SDLTest_TextWindow *textwin, SDL_Renderer *renderer)
void SDLTest_CleanupTextDrawing(void)