Skip to content

Commit

Permalink
BACKENDS: Fix GraphicsManager handling of empty cursors
Browse files Browse the repository at this point in the history
The SDL graphics manager was just ignoring calls from CursorMan to
set the cursor to a blank cursor, which meant engines that did not
immediately send a cursor to CursorMan at startup would still show
the launcher's cursor (usually with a broken palette).

The OpenGL graphics manager would try to generate and draw an
invalid cursor surface when receiving an empty cursor.
  • Loading branch information
csnover committed Oct 15, 2017
1 parent da0a8db commit 5d8cf6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
17 changes: 12 additions & 5 deletions backends/graphics/opengl/opengl-graphics.cpp
Expand Up @@ -567,6 +567,18 @@ void applyColorKey(DstPixel *dst, const SrcPixel *src, uint w, uint h, uint dstP
} // End of anonymous namespace

void OpenGLGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {

_cursorKeyColor = keycolor;
_cursorHotspotX = hotspotX;
_cursorHotspotY = hotspotY;
_cursorDontScale = dontScale;

if (!w || !h) {
delete _cursor;
_cursor = nullptr;
return;
}

Graphics::PixelFormat inputFormat;
#ifdef USE_RGB_COLOR
if (format) {
Expand Down Expand Up @@ -602,11 +614,6 @@ void OpenGLGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int
_cursor->enableLinearFiltering(_currentState.filtering);
}

_cursorKeyColor = keycolor;
_cursorHotspotX = hotspotX;
_cursorHotspotY = hotspotY;
_cursorDontScale = dontScale;

_cursor->allocate(w, h);
if (inputFormat.bytesPerPixel == 1) {
// For CLUT8 cursors we can simply copy the input data into the
Expand Down
26 changes: 13 additions & 13 deletions backends/graphics/surfacesdl/surfacesdl-graphics.cpp
Expand Up @@ -1876,9 +1876,6 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
assert(keycolor <= 0xFF);
#endif

if (w == 0 || h == 0)
return;

_mouseCurState.hotX = hotspot_x;
_mouseCurState.hotY = hotspot_y;

Expand All @@ -1890,6 +1887,10 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
_mouseCurState.w = w;
_mouseCurState.h = h;

if (!w || !h) {
return;
}

if (_mouseOrigSurface)
SDL_FreeSurface(_mouseOrigSurface);

Expand Down Expand Up @@ -1928,22 +1929,21 @@ void SurfaceSdlGraphicsManager::blitCursor() {
#else
byte color;
#endif
int w, h, i, j;

if (!_mouseOrigSurface || !_mouseData)
int w = _mouseCurState.w;
int h = _mouseCurState.h;

if (!_mouseOrigSurface || !_mouseData || !w || !h)
return;

_cursorNeedsRedraw = true;

w = _mouseCurState.w;
h = _mouseCurState.h;

SDL_LockSurface(_mouseOrigSurface);

// Make whole surface transparent
for (i = 0; i < h + 2; i++) {
for (int i = 0; i < h + 2; i++) {
dstPtr = (byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * i;
for (j = 0; j < w + 2; j++) {
for (int j = 0; j < w + 2; j++) {
*(uint16 *)dstPtr = kMouseColorKey;
dstPtr += 2;
}
Expand All @@ -1959,8 +1959,8 @@ void SurfaceSdlGraphicsManager::blitCursor() {
else
palette = _cursorPalette;

for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
#ifdef USE_RGB_COLOR
if (_cursorFormat.bytesPerPixel > 1) {
if (_cursorFormat.bytesPerPixel == 2)
Expand Down Expand Up @@ -2112,7 +2112,7 @@ void SurfaceSdlGraphicsManager::undrawMouse() {
}

void SurfaceSdlGraphicsManager::drawMouse() {
if (!_cursorVisible || !_mouseSurface) {
if (!_cursorVisible || !_mouseSurface || !_mouseCurState.w || !_mouseCurState.h) {
_mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0;
return;
}
Expand Down

0 comments on commit 5d8cf6b

Please sign in to comment.