diff options
| author | Torbjörn Andersson | 2006-05-20 10:59:25 +0000 |
|---|---|---|
| committer | Torbjörn Andersson | 2006-05-20 10:59:25 +0000 |
| commit | 6cdd98b6179954a6ccfc40a9db5bf106a3a9b9e1 (patch) | |
| tree | ba2f0a1361f04b6ec44b12d62326786e2c8f24b0 /graphics | |
| parent | 1c7c0039b5483919387943625a04646c5b6b0754 (diff) | |
| download | scummvm-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
Diffstat (limited to 'graphics')
| -rw-r--r-- | graphics/module.mk | 1 | ||||
| -rw-r--r-- | graphics/paletteman.cpp | 93 | ||||
| -rw-r--r-- | graphics/paletteman.h | 94 |
3 files changed, 188 insertions, 0 deletions
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 |
