From c51682ca16ca6dd508fc00ef5ca08413da999356 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 19 Nov 2012 20:38:52 -0800 Subject: [PATCH] Added code to testwm2 to test the system cursor support --- include/SDL_mouse.h | 1 + test/testwm2.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/SDL_mouse.h b/include/SDL_mouse.h index 8bf1f61ac..e0cb8e625 100644 --- a/include/SDL_mouse.h +++ b/include/SDL_mouse.h @@ -75,6 +75,7 @@ typedef enum SDL_SYSTEM_CURSOR_SIZEALL, // Four pointed arrow pointing north, south, east, and west SDL_SYSTEM_CURSOR_NO, // Slashed circle or crossbones SDL_SYSTEM_CURSOR_HAND, // Hand + SDL_NUM_SYSTEM_CURSORS } SDL_SystemCursor; /* Function prototypes */ diff --git a/test/testwm2.c b/test/testwm2.c index 53eabad9b..366e86f38 100644 --- a/test/testwm2.c +++ b/test/testwm2.c @@ -28,8 +28,26 @@ quit(int rc) int main(int argc, char *argv[]) { + static const char *cursorNames[] = { + "arrow", + "ibeam", + "wait", + "crosshair", + "waitarrow", + "sizeNWSE", + "sizeNESW", + "sizeWE", + "sizeNS", + "sizeALL", + "NO", + "hand", + }; + SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS); + int i, done; SDL_Event event; + int system_cursor = -1; + SDL_Cursor *cursor = NULL; /* Initialize test framework */ state = CommonCreateState(argv, SDL_INIT_VIDEO); @@ -73,8 +91,33 @@ main(int argc, char *argv[]) } } } + if (event.type == SDL_KEYUP) { + SDL_bool updateCursor = SDL_FALSE; + + if (event.key.keysym.sym == SDLK_LEFT) { + --system_cursor; + if (system_cursor < 0) { + system_cursor = SDL_NUM_SYSTEM_CURSORS - 1; + } + updateCursor = SDL_TRUE; + } else if (event.key.keysym.sym == SDLK_RIGHT) { + ++system_cursor; + if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) { + system_cursor = 0; + } + updateCursor = SDL_TRUE; + } + if (updateCursor) { + SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]); + SDL_FreeCursor(cursor); + cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor); + SDL_SetCursor(cursor); + } + } } } + SDL_FreeCursor(cursor); + quit(0); // keep the compiler happy ... return(0);