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
This commit is contained in:
Torbjörn Andersson 2006-05-20 10:59:25 +00:00
parent 1c7c0039b5
commit 6cdd98b617
7 changed files with 200 additions and 7 deletions

View File

@ -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();
}

View File

@ -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);

View File

@ -11,6 +11,7 @@ MODULE_OBJS := \
ilbm.o \
imagedec.o \
imageman.o \
paletteman.o \
primitives.o \
scaler.o \
scaler/thumbnail.o \

93
graphics/paletteman.cpp Normal file
View File

@ -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

94
graphics/paletteman.h Normal file
View File

@ -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

View File

@ -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() {

View File

@ -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();