[Scummvm-cvs-logs] SF.net SVN: scummvm: [22543] scummvm/trunk/gui

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sat May 20 04:00:09 CEST 2006


Revision: 22543
Author:   eriktorbjorn
Date:     2006-05-20 03:59:25 -0700 (Sat, 20 May 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22543&view=rev

Log Message:
-----------
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

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/cursor.cpp
    scummvm/trunk/engines/scumm/he/resource_he.cpp
    scummvm/trunk/graphics/module.mk
    scummvm/trunk/gui/ThemeNew.cpp
    scummvm/trunk/gui/newgui.cpp

Added Paths:
-----------
    scummvm/trunk/graphics/paletteman.cpp
    scummvm/trunk/graphics/paletteman.h
Modified: scummvm/trunk/engines/scumm/cursor.cpp
===================================================================
--- scummvm/trunk/engines/scumm/cursor.cpp	2006-05-20 10:57:15 UTC (rev 22542)
+++ scummvm/trunk/engines/scumm/cursor.cpp	2006-05-20 10:59:25 UTC (rev 22543)
@@ -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 @@
 
 	// 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();
 }

Modified: scummvm/trunk/engines/scumm/he/resource_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/resource_he.cpp	2006-05-20 10:57:15 UTC (rev 22542)
+++ scummvm/trunk/engines/scumm/he/resource_he.cpp	2006-05-20 10:59:25 UTC (rev 22543)
@@ -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 @@
 		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);

Modified: scummvm/trunk/graphics/module.mk
===================================================================
--- scummvm/trunk/graphics/module.mk	2006-05-20 10:57:15 UTC (rev 22542)
+++ scummvm/trunk/graphics/module.mk	2006-05-20 10:59:25 UTC (rev 22543)
@@ -11,6 +11,7 @@
 	ilbm.o \
 	imagedec.o \
 	imageman.o \
+	paletteman.o \
 	primitives.o \
 	scaler.o \
 	scaler/thumbnail.o \

Added: scummvm/trunk/graphics/paletteman.cpp
===================================================================
--- scummvm/trunk/graphics/paletteman.cpp	                        (rev 0)
+++ scummvm/trunk/graphics/paletteman.cpp	2006-05-20 10:59:25 UTC (rev 22543)
@@ -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


Property changes on: scummvm/trunk/graphics/paletteman.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: scummvm/trunk/graphics/paletteman.h
===================================================================
--- scummvm/trunk/graphics/paletteman.h	                        (rev 0)
+++ scummvm/trunk/graphics/paletteman.h	2006-05-20 10:59:25 UTC (rev 22543)
@@ -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


Property changes on: scummvm/trunk/graphics/paletteman.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/gui/ThemeNew.cpp
===================================================================
--- scummvm/trunk/gui/ThemeNew.cpp	2006-05-20 10:57:15 UTC (rev 22542)
+++ scummvm/trunk/gui/ThemeNew.cpp	2006-05-20 10:59:25 UTC (rev 22543)
@@ -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::disable() {
 	_system->disableCursorPalette(true);
 	_system->hideOverlay();
+	PaletteMan.popCursorPalette();
 	_enabled = false;
 }
 
@@ -1546,9 +1548,8 @@
 #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() {

Modified: scummvm/trunk/gui/newgui.cpp
===================================================================
--- scummvm/trunk/gui/newgui.cpp	2006-05-20 10:57:15 UTC (rev 22542)
+++ scummvm/trunk/gui/newgui.cpp	2006-05-20 10:59:25 UTC (rev 22543)
@@ -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 @@
 			 87,  87,  87, 0
 		};
 
-		_system->setCursorPalette(palette, 0, 4);
+		PaletteMan.pushCursorPalette(palette, 0, 4);
 	}
 
 	while (!_dialogStack.empty() && activeDialog == _dialogStack.top()) {
@@ -272,6 +273,8 @@
 	}
 
 	_theme->closeDialog();
+	if (useStandardCurs)
+		PaletteMan.popCursorPalette();
 
 	if (didSaveState) {
 		restoreState();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list