diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 1a80b9be19b..fadd7a376c7 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1403,6 +1403,49 @@ void OSystem_SDL::warpMouse(int x, int y) { } } +#ifdef ENABLE_16BIT +void OSystem_SDL::setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale) { + if (w == 0 || h == 0) + return; + + _mouseCurState.hotX = hotspot_x; + _mouseCurState.hotY = hotspot_y; + + _mouseKeyColor = keycolor; + + _cursorTargetScale = cursorTargetScale; + + if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h) { + _mouseCurState.w = w; + _mouseCurState.h = h; + + if (_mouseOrigSurface) + SDL_FreeSurface(_mouseOrigSurface); + + // Allocate bigger surface because AdvMame2x adds black pixel at [0,0] + _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, + _mouseCurState.w + 2, + _mouseCurState.h + 2, + 16, + _hwscreen->format->Rmask, + _hwscreen->format->Gmask, + _hwscreen->format->Bmask, + _hwscreen->format->Amask); + + if (_mouseOrigSurface == NULL) + error("allocating _mouseOrigSurface failed"); + SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey); + } + + free(_mouseData); + + _mouseData = (byte *)malloc(w * h * 2); + memcpy(_mouseData, buf, w * h * 2); + + blitCursor(); +} +#endif + void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { if (w == 0 || h == 0) return; @@ -1438,13 +1481,9 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, free(_mouseData); -#ifdef ENABLE_16BIT - _mouseData = (byte *)malloc(w * h * 2); - memcpy(_mouseData, buf, w * h * 2); -#else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); -#endif + blitCursor(); } diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index f8430667499..3e0bf19f8fd 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -112,6 +112,10 @@ public: virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) // Set the bitmap that's used when drawing the cursor. +#ifdef ENABLE_16BIT + //HACK Made a second method as a quick and dirty workaround to avoid linker errors with engine libs + virtual void setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) +#endif virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) // Set colors of cursor palette diff --git a/common/system.h b/common/system.h index 5b72dab7c13..eb01093049b 100644 --- a/common/system.h +++ b/common/system.h @@ -687,8 +687,13 @@ public: * @param keycolor transparency color index * @param cursorTargetScale scale factor which cursor is designed for */ +#ifdef ENABLE_16BIT + //HACK made a second method as a quick and dirty workaround to avoid linker errors with engine libs + virtual void setMouseCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor = 65535, int cursorTargetScale = 1) = 0; +#endif virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int cursorTargetScale = 1) = 0; + /** * Replace the specified range of cursor the palette with new colors. * The palette entries from 'start' till (start+num-1) will be replaced - so diff --git a/dists/msvc8/scumm.vcproj b/dists/msvc8/scumm.vcproj index 7b7588b0fdd..03e1f9cc395 100644 --- a/dists/msvc8/scumm.vcproj +++ b/dists/msvc8/scumm.vcproj @@ -1,7 +1,7 @@ = 80) ? 5 : 255; - CursorMan.replaceCursor(_grabbedCursor, _cursor.width, _cursor.height, - _cursor.hotspotX, _cursor.hotspotY, - (_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor), - (_game.heversion == 70 ? 2 : 1)); + if (_game.features & GF_16BIT_COLOR && _hePalettes) { + //HACK Had to make a second method to avoid many, many linker errors from other engines + //this requires ENABLE_16BIT to be defined in the Scumm project, again, because I #ifdef'ed + //the method's definition and declaration in cursorman.h + CursorMan.replaceCursor16(_grabbedCursor, _cursor.width, _cursor.height, + _cursor.hotspotX, _cursor.hotspotY, + (_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor), + (_game.heversion == 70 ? 2 : 1)); + } else { + CursorMan.replaceCursor(_grabbedCursor, _cursor.width, _cursor.height, + _cursor.hotspotX, _cursor.hotspotY, + (_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor), + (_game.heversion == 70 ? 2 : 1)); + } } void ScummEngine_v6::grabCursor(int x, int y, int w, int h) { diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp index f303749572c..84578a39118 100644 --- a/graphics/cursorman.cpp +++ b/graphics/cursorman.cpp @@ -100,6 +100,37 @@ void CursorManager::popAllCursors() { g_system->showMouse(isVisible()); } +#ifdef ENABLE_16BIT +//HACK Made a separate method to avoid massive linker errors on every engine +void CursorManager::replaceCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor, int targetScale) { + if (_cursorStack.empty()) { + pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale); + return; + } + + Cursor *cur = _cursorStack.top(); + + uint size = w * h * 2; + + if (cur->_size < size) { + delete[] cur->_data; + cur->_data = new byte[size]; + cur->_size = size; + } + + if (buf && cur->_data) + memcpy(cur->_data, buf, size); + + cur->_width = w; + cur->_height = h; + cur->_hotspotX = hotspotX; + cur->_hotspotY = hotspotY; + cur->_keycolor = keycolor; + cur->_targetScale = targetScale; + + g_system->setMouseCursor16(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale); +} +#endif void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) { if (_cursorStack.empty()) { @@ -108,11 +139,8 @@ void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, } Cursor *cur = _cursorStack.top(); -#ifdef ENABLE_16BIT - uint size = w * h * 2; -#else + uint size = w * h; -#endif if (cur->_size < size) { delete[] cur->_data; diff --git a/graphics/cursorman.h b/graphics/cursorman.h index bc38466eda3..8ad42fe0d47 100644 --- a/graphics/cursorman.h +++ b/graphics/cursorman.h @@ -77,6 +77,10 @@ public: * @param keycolor the index for the transparent color * @param targetScale the scale for which the cursor is designed */ +#ifdef ENABLE_16BIT + //HACK made a separate method to avoid massive linker errors on every engine. + void replaceCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor = 65535, int targetScale = 1); +#endif void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1); /**