diff options
author | Torbjörn Andersson | 2006-05-21 13:27:18 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2006-05-21 13:27:18 +0000 |
commit | d7296ae6667d0bfde089344c75caba6630757dcb (patch) | |
tree | 9c94ef981f0674a189999620121e9b239d97c248 | |
parent | 1920cc0fa80ba04d8dae7555336fae95c5834e73 (diff) | |
download | scummvm-rg350-d7296ae6667d0bfde089344c75caba6630757dcb.tar.gz scummvm-rg350-d7296ae6667d0bfde089344c75caba6630757dcb.tar.bz2 scummvm-rg350-d7296ae6667d0bfde089344c75caba6630757dcb.zip |
Make it so that if the new cursor palette to be set has zero colours, the
cursor palette is disabled.
Also, when replacing a cursor palette, try to re-use the old palette buffer, as
a minor optimization. (Not that these functions should need any optimization,
but it's simple and shouldn't hurt.)
svn-id: r22554
-rw-r--r-- | graphics/paletteman.cpp | 44 | ||||
-rw-r--r-- | graphics/paletteman.h | 33 |
2 files changed, 50 insertions, 27 deletions
diff --git a/graphics/paletteman.cpp b/graphics/paletteman.cpp index 0d751531a3..320b3b6497 100644 --- a/graphics/paletteman.cpp +++ b/graphics/paletteman.cpp @@ -41,15 +41,13 @@ void PaletteManager::pushCursorPalette(const byte *colors, uint start, uint num) if (!g_system->hasFeature(OSystem::kFeatureCursorHasPalette)) return; - Palette *pal = new Palette; - - pal->colors = new byte[4 * num]; - pal->start = start; - pal->num = num; - memcpy(pal->colors, colors, 4 * num); - + Palette *pal = new Palette(colors, start, num); _cursorPaletteStack.push(pal); - g_system->setCursorPalette(colors, start, num); + + if (num) + g_system->setCursorPalette(colors, start, num); + else + g_system->disableCursorPalette(true); } void PaletteManager::popCursorPalette() { @@ -70,7 +68,11 @@ void PaletteManager::popCursorPalette() { } pal = _cursorPaletteStack.top(); - g_system->setCursorPalette(pal->colors, pal->start, pal->num); + + if (pal->_num) + g_system->setCursorPalette(pal->_colors, pal->_start, pal->_num); + else + g_system->disableCursorPalette(true); } void PaletteManager::replaceCursorPalette(const byte *colors, uint start, uint num) { @@ -82,16 +84,24 @@ void PaletteManager::replaceCursorPalette(const byte *colors, uint start, uint n return; } - Palette *pal = _cursorPaletteStack.pop(); + Palette *pal = _cursorPaletteStack.top(); - delete pal->colors; - pal->colors = new byte[4 * num]; - pal->start = start; - pal->num = num; - memcpy(pal->colors, colors, 4 * num); + if (pal->_size < 4 * num) { + delete pal->_colors; + pal->_colors = new byte[4 * num]; + } else { + pal->_size = 4 * num; + } - _cursorPaletteStack.push(pal); - g_system->setCursorPalette(pal->colors, pal->start, pal->num); + pal->_start = start; + pal->_num = num; + + if (num) { + memcpy(pal->_colors, colors, 4 * num); + g_system->setCursorPalette(pal->_colors, pal->_start, pal->_num); + } else { + g_system->disableCursorPalette(true); + } } } // End of namespace Graphics diff --git a/graphics/paletteman.h b/graphics/paletteman.h index 5663d7d3a7..4659992195 100644 --- a/graphics/paletteman.h +++ b/graphics/paletteman.h @@ -42,6 +42,8 @@ public: * @param colors the new palette data, in interleaved RGB format * @param start the first palette entry to be updated * @param num the number of palette entries to be updated + * + * @note If num is zero, the cursor palette is disabled. */ void pushCursorPalette(const byte *colors, uint start, uint num); @@ -54,11 +56,14 @@ public: /** * Replace the current cursor palette on the stack. If the stack is - * empty, the palette is pushed instead. + * empty, the palette is pushed instead. It's a slightly more optimized + * way of popping the old palette before pushing the new one. * * @param colors the new palette data, in interleaved RGB format * @param start the first palette entry to be updated * @param num the number of palette entries to be updated + * + * @note If num is zero, the cursor palette is disabled. */ void replaceCursorPalette(const byte *colors, uint start, uint num); @@ -67,18 +72,26 @@ private: PaletteManager(); struct Palette { - byte *colors; - uint start; - uint num; - - Palette() { - colors = NULL; - start = 0; - num = 0; + byte *_colors; + uint _start; + uint _num; + uint _size; + + Palette(const byte *colors, uint start, uint num) { + _start = start; + _num = num; + _size = 4 * num; + + if (num) { + _colors = new byte[_size]; + memcpy(_colors, colors, _size); + } else { + _colors = NULL; + } } ~Palette() { - delete [] colors; + delete [] _colors; } }; |