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