aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/ThemeRenderer.cpp91
-rw-r--r--gui/ThemeRenderer.h15
2 files changed, 102 insertions, 4 deletions
diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp
index 2be95350e1..30fb371cd5 100644
--- a/gui/ThemeRenderer.cpp
+++ b/gui/ThemeRenderer.cpp
@@ -30,7 +30,7 @@
#include "common/events.h"
#include "common/config-manager.h"
#include "graphics/imageman.h"
-
+#include "graphics/cursorman.h"
#include "gui/launcher.h"
#include "gui/ThemeRenderer.h"
@@ -98,10 +98,12 @@ const ThemeRenderer::TextDataInfo ThemeRenderer::kTextDataDefaults[] = {
ThemeRenderer::ThemeRenderer(Common::String fileName, GraphicsMode mode) :
_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled),
_screen(0), _backBuffer(0), _bytesPerPixel(0), _initOk(false),
- _themeOk(false), _enabled(false), _buffering(false) {
+ _themeOk(false), _enabled(false), _buffering(false), _cursor(0) {
_system = g_system;
_parser = new ThemeParser(this);
_themeEval = new GUI::ThemeEval();
+
+ _useCursor = false;
for (int i = 0; i < kDrawDataMAX; ++i) {
_widgets[i] = 0;
@@ -131,6 +133,7 @@ ThemeRenderer::~ThemeRenderer() {
unloadTheme();
delete _parser;
delete _themeEval;
+ delete[] _cursor;
for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i)
ImageMan.unregisterSurface(i->_key);
@@ -200,14 +203,18 @@ void ThemeRenderer::refresh() {
init();
if (_enabled) {
_system->showOverlay();
-// CursorMan.replaceCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
-// CursorMan.replaceCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
+ CursorMan.replaceCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
+ CursorMan.replaceCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
}
}
void ThemeRenderer::enable() {
init();
resetDrawArea();
+
+ if (_useCursor)
+ setUpCursor();
+
_system->showOverlay();
clearAll();
_enabled = true;
@@ -215,6 +222,12 @@ void ThemeRenderer::enable() {
void ThemeRenderer::disable() {
_system->hideOverlay();
+
+ if (_useCursor) {
+ CursorMan.popCursorPalette();
+ CursorMan.popCursor();
+ }
+
_enabled = false;
}
@@ -373,6 +386,10 @@ bool ThemeRenderer::loadTheme(Common::String fileName) {
}
}
+ if (_system->hasFeature(OSystem::kFeatureCursorHasPalette)) {
+ createCursor();
+ }
+
_themeName = "DEBUG - A Theme name";
_themeOk = true;
return true;
@@ -890,4 +907,70 @@ void ThemeRenderer::openDialog(bool doBuffer, ShadingStyle style) {
_vectorRenderer->setSurface(_screen);
}
+void ThemeRenderer::setUpCursor() {
+ CursorMan.pushCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
+ CursorMan.pushCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
+ CursorMan.showMouse(true);
+}
+
+void ThemeRenderer::createCursor() {
+ const Surface *cursor = _bitmaps["cursor.bmp"];
+
+ if (!cursor)
+ return;
+
+ _cursorHotspotX = _themeEval->getVar("Cursor.Hotspot.X", 0);
+ _cursorHotspotY = _themeEval->getVar("Cursor.Hotspot.Y", 0);
+
+ _cursorTargetScale = _themeEval->getVar("Cursor.TargetScale", 3);
+
+ _cursorWidth = cursor->w;
+ _cursorHeight = cursor->h;
+
+ uint colorsFound = 0;
+ const OverlayColor *src = (const OverlayColor*)cursor->pixels;
+
+ byte *table = new byte[65536];
+ assert(table);
+ memset(table, 0, sizeof(byte)*65536);
+
+ byte r, g, b;
+
+ uint16 transparency = RGBToColor<ColorMasks<565> >(255, 0, 255);
+
+ delete[] _cursor;
+
+ _cursor = new byte[_cursorWidth * _cursorHeight];
+ assert(_cursor);
+ memset(_cursor, 255, sizeof(byte)*_cursorWidth*_cursorHeight);
+
+ for (uint y = 0; y < _cursorHeight; ++y) {
+ for (uint x = 0; x < _cursorWidth; ++x) {
+ _system->colorToRGB(src[x], r, g, b);
+ uint16 col = RGBToColor<ColorMasks<565> >(r, g, b);
+ if (!table[col] && col != transparency) {
+ table[col] = colorsFound++;
+
+ uint index = table[col];
+ _cursorPal[index * 4 + 0] = r;
+ _cursorPal[index * 4 + 1] = g;
+ _cursorPal[index * 4 + 2] = b;
+ _cursorPal[index * 4 + 3] = 0xFF;
+
+ if (colorsFound > MAX_CURS_COLORS)
+ error("Cursor contains too much colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
+ }
+
+ if (col != transparency) {
+ uint index = table[col];
+ _cursor[y * _cursorWidth + x] = index;
+ }
+ }
+ src += _cursorWidth;
+ }
+
+ _useCursor = true;
+ delete[] table;
+}
+
} // end of namespace GUI.
diff --git a/gui/ThemeRenderer.h b/gui/ThemeRenderer.h
index 1fd5ea321c..0ddfe0d7c4 100644
--- a/gui/ThemeRenderer.h
+++ b/gui/ThemeRenderer.h
@@ -458,7 +458,9 @@ public:
}
void *evaluator() { return _themeEval; }
+
bool supportsImages() const { return true; }
+ bool ownCursor() const { return _useCursor; }
Graphics::Surface *getBitmap(const Common::String &name) {
return _bitmaps.contains(name) ? _bitmaps[name] : 0;
@@ -697,6 +699,19 @@ protected:
Common::String _themeName; /** Name of the currently loaded theme */
Common::String _themeFileName;
+
+ /** Custom Cursor Management */
+ void setUpCursor();
+ void createCursor();
+
+ bool _useCursor;
+ int _cursorHotspotX, _cursorHotspotY;
+ int _cursorTargetScale;
+#define MAX_CURS_COLORS 255
+ byte *_cursor;
+ bool _needPaletteUpdates;
+ uint _cursorWidth, _cursorHeight;
+ byte _cursorPal[4*MAX_CURS_COLORS];
};
} // end of namespace GUI.