aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/default-palette.h63
-rw-r--r--backends/graphics/graphics.h4
-rw-r--r--backends/graphics/opengl/opengl-graphics.h4
-rw-r--r--backends/graphics/sdl/sdl-graphics.h5
4 files changed, 75 insertions, 1 deletions
diff --git a/backends/graphics/default-palette.h b/backends/graphics/default-palette.h
new file mode 100644
index 0000000000..6e3a75350e
--- /dev/null
+++ b/backends/graphics/default-palette.h
@@ -0,0 +1,63 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 BACKENDS_GRAPHICS_DEFAULT_PALETTE_H
+#define BACKENDS_GRAPHICS_DEFAULT_PALETTE_H
+
+#include "graphics/palette.h"
+
+/**
+ * This is a default implementation of the PaletteManager interface
+ * which ensures that grabPalette works as specified. Of course
+ * it is still necessary to provide code that actually updates
+ * the (possibly emulated) "hardware" palette of the backend.
+ * For this purpose, implement the abstract setPaletteIntern
+ * method.
+ */
+class DefaultPaletteManager : public PaletteManager {
+protected:
+ byte _palette[4 * 256];
+
+ /**
+ * Subclasses should only implement this method and none of the others.
+ * Its semantics are like that of setPalette, only that it does not need
+ * to worry about making it possible to query the palette values once they
+ * have been set.
+ */
+ virtual void setPaletteIntern(const byte *colors, uint start, uint num) = 0;
+
+public:
+ void setPalette(const byte *colors, uint start, uint num) {
+ assert(start + num <= 256);
+ memcpy(_palette + 4 * start, colors, 4 * num);
+ setPaletteIntern(colors, start, num);
+ }
+ void grabPalette(byte *colors, uint start, uint num) {
+ assert(start + num <= 256);
+ memcpy(colors, _palette + 4 * start, 4 * num);
+ }
+};
+
+#endif
diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h
index d2ce6534e1..953171d089 100644
--- a/backends/graphics/graphics.h
+++ b/backends/graphics/graphics.h
@@ -30,11 +30,13 @@
#include "common/noncopyable.h"
#include "common/keyboard.h"
+#include "graphics/palette.h"
+
/**
* Abstract class for graphics manager. Subclasses
* implement the real functionality.
*/
-class GraphicsManager : Common::NonCopyable {
+class GraphicsManager : public PaletteManager {
public:
virtual ~GraphicsManager() {}
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index b0334471f1..27c850f0ab 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -81,8 +81,12 @@ public:
virtual int16 getHeight();
virtual int16 getWidth();
+protected:
+ // PaletteManager API
virtual void setPalette(const byte *colors, uint start, uint num);
virtual void grabPalette(byte *colors, uint start, uint num);
+
+public:
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
virtual Graphics::Surface *lockScreen();
virtual void unlockScreen();
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 6a55a3d489..0daaab104c 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -101,8 +101,13 @@ public:
virtual int16 getHeight();
virtual int16 getWidth();
+
+protected:
+ // PaletteManager API
virtual void setPalette(const byte *colors, uint start, uint num);
virtual void grabPalette(byte *colors, uint start, uint num);
+
+public:
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
virtual Graphics::Surface *lockScreen();
virtual void unlockScreen();