Navigation Menu

Skip to content

Commit

Permalink
Modified the custom cursor test to be able to load BMP files as cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 4, 2016
1 parent a21a227 commit 56c88c4
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions test/testcustomcursor.c
Expand Up @@ -67,6 +67,18 @@ static const char *arrow[] = {
"0,0"
};

static SDL_Cursor*
init_color_cursor(const char *file)
{
SDL_Cursor *cursor = NULL;
SDL_Surface *surface = SDL_LoadBMP(file);
if (surface) {
cursor = SDL_CreateColorCursor(surface, 0, 0);
SDL_FreeSurface(surface);
}
return cursor;
}

static SDL_Cursor*
init_system_cursor(const char *image[])
{
Expand Down Expand Up @@ -140,6 +152,7 @@ int
main(int argc, char *argv[])
{
int i;
const char *color_cursor = NULL;

/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
Expand All @@ -154,7 +167,8 @@ main(int argc, char *argv[])

consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
consumed = -1;
color_cursor = argv[i];
break;
}
if (consumed < 0) {
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
Expand All @@ -173,7 +187,15 @@ main(int argc, char *argv[])
SDL_RenderClear(renderer);
}

cursor = init_system_cursor(arrow);
if (color_cursor) {
cursor = init_color_cursor(color_cursor);
} else {
cursor = init_system_cursor(arrow);
}
if (!cursor) {
SDL_Log("Error, couldn't create cursor\n");
quit(2);
}
SDL_SetCursor(cursor);

/* Main render loop */
Expand Down

0 comments on commit 56c88c4

Please sign in to comment.