testwm2: draw various debug logging into the window itself Renderer output size, window position/size, display bounds, etc. Uses new SDLTest_CommonDrawWindowInfo function in test_common.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h
index 6e4344f..8a92c05 100644
--- a/include/SDL_test_common.h
+++ b/include/SDL_test_common.h
@@ -206,6 +206,14 @@ void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *do
*/
void SDLTest_CommonQuit(SDLTest_CommonState * state);
+/**
+ * \brief Draws various window information (position, size, etc.) to the renderer.
+ *
+ * \param renderer The renderer to draw to.
+ * \param window The window whose information should be displayed.
+ *
+ */
+void SDLTest_CommonDrawWindowInfo(SDL_Renderer * renderer, SDL_Window * window);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 0b5bc0e..9ff04c5 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -630,6 +630,170 @@ SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **arg
}
static void
+SDLTest_PrintDisplayOrientation(char* text, size_t maxlen, SDL_DisplayOrientation orientation)
+{
+ switch (orientation) {
+ case SDL_ORIENTATION_UNKNOWN:
+ SDL_snprintfcat(text, maxlen, "UNKNOWN");
+ break;
+ case SDL_ORIENTATION_LANDSCAPE:
+ SDL_snprintfcat(text, maxlen, "LANDSCAPE");
+ break;
+ case SDL_ORIENTATION_LANDSCAPE_FLIPPED:
+ SDL_snprintfcat(text, maxlen, "LANDSCAPE_FLIPPED");
+ break;
+ case SDL_ORIENTATION_PORTRAIT:
+ SDL_snprintfcat(text, maxlen, "PORTRAIT");
+ break;
+ case SDL_ORIENTATION_PORTRAIT_FLIPPED:
+ SDL_snprintfcat(text, maxlen, "PORTRAIT_FLIPPED");
+ break;
+ default:
+ SDL_snprintfcat(text, maxlen, "0x%8.8x", orientation);
+ break;
+ }
+}
+
+static void
+SDLTest_PrintWindowFlag(char* text, size_t maxlen, Uint32 flag)
+{
+ switch (flag) {
+ case SDL_WINDOW_FULLSCREEN:
+ SDL_snprintfcat(text, maxlen, "FULLSCREEN");
+ break;
+ case SDL_WINDOW_OPENGL:
+ SDL_snprintfcat(text, maxlen, "OPENGL");
+ break;
+ case SDL_WINDOW_SHOWN:
+ SDL_snprintfcat(text, maxlen, "SHOWN");
+ break;
+ case SDL_WINDOW_HIDDEN:
+ SDL_snprintfcat(text, maxlen, "HIDDEN");
+ break;
+ case SDL_WINDOW_BORDERLESS:
+ SDL_snprintfcat(text, maxlen, "BORDERLESS");
+ break;
+ case SDL_WINDOW_RESIZABLE:
+ SDL_snprintfcat(text, maxlen, "RESIZABLE");
+ break;
+ case SDL_WINDOW_MINIMIZED:
+ SDL_snprintfcat(text, maxlen, "MINIMIZED");
+ break;
+ case SDL_WINDOW_MAXIMIZED:
+ SDL_snprintfcat(text, maxlen, "MAXIMIZED");
+ break;
+ case SDL_WINDOW_MOUSE_GRABBED:
+ SDL_snprintfcat(text, maxlen, "MOUSE_GRABBED");
+ break;
+ case SDL_WINDOW_INPUT_FOCUS:
+ SDL_snprintfcat(text, maxlen, "INPUT_FOCUS");
+ break;
+ case SDL_WINDOW_MOUSE_FOCUS:
+ SDL_snprintfcat(text, maxlen, "MOUSE_FOCUS");
+ break;
+ case SDL_WINDOW_FULLSCREEN_DESKTOP:
+ SDL_snprintfcat(text, maxlen, "FULLSCREEN_DESKTOP");
+ break;
+ case SDL_WINDOW_FOREIGN:
+ SDL_snprintfcat(text, maxlen, "FOREIGN");
+ break;
+ case SDL_WINDOW_ALLOW_HIGHDPI:
+ SDL_snprintfcat(text, maxlen, "ALLOW_HIGHDPI");
+ break;
+ case SDL_WINDOW_MOUSE_CAPTURE:
+ SDL_snprintfcat(text, maxlen, "MOUSE_CAPTURE");
+ break;
+ case SDL_WINDOW_ALWAYS_ON_TOP:
+ SDL_snprintfcat(text, maxlen, "ALWAYS_ON_TOP");
+ break;
+ case SDL_WINDOW_SKIP_TASKBAR:
+ SDL_snprintfcat(text, maxlen, "SKIP_TASKBAR");
+ break;
+ case SDL_WINDOW_UTILITY:
+ SDL_snprintfcat(text, maxlen, "UTILITY");
+ break;
+ case SDL_WINDOW_TOOLTIP:
+ SDL_snprintfcat(text, maxlen, "TOOLTIP");
+ break;
+ case SDL_WINDOW_POPUP_MENU:
+ SDL_snprintfcat(text, maxlen, "POPUP_MENU");
+ break;
+ case SDL_WINDOW_KEYBOARD_GRABBED:
+ SDL_snprintfcat(text, maxlen, "KEYBOARD_GRABBED");
+ break;
+ case SDL_WINDOW_VULKAN:
+ SDL_snprintfcat(text, maxlen, "VULKAN");
+ break;
+ case SDL_WINDOW_METAL:
+ SDL_snprintfcat(text, maxlen, "METAL");
+ break;
+ default:
+ SDL_snprintfcat(text, maxlen, "0x%8.8x", flag);
+ break;
+ }
+}
+
+static void
+SDLTest_PrintWindowFlags(char* text, size_t maxlen, Uint32 flags)
+{
+ const Uint32 window_flags[] = {
+ SDL_WINDOW_FULLSCREEN,
+ SDL_WINDOW_OPENGL,
+ SDL_WINDOW_SHOWN,
+ SDL_WINDOW_HIDDEN,
+ SDL_WINDOW_BORDERLESS,
+ SDL_WINDOW_RESIZABLE,
+ SDL_WINDOW_MINIMIZED,
+ SDL_WINDOW_MAXIMIZED,
+ SDL_WINDOW_MOUSE_GRABBED,
+ SDL_WINDOW_INPUT_FOCUS,
+ SDL_WINDOW_MOUSE_FOCUS,
+ SDL_WINDOW_FULLSCREEN_DESKTOP,
+ SDL_WINDOW_FOREIGN,
+ SDL_WINDOW_ALLOW_HIGHDPI,
+ SDL_WINDOW_MOUSE_CAPTURE,
+ SDL_WINDOW_ALWAYS_ON_TOP,
+ SDL_WINDOW_SKIP_TASKBAR,
+ SDL_WINDOW_UTILITY,
+ SDL_WINDOW_TOOLTIP,
+ SDL_WINDOW_POPUP_MENU,
+ SDL_WINDOW_KEYBOARD_GRABBED,
+ SDL_WINDOW_VULKAN,
+ SDL_WINDOW_METAL
+ };
+
+ int i;
+ int count = 0;
+ for (i = 0; i < (sizeof(window_flags) / sizeof(window_flags[0])); ++i) {
+ const Uint32 flag = window_flags[i];
+ if ((flags & flag) == flag) {
+ if (count > 0) {
+ SDL_snprintfcat(text, maxlen, " | ");
+ }
+ SDLTest_PrintWindowFlag(text, maxlen, flag);
+ ++count;
+ }
+ }
+}
+
+static void
+SDLTest_PrintButtonMask(char* text, size_t maxlen, Uint32 flags)
+{
+ int i;
+ int count = 0;
+ for (i = 1; i <= 32; ++i) {
+ const Uint32 flag = SDL_BUTTON(i);
+ if ((flags & flag) == flag) {
+ if (count > 0) {
+ SDL_snprintfcat(text, maxlen, " | ");
+ }
+ SDL_snprintfcat(text, maxlen, "SDL_BUTTON(%d)", i);
+ ++count;
+ }
+ }
+}
+
+static void
SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag)
{
switch (flag) {
@@ -1990,4 +2154,115 @@ SDLTest_CommonQuit(SDLTest_CommonState * state)
SDLTest_LogAllocations();
}
+void
+SDLTest_CommonDrawWindowInfo(SDL_Renderer * renderer, SDL_Window * window)
+{
+ char text[1024];
+ int textY = 0;
+ const int lineHeight = 10;
+ int x, y, w, h;
+ SDL_Rect rect;
+ SDL_DisplayMode mode;
+ float ddpi, hdpi, vdpi;
+ Uint32 flags;
+ const int windowDisplayIndex = SDL_GetWindowDisplayIndex(window);
+
+ /* Renderer */
+
+ if (0 == SDL_GetRendererOutputSize(renderer, &w, &h)) {
+ SDL_snprintf(text, sizeof(text), "SDL_GetRendererOutputSize: %dx%d", w, h);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+ }
+
+ SDL_RenderGetViewport(renderer, &rect);
+ SDL_snprintf(text, sizeof(text), "SDL_RenderGetViewport: %d,%d, %dx%d",
+ rect.x, rect.y, rect.w, rect.h);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ /* Window */
+
+ SDLTest_DrawString(renderer, 0, textY, "----");
+ textY += lineHeight;
+
+ SDL_GetWindowPosition(window, &x, &y);
+ SDL_snprintf(text, sizeof(text), "SDL_GetWindowPosition: %d,%d", x, y);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ SDL_GetWindowSize(window, &w, &h);
+ SDL_snprintf(text, sizeof(text), "SDL_GetWindowSize: %dx%d", w, h);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ SDL_snprintf(text, sizeof(text), "SDL_GetWindowFlags: ");
+ SDLTest_PrintWindowFlags(text, sizeof(text), SDL_GetWindowFlags(window));
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ /* Display */
+
+ SDLTest_DrawString(renderer, 0, textY, "----");
+ textY += lineHeight;
+
+ SDL_snprintf(text, sizeof(text), "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ SDL_snprintf(text, sizeof(text), "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex));
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ if (0 == SDL_GetDisplayBounds(windowDisplayIndex, &rect)) {
+ SDL_snprintf(text, sizeof(text), "SDL_GetDisplayBounds: %d,%d, %dx%d",
+ rect.x, rect.y, rect.w, rect.h);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+ }
+
+ if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) {
+ SDL_snprintf(text, sizeof(text), "SDL_GetCurrentDisplayMode: %dx%d@%d",
+ mode.w, mode.h, mode.refresh_rate);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+ }
+
+ if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) {
+ SDL_snprintf(text, sizeof(text), "SDL_GetDesktopDisplayMode: %dx%d@%d",
+ mode.w, mode.h, mode.refresh_rate);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+ }
+
+ if (0 == SDL_GetDisplayDPI(windowDisplayIndex, &ddpi, &hdpi, &vdpi)) {
+ SDL_snprintf(text, sizeof(text), "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f",
+ ddpi, hdpi, vdpi);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+ }
+
+ SDL_snprintf(text, sizeof(text), "SDL_GetDisplayOrientation: ");
+ SDLTest_PrintDisplayOrientation(text, sizeof(text), SDL_GetDisplayOrientation(windowDisplayIndex));
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ /* Mouse */
+
+ SDLTest_DrawString(renderer, 0, textY, "----");
+ textY += lineHeight;
+
+ flags = SDL_GetMouseState(&x, &y);
+ SDL_snprintf(text, sizeof(text), "SDL_GetMouseState: %d,%d ", x, y);
+ SDLTest_PrintButtonMask(text, sizeof(text), flags);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+
+ flags = SDL_GetGlobalMouseState(&x, &y);
+ SDL_snprintf(text, sizeof(text), "SDL_GetGlobalMouseState: %d,%d ", x, y);
+ SDLTest_PrintButtonMask(text, sizeof(text), flags);
+ SDLTest_DrawString(renderer, 0, textY, text);
+ textY += lineHeight;
+}
+
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/test/testwm2.c b/test/testwm2.c
index d849283..1dc6635 100644
--- a/test/testwm2.c
+++ b/test/testwm2.c
@@ -105,7 +105,12 @@ loop()
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (renderer != NULL) {
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
+
+ SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
+ SDLTest_CommonDrawWindowInfo(renderer, state->windows[i]);
+
SDL_RenderPresent(renderer);
}
}