Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added code to testwm2 to test the system cursor support
  • Loading branch information
slouken committed Nov 20, 2012
1 parent 2f7a678 commit c51682c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/SDL_mouse.h
Expand Up @@ -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 */
Expand Down
43 changes: 43 additions & 0 deletions test/testwm2.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c51682c

Please sign in to comment.