Handle missing cursor support correctly (#153)

* Fixes whitespaces

* Fix DEBUG builds for odroid xu4

* Fixes log filename and adds flag to Makefile

* More whitespace

* Keeps cursor disabled if unsupported

Without these changes, the cursor will be activated but not drawn.
This commit disables the cursor if implementation for current gfx is
missing.
Moreover, the cursorSurface will be freed after use.
This commit is contained in:
bspinner 2017-11-14 21:42:09 +01:00 committed by Dimitris Panokostas
parent 05b4193a99
commit 6e0ab8ae90
4 changed files with 71 additions and 33 deletions

View file

@ -100,12 +100,12 @@ void logging_init(void)
debugfile = 0;
}
sprintf(debugfilename, "%s/uae4arm_log.txt", start_path_data);
sprintf(debugfilename, "%s/amiberry_log.txt", start_path_data);
if (!debugfile)
debugfile = fopen(debugfilename, "wt");
first++;
write_log("UAE4ARM Logfile\n\n");
write_log("AMIBERRY Logfile\n\n");
#endif
}

View file

@ -156,7 +156,7 @@ void InGameMessage(const char* msg)
// Now we let the Gui object draw itself.
msg_gui->draw();
// Finally we update the screen.
if (!drawn)
if (!drawn && cursor != nullptr)
{
SDL_ShowCursor(SDL_ENABLE);
updatedisplayarea();

View file

@ -187,26 +187,47 @@ void UpdateGuiScreen()
namespace sdl
{
void gui_init()
// Sets the cursor image up
void setup_cursor()
{
//-------------------------------------------------
// Create new screen for GUI
//-------------------------------------------------
// Detect resolution and load appropiate cursor image
if (sdlMode.w > 1280)
{
// High resolution detected, we'll use a double-size cursor
cursorSurface = SDL_LoadBMP("data/cursor-x2.bmp");
}
else
{
cursorSurface = SDL_LoadBMP("data/cursor.bmp");
}
if (cursorSurface)
if (cursorSurface == nullptr)
{
cursor = SDL_CreateColorCursor(cursorSurface, 0, 0);
SDL_SetCursor(cursor);
// Load failed. Log error.
cout << "Could not load cursor bitmap: " << SDL_GetError() << endl;
return;
}
// Create new cursor with surface
cursor = SDL_CreateColorCursor(cursorSurface, 0, 0);
if (cursor == nullptr)
{
// Cursor creation failed. Log error and free surface
cout << "Could not create color cursor: " << SDL_GetError() << endl;
SDL_FreeSurface(cursorSurface);
cursorSurface = nullptr;
return;
}
SDL_SetCursor(cursor);
}
void gui_init()
{
//-------------------------------------------------
// Create new screen for GUI
//-------------------------------------------------
setup_cursor();
// make the scaled rendering look smoother (linear scaling).
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
@ -218,7 +239,10 @@ namespace sdl
gui_texture = SDL_CreateTextureFromSurface(renderer, gui_screen);
check_error_sdl(gui_texture == nullptr, "Unable to create texture");
SDL_ShowCursor(SDL_ENABLE);
if (cursor)
{
SDL_ShowCursor(SDL_ENABLE);
}
//-------------------------------------------------
// Create helpers for guisan
@ -250,6 +274,12 @@ namespace sdl
if (cursor)
{
SDL_FreeCursor(cursor);
cursor = nullptr;
}
if (cursorSurface)
{
SDL_FreeSurface(cursorSurface);
cursorSurface = nullptr;
}
gui_screen = nullptr;
}