aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjörn Andersson2006-05-20 10:59:25 +0000
committerTorbjörn Andersson2006-05-20 10:59:25 +0000
commit6cdd98b6179954a6ccfc40a9db5bf106a3a9b9e1 (patch)
treeba2f0a1361f04b6ec44b12d62326786e2c8f24b0
parent1c7c0039b5483919387943625a04646c5b6b0754 (diff)
downloadscummvm-rg350-6cdd98b6179954a6ccfc40a9db5bf106a3a9b9e1.tar.gz
scummvm-rg350-6cdd98b6179954a6ccfc40a9db5bf106a3a9b9e1.tar.bz2
scummvm-rg350-6cdd98b6179954a6ccfc40a9db5bf106a3a9b9e1.zip
After the GUI has finished, restore the old cursor palette (if any). For this
to work, cursor palette now has to be set using the new "palette manager". See graphics/paletteman.cpp svn-id: r22543
-rw-r--r--engines/scumm/cursor.cpp4
-rw-r--r--engines/scumm/he/resource_he.cpp5
-rw-r--r--graphics/module.mk1
-rw-r--r--graphics/paletteman.cpp93
-rw-r--r--graphics/paletteman.h94
-rw-r--r--gui/ThemeNew.cpp5
-rw-r--r--gui/newgui.cpp5
7 files changed, 200 insertions, 7 deletions
diff --git a/engines/scumm/cursor.cpp b/engines/scumm/cursor.cpp
index aabcbee482..2e624144ad 100644
--- a/engines/scumm/cursor.cpp
+++ b/engines/scumm/cursor.cpp
@@ -23,6 +23,7 @@
#include "common/stdafx.h"
#include "common/system.h"
#include "common/util.h"
+#include "graphics/paletteman.h"
#include "scumm/bomp.h"
#include "scumm/charset.h"
#include "scumm/intern.h"
@@ -176,8 +177,7 @@ void ScummEngine_v70he::setDefaultCursor() {
// Since white color position is not guaranteed
// we setup our own palette if supported by backend
- if (_system->hasFeature(OSystem::kFeatureCursorHasPalette))
- _system->setCursorPalette(palette, 0xfe, 2);
+ PaletteMan.replaceCursorPalette(palette, 0xfe, 2);
updateCursor();
}
diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp
index dadc6ea7b7..8cbb2f263f 100644
--- a/engines/scumm/he/resource_he.cpp
+++ b/engines/scumm/he/resource_he.cpp
@@ -33,6 +33,7 @@
#include "scumm/he/sound_he.h"
#include "sound/wave.h"
+#include "graphics/paletteman.h"
#include "common/stream.h"
#include "common/system.h"
@@ -106,8 +107,8 @@ void ResExtractor::setCursor(int id) {
cc->last_used = g_system->getMillis();
}
- if (_vm->_system->hasFeature(OSystem::kFeatureCursorHasPalette) && cc->palette)
- _vm->_system->setCursorPalette(cc->palette, 0, cc->palSize);
+ if (cc->palette)
+ PaletteMan.replaceCursorPalette(cc->palette, 0, cc->palSize);
_vm->setCursorHotspot(cc->hotspot_x, cc->hotspot_y);
_vm->setCursorFromBuffer(cc->bitmap, cc->w, cc->h, cc->w);
diff --git a/graphics/module.mk b/graphics/module.mk
index 89b32fac19..1bf6536448 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -11,6 +11,7 @@ MODULE_OBJS := \
ilbm.o \
imagedec.o \
imageman.o \
+ paletteman.o \
primitives.o \
scaler.o \
scaler/thumbnail.o \
diff --git a/graphics/paletteman.cpp b/graphics/paletteman.cpp
new file mode 100644
index 0000000000..a41691b618
--- /dev/null
+++ b/graphics/paletteman.cpp
@@ -0,0 +1,93 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "graphics/paletteman.h"
+
+#include "common/system.h"
+#include "common/stack.h"
+
+DECLARE_SINGLETON(Graphics::PaletteManager);
+
+namespace Graphics {
+
+static bool g_initialized = false;
+
+PaletteManager::PaletteManager() {
+ if (!g_initialized) {
+ _cursorPaletteStack.clear();
+ }
+}
+
+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);
+
+ _cursorPaletteStack.push(pal);
+
+ g_system->setCursorPalette(colors, start, num);
+}
+
+void PaletteManager::popCursorPalette() {
+ if (!g_system->hasFeature(OSystem::kFeatureCursorHasPalette))
+ return;
+
+ if (_cursorPaletteStack.empty())
+ return;
+
+ Palette *pal;
+
+ pal = _cursorPaletteStack.pop();
+ delete pal;
+
+ if (_cursorPaletteStack.empty()) {
+ g_system->disableCursorPalette(true);
+ return;
+ }
+
+ pal = _cursorPaletteStack.top();
+ g_system->setCursorPalette(pal->colors, pal->start, pal->num);
+}
+
+void PaletteManager::replaceCursorPalette(const byte *colors, uint start, uint num) {
+ if (!g_system->hasFeature(OSystem::kFeatureCursorHasPalette))
+ return;
+
+ if (_cursorPaletteStack.empty()) {
+ pushCursorPalette(colors, start, num);
+ return;
+ }
+
+ Palette *pal = _cursorPaletteStack.pop();
+
+ delete pal->colors;
+ pal->colors = new byte[4 * num];
+ pal->start = start;
+ pal->num = num;
+}
+
+} // End of namespace Graphics
diff --git a/graphics/paletteman.h b/graphics/paletteman.h
new file mode 100644
index 0000000000..5663d7d3a7
--- /dev/null
+++ b/graphics/paletteman.h
@@ -0,0 +1,94 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef GRAPHICS_PALETTEMAN_H
+#define GRAPHICS_PALETTEMAN_H
+
+#include "common/stdafx.h"
+#include "common/scummsys.h"
+#include "common/stack.h"
+#include "common/singleton.h"
+
+namespace Graphics {
+
+class PaletteManager : public Common::Singleton<PaletteManager> {
+public:
+ /**
+ * Push a new cursor palette onto the stack, and set it in the backend.
+ * The palette entries from 'start' till (start+num-1) will be replaced
+ * so a full palette updated is accomplished via start=0, num=256.
+ *
+ * The palette data is specified in the same interleaved RGBA format as
+ * used by all backends.
+ *
+ * @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
+ */
+ void pushCursorPalette(const byte *colors, uint start, uint num);
+
+ /**
+ * Pop a cursor palette from the stack, and restore the previous one to
+ * the backend. If there is no previous palette, the cursor palette is
+ * disabled instead.
+ */
+ void popCursorPalette();
+
+ /**
+ * Replace the current cursor palette on the stack. If the stack is
+ * empty, the palette is pushed instead.
+ *
+ * @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
+ */
+ void replaceCursorPalette(const byte *colors, uint start, uint num);
+
+private:
+ friend class Common::Singleton<SingletonBaseType>;
+ PaletteManager();
+
+ struct Palette {
+ byte *colors;
+ uint start;
+ uint num;
+
+ Palette() {
+ colors = NULL;
+ start = 0;
+ num = 0;
+ }
+
+ ~Palette() {
+ delete [] colors;
+ }
+ };
+
+ Common::Stack<Palette *> _cursorPaletteStack;
+};
+
+
+} // End of namespace Graphics
+
+/** Shortcut for accessing the font manager. */
+#define PaletteMan (Graphics::PaletteManager::instance())
+
+#endif
diff --git a/gui/ThemeNew.cpp b/gui/ThemeNew.cpp
index b08dded3ce..0ff6b45fa4 100644
--- a/gui/ThemeNew.cpp
+++ b/gui/ThemeNew.cpp
@@ -27,6 +27,7 @@
#include "graphics/imageman.h"
#include "graphics/imagedec.h"
#include "graphics/colormasks.h"
+#include "graphics/paletteman.h"
#include "common/config-manager.h"
#include "common/file.h"
@@ -383,6 +384,7 @@ void ThemeNew::enable() {
void ThemeNew::disable() {
_system->disableCursorPalette(true);
_system->hideOverlay();
+ PaletteMan.popCursorPalette();
_enabled = false;
}
@@ -1546,9 +1548,8 @@ OverlayColor ThemeNew::calcDimColor(OverlayColor col) {
#pragma mark -
void ThemeNew::setUpCursor() {
- _system->setCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
+ PaletteMan.pushCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
_system->setMouseCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
- _system->disableCursorPalette(false);
}
void ThemeNew::createCursor() {
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index edd91e9f39..db45d94e3c 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -22,6 +22,7 @@
#include "common/stdafx.h"
#include "common/system.h"
#include "common/util.h"
+#include "graphics/paletteman.h"
#include "gui/newgui.h"
#include "gui/dialog.h"
#include "gui/eval.h"
@@ -154,7 +155,7 @@ void NewGui::runLoop() {
87, 87, 87, 0
};
- _system->setCursorPalette(palette, 0, 4);
+ PaletteMan.pushCursorPalette(palette, 0, 4);
}
while (!_dialogStack.empty() && activeDialog == _dialogStack.top()) {
@@ -272,6 +273,8 @@ void NewGui::runLoop() {
}
_theme->closeDialog();
+ if (useStandardCurs)
+ PaletteMan.popCursorPalette();
if (didSaveState) {
restoreState();