Added code to testwm2 to test the system cursor support
authorSam Lantinga <slouken@libsdl.org>
Mon, 19 Nov 2012 20:38:52 -0800
changeset 6677c3202c29e352
parent 6676 4ff261ffaa42
child 6678 afb9be20f8d2
Added code to testwm2 to test the system cursor support
include/SDL_mouse.h
test/testwm2.c
     1.1 --- a/include/SDL_mouse.h	Mon Nov 19 20:27:08 2012 -0800
     1.2 +++ b/include/SDL_mouse.h	Mon Nov 19 20:38:52 2012 -0800
     1.3 @@ -75,6 +75,7 @@
     1.4      SDL_SYSTEM_CURSOR_SIZEALL,   // Four pointed arrow pointing north, south, east, and west
     1.5      SDL_SYSTEM_CURSOR_NO,        // Slashed circle or crossbones
     1.6      SDL_SYSTEM_CURSOR_HAND,      // Hand
     1.7 +    SDL_NUM_SYSTEM_CURSORS
     1.8  } SDL_SystemCursor;
     1.9  
    1.10  /* Function prototypes */
     2.1 --- a/test/testwm2.c	Mon Nov 19 20:27:08 2012 -0800
     2.2 +++ b/test/testwm2.c	Mon Nov 19 20:38:52 2012 -0800
     2.3 @@ -28,8 +28,26 @@
     2.4  int
     2.5  main(int argc, char *argv[])
     2.6  {
     2.7 +    static const char *cursorNames[] = {
     2.8 +        "arrow",
     2.9 +        "ibeam",
    2.10 +        "wait",
    2.11 +        "crosshair",
    2.12 +        "waitarrow",
    2.13 +        "sizeNWSE",
    2.14 +        "sizeNESW",
    2.15 +        "sizeWE",
    2.16 +        "sizeNS",
    2.17 +        "sizeALL",
    2.18 +        "NO",
    2.19 +        "hand",
    2.20 +    };
    2.21 +    SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
    2.22 +
    2.23      int i, done;
    2.24      SDL_Event event;
    2.25 +    int system_cursor = -1;
    2.26 +    SDL_Cursor *cursor = NULL;
    2.27  
    2.28      /* Initialize test framework */
    2.29      state = CommonCreateState(argv, SDL_INIT_VIDEO);
    2.30 @@ -73,8 +91,33 @@
    2.31                      }
    2.32                  }
    2.33              }
    2.34 +            if (event.type == SDL_KEYUP) {
    2.35 +                SDL_bool updateCursor = SDL_FALSE;
    2.36 +
    2.37 +                if (event.key.keysym.sym == SDLK_LEFT) {
    2.38 +                    --system_cursor;
    2.39 +                    if (system_cursor < 0) {
    2.40 +                        system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
    2.41 +                    }
    2.42 +                    updateCursor = SDL_TRUE;
    2.43 +                } else if (event.key.keysym.sym == SDLK_RIGHT) {
    2.44 +                    ++system_cursor;
    2.45 +                    if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
    2.46 +                        system_cursor = 0;
    2.47 +                    }
    2.48 +                    updateCursor = SDL_TRUE;
    2.49 +                }
    2.50 +                if (updateCursor) {
    2.51 +                    SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
    2.52 +                    SDL_FreeCursor(cursor);
    2.53 +                    cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
    2.54 +                    SDL_SetCursor(cursor);
    2.55 +                }
    2.56 +            }
    2.57          }
    2.58      }
    2.59 +    SDL_FreeCursor(cursor);
    2.60 +
    2.61      quit(0);
    2.62  	// keep the compiler happy ...
    2.63  	return(0);