SDL_test_font.h 5.4 KB

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