diff options
author | Jody Northup | 2009-06-06 01:16:04 +0000 |
---|---|---|
committer | Jody Northup | 2009-06-06 01:16:04 +0000 |
commit | 56e5920bba753820c457c078237a8c06241302ed (patch) | |
tree | 1cbbb95462b52dfcaa9ae17ee69d412094851f21 /graphics | |
parent | 8ff3a568fa8fe564749080a9af5e20b897933d93 (diff) | |
download | scummvm-rg350-56e5920bba753820c457c078237a8c06241302ed.tar.gz scummvm-rg350-56e5920bba753820c457c078237a8c06241302ed.tar.bz2 scummvm-rg350-56e5920bba753820c457c078237a8c06241302ed.zip |
Corrected cursor display errors introduced by revision 41204, reimplemented 16-bit cursor support in a less hacky, but still temporary way.
svn-id: r41209
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/cursorman.cpp | 96 | ||||
-rw-r--r-- | graphics/cursorman.h | 68 |
2 files changed, 68 insertions, 96 deletions
diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp index 5fe58314b3..00932e55b0 100644 --- a/graphics/cursorman.cpp +++ b/graphics/cursorman.cpp @@ -56,42 +56,34 @@ bool CursorManager::showMouse(bool visible) { // Should work, even if there's just a dummy cursor on the stack. return g_system->showMouse(visible); } -#ifdef ENABLE_16BIT -void CursorManager::pushCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor, int targetScale) { - Cursor16 *cur = new Cursor16(buf, w, h, hotspotX, hotspotY, keycolor, targetScale); - - cur->_visible = isVisible(); - _cursor16Stack.push(cur); - if (buf) { - g_system->setMouseCursor16(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale); - } +void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) { +#ifdef ENABLE_16BIT + pushCursorReal(buf,w,h,hotspotX,hotspotY,keycolor,targetScale,8); } - -void CursorManager::popCursor16() { - if (_cursor16Stack.empty()) - return; - - Cursor16 *cur = _cursor16Stack.pop(); - delete cur; - - if (!_cursorStack.empty()) { - cur = _cursor16Stack.top(); - g_system->setMouseCursor16(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale); +void CursorManager::pushCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, uint8 bitDepth) { + uint32 colmask = 0xFF; + uint8 byteDepth = bitDepth >> 3; + for (int i = byteDepth; i > 1; i--) { + colmask <<= 8; + colmask |= 0xFF; } + keycolor &= colmask; - g_system->showMouse(isVisible()); -} -#endif - -void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) { + Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth); +#else Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale); +#endif cur->_visible = isVisible(); _cursorStack.push(cur); if (buf) { +#ifdef ENABLE_16BIT + g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth); +#else g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale); +#endif } } @@ -104,7 +96,11 @@ void CursorManager::popCursor() { if (!_cursorStack.empty()) { cur = _cursorStack.top(); +#ifdef ENABLE_16BIT + g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale, cur->_bitDepth); +#else g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale); +#endif } g_system->showMouse(isVisible()); @@ -127,47 +123,37 @@ void CursorManager::popAllCursors() { g_system->showMouse(isVisible()); } +void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) { #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()) { - pushCursor16(buf, w, h, hotspotX, hotspotY, keycolor, targetScale); - return; - } - - Cursor *cur = _cursorStack.top(); - - uint size = w * h * 2; + replaceCursorReal(buf,w,h,hotspotX,hotspotY,keycolor,targetScale); +} - if (cur->_size < size) { - delete[] cur->_data; - cur->_data = new byte[size]; - cur->_size = size; +void CursorManager::replaceCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, uint8 bitDepth) { + uint32 colmask = 0xFF; + uint8 byteDepth = bitDepth >> 3; + for (int i = byteDepth; i > 1; i--) { + colmask <<= 8; + colmask |= 0xFF; } + keycolor &= colmask; - 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()) { +#ifdef ENABLE_16BIT + pushCursorReal(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth); +#else pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale); +#endif return; } Cursor *cur = _cursorStack.top(); +#ifdef ENABLE_16BIT + uint size = w * h * (bitDepth >> 3); +#else uint size = w * h; +#endif if (cur->_size < size) { delete[] cur->_data; @@ -185,7 +171,11 @@ void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, cur->_keycolor = keycolor; cur->_targetScale = targetScale; +#ifdef ENABLE_16BIT + g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale, bitDepth); +#else g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale); +#endif } void CursorManager::disableCursorPalette(bool disable) { diff --git a/graphics/cursorman.h b/graphics/cursorman.h index b54ef31439..481567bb09 100644 --- a/graphics/cursorman.h +++ b/graphics/cursorman.h @@ -57,6 +57,9 @@ public: * cursor will be added to the stack, but not to the backend. */ void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1); +#ifdef ENABLE_16BIT + void pushCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, uint8 bitDepth = 8); +#endif /** * Pop a cursor from the stack, and restore the previous one to the @@ -64,13 +67,6 @@ public: */ void popCursor(); -#ifdef ENABLE_16BIT - //HACK This is such a incredible hack - //I really need to make the one method - //work under multiple bitdepths - void pushCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor = 65535, int targetScale = 1); - void popCursor16(); -#endif /** * Replace the current cursor on the stack. If the stack is empty, the * cursor is pushed instead. It's a slightly more optimized way of @@ -84,11 +80,11 @@ public: * @param keycolor the index for the transparent color * @param targetScale the scale for which the cursor is designed */ + void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1); #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); + void replaceCursorReal(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, uint8 bitDepth = 8); #endif - void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1); /** * Pop all of the cursors and cursor palettes from their respective stacks. @@ -144,37 +140,7 @@ public: private: friend class Common::Singleton<SingletonBaseType>; CursorManager(); -#ifdef ENABLE_16BIT - struct Cursor16 { - byte *_data; - bool _visible; - uint _width; - uint _height; - int _hotspotX; - int _hotspotY; - uint16 _keycolor; - byte _targetScale; - - uint _size; - Cursor16(const byte *data, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor = 65535, int targetScale = 1) { - _size = w * h * 2; - _data = new byte[_size]; - if (data && _data) - memcpy(_data, data, _size); - _width = w; - _height = h; - _hotspotX = hotspotX; - _hotspotY = hotspotY; - _keycolor = keycolor; - _targetScale = targetScale; - } - - ~Cursor16() { - delete[] _data; - } - }; -#endif struct Cursor { byte *_data; bool _visible; @@ -182,13 +148,33 @@ private: uint _height; int _hotspotX; int _hotspotY; +#ifdef ENABLE_16BIT + uint32 _keycolor; + uint8 _bitDepth; +#else byte _keycolor; +#endif byte _targetScale; + uint _size; +#ifdef ENABLE_16BIT + Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, uint8 bitDepth = 8) { + uint32 colmask = 0xFF; + uint8 byteDepth = bitDepth >> 3; + _size = w * h * byteDepth; + _bitDepth = bitDepth; + for (int i = byteDepth; i > 1; i--) { + colmask <<= 8; + colmask |= 0xFF; + } + _keycolor = keycolor & colmask; +#else Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1) { _size = w * h; + _keycolor = keycolor; +#endif _data = new byte[_size]; if (data && _data) memcpy(_data, data, _size); @@ -196,7 +182,6 @@ private: _height = h; _hotspotX = hotspotX; _hotspotY = hotspotY; - _keycolor = keycolor; _targetScale = targetScale; } @@ -234,9 +219,6 @@ private: }; Common::Stack<Cursor *> _cursorStack; -#ifdef ENABLE_16BIT - Common::Stack<Cursor16 *> _cursor16Stack; -#endif Common::Stack<Palette *> _cursorPaletteStack; }; |