🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.3 KiB

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