testcustomcursor: Allow running without custom or system cursors
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
diff --git a/test/testcustomcursor.c b/test/testcustomcursor.c
index d29c1c5..698d31f 100644
--- a/test/testcustomcursor.c
+++ b/test/testcustomcursor.c
@@ -135,6 +135,8 @@ init_system_cursor(const char *image[])
static SDLTest_CommonState *state;
int done;
static SDL_Cursor *cursors[1+SDL_NUM_SYSTEM_CURSORS];
+static SDL_SystemCursor cursor_types[1+SDL_NUM_SYSTEM_CURSORS];
+static int num_cursors;
static int current_cursor;
static int show_cursor;
@@ -156,32 +158,34 @@ loop()
SDLTest_CommonEvent(state, &event, &done);
if (event.type == SDL_MOUSEBUTTONDOWN) {
if (event.button.button == SDL_BUTTON_LEFT) {
+ if (num_cursors == 0) {
+ continue;
+ }
+
++current_cursor;
- if (current_cursor == SDL_arraysize(cursors)) {
+ if (current_cursor == num_cursors) {
current_cursor = 0;
}
SDL_SetCursor(cursors[current_cursor]);
- if (current_cursor == 0) {
- SDL_Log("Custom cursor");
- } else {
- switch ((SDL_SystemCursor) (current_cursor-1)) {
- case SDL_SYSTEM_CURSOR_ARROW: SDL_Log("Arrow"); break;
- case SDL_SYSTEM_CURSOR_IBEAM: SDL_Log("I-beam"); break;
- case SDL_SYSTEM_CURSOR_WAIT: SDL_Log("Wait"); break;
- case SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_Log("Crosshair"); break;
- case SDL_SYSTEM_CURSOR_WAITARROW: SDL_Log("Small wait cursor (or Wait if not available)"); break;
- case SDL_SYSTEM_CURSOR_SIZENWSE: SDL_Log("Double arrow pointing northwest and southeast"); break;
- case SDL_SYSTEM_CURSOR_SIZENESW: SDL_Log("Double arrow pointing northeast and southwest"); break;
- case SDL_SYSTEM_CURSOR_SIZEWE: SDL_Log("Double arrow pointing west and east"); break;
- case SDL_SYSTEM_CURSOR_SIZENS: SDL_Log("Double arrow pointing north and south"); break;
- case SDL_SYSTEM_CURSOR_SIZEALL: SDL_Log("Four pointed arrow pointing north, south, east, and west"); break;
- case SDL_SYSTEM_CURSOR_NO: SDL_Log("Slashed circle or crossbones"); break;
- case SDL_SYSTEM_CURSOR_HAND: SDL_Log("Hand"); break;
- default: SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM."); break;
- }
+ switch (cursor_types[current_cursor]) {
+ case (SDL_SystemCursor)-1: SDL_Log("Custom cursor"); break;
+ case SDL_SYSTEM_CURSOR_ARROW: SDL_Log("Arrow"); break;
+ case SDL_SYSTEM_CURSOR_IBEAM: SDL_Log("I-beam"); break;
+ case SDL_SYSTEM_CURSOR_WAIT: SDL_Log("Wait"); break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_Log("Crosshair"); break;
+ case SDL_SYSTEM_CURSOR_WAITARROW: SDL_Log("Small wait cursor (or Wait if not available)"); break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE: SDL_Log("Double arrow pointing northwest and southeast"); break;
+ case SDL_SYSTEM_CURSOR_SIZENESW: SDL_Log("Double arrow pointing northeast and southwest"); break;
+ case SDL_SYSTEM_CURSOR_SIZEWE: SDL_Log("Double arrow pointing west and east"); break;
+ case SDL_SYSTEM_CURSOR_SIZENS: SDL_Log("Double arrow pointing north and south"); break;
+ case SDL_SYSTEM_CURSOR_SIZEALL: SDL_Log("Four pointed arrow pointing north, south, east, and west"); break;
+ case SDL_SYSTEM_CURSOR_NO: SDL_Log("Slashed circle or crossbones"); break;
+ case SDL_SYSTEM_CURSOR_HAND: SDL_Log("Hand"); break;
+ default: SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM."); break;
}
+
} else {
show_cursor = !show_cursor;
SDL_ShowCursor(show_cursor);
@@ -240,23 +244,38 @@ main(int argc, char *argv[])
SDL_RenderClear(renderer);
}
+ num_cursors = 0;
+
if (color_cursor) {
- cursors[0] = init_color_cursor(color_cursor);
+ SDL_Cursor *cursor = init_color_cursor(color_cursor);
+ if (cursor) {
+ cursors[num_cursors] = cursor;
+ cursor_types[num_cursors] = (SDL_SystemCursor)-1;
+ num_cursors++;
+ }
} else {
- cursors[0] = init_system_cursor(arrow);
- }
- if (!cursors[0]) {
- SDL_Log("Error, couldn't create cursor\n");
- quit(2);
+ SDL_Cursor *cursor = init_system_cursor(arrow);
+ if (cursor) {
+ cursors[num_cursors] = cursor;
+ cursor_types[num_cursors] = (SDL_SystemCursor)-1;
+ num_cursors++;
+ }
}
+
for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
- cursors[1+i] = SDL_CreateSystemCursor((SDL_SystemCursor)i);
- if (!cursors[1+i]) {
- SDL_Log("Error, couldn't create system cursor %d\n", i);
- quit(2);
+ SDL_Cursor *cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
+ if (cursor) {
+ cursors[num_cursors] = cursor;
+ cursor_types[num_cursors] = i;
+ num_cursors++;
}
}
- SDL_SetCursor(cursors[0]);
+
+ if (num_cursors > 0) {
+ SDL_SetCursor(cursors[0]);
+ }
+
+ show_cursor = SDL_ShowCursor(SDL_QUERY);
/* Main render loop */
done = 0;
@@ -268,7 +287,7 @@ main(int argc, char *argv[])
}
#endif
- for (i = 0; i < SDL_arraysize(cursors); ++i) {
+ for (i = 0; i < num_cursors; ++i) {
SDL_FreeCursor(cursors[i]);
}
quit(0);