SDL_test_font.h 5.4 KB

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