From 56c88c4531a59bdd1f612bbfab00f54b85415ad9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 4 Oct 2016 04:08:02 -0700 Subject: [PATCH] Modified the custom cursor test to be able to load BMP files as cursors --- test/testcustomcursor.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/testcustomcursor.c b/test/testcustomcursor.c index e6db781d8..88b5c322d 100644 --- a/test/testcustomcursor.c +++ b/test/testcustomcursor.c @@ -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[]) { @@ -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); @@ -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)); @@ -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 */