From 6cdd98b6179954a6ccfc40a9db5bf106a3a9b9e1 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 20 May 2006 10:59:25 +0000 Subject: 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 --- graphics/module.mk | 1 + graphics/paletteman.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ graphics/paletteman.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 graphics/paletteman.cpp create mode 100644 graphics/paletteman.h (limited to 'graphics') 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 { +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; + PaletteManager(); + + struct Palette { + byte *colors; + uint start; + uint num; + + Palette() { + colors = NULL; + start = 0; + num = 0; + } + + ~Palette() { + delete [] colors; + } + }; + + Common::Stack _cursorPaletteStack; +}; + + +} // End of namespace Graphics + +/** Shortcut for accessing the font manager. */ +#define PaletteMan (Graphics::PaletteManager::instance()) + +#endif -- cgit v1.2.3