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