aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/main.cpp2
-rw-r--r--dists/msvc9/scummvm.vcproj40
-rw-r--r--graphics/VectorRenderer.cpp2
-rw-r--r--graphics/VectorRenderer.h2
-rw-r--r--graphics/VectorRendererSpec.cpp6
-rw-r--r--gui/ThemeEngine.cpp (renamed from gui/ThemeRenderer.cpp)346
-rw-r--r--gui/ThemeEngine.h (renamed from gui/ThemeRenderer.h)168
-rw-r--r--gui/ThemeEval.cpp170
-rw-r--r--gui/ThemeEval.h305
-rw-r--r--gui/ThemeLayout.cpp227
-rw-r--r--gui/ThemeLayout.h239
-rw-r--r--gui/ThemeParser.cpp4
-rw-r--r--gui/ThemeParser.h8
-rw-r--r--gui/module.mk3
-rw-r--r--gui/newgui.cpp14
-rw-r--r--gui/newgui.h4
-rw-r--r--gui/options.cpp6
-rw-r--r--gui/theme.h2
18 files changed, 836 insertions, 712 deletions
diff --git a/base/main.cpp b/base/main.cpp
index 666d4fdfe3..031e8fd522 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -43,7 +43,7 @@
#include "common/system.h"
#include "gui/newgui.h"
#include "gui/message.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "gui/ThemeParser.h"
#if defined(_WIN32_WCE)
diff --git a/dists/msvc9/scummvm.vcproj b/dists/msvc9/scummvm.vcproj
index 7fd256cd42..fc6713c49f 100644
--- a/dists/msvc9/scummvm.vcproj
+++ b/dists/msvc9/scummvm.vcproj
@@ -1205,31 +1205,39 @@
>
</File>
<File
- RelativePath="..\..\gui\ThemeParser.cpp"
+ RelativePath="..\..\gui\ThemeEngine.cpp"
>
</File>
<File
- RelativePath="..\..\gui\ThemeParser.h"
+ RelativePath="..\..\gui\ThemeEngine.h"
>
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCustomBuildTool"
- />
- </FileConfiguration>
</File>
<File
- RelativePath="..\..\gui\ThemeRenderer.cpp"
+ RelativePath="..\..\gui\ThemeEval.cpp"
>
</File>
<File
- RelativePath="..\..\gui\ThemeEval.cpp"
+ RelativePath="..\..\gui\ThemeLayout.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\gui\ThemeLayout.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\gui\ThemeParser.cpp"
>
</File>
<File
- RelativePath="..\..\gui\ThemeRenderer.h"
+ RelativePath="..\..\gui\ThemeParser.h"
>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath="..\..\gui\widget.cpp"
@@ -1350,6 +1358,14 @@
/>
</FileConfiguration>
</File>
+ <File
+ RelativePath="..\..\graphics\VectorRendererSpec.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\graphics\VectorRendererSpec.h"
+ >
+ </File>
<Filter
Name="scaler"
>
diff --git a/graphics/VectorRenderer.cpp b/graphics/VectorRenderer.cpp
index ae72ce0ce1..4f9bd48334 100644
--- a/graphics/VectorRenderer.cpp
+++ b/graphics/VectorRenderer.cpp
@@ -30,7 +30,7 @@
#include "graphics/surface.h"
#include "graphics/colormasks.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "graphics/VectorRenderer.h"
#define VECTOR_RENDERER_FAST_TRIANGLES
diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h
index 8ba9126b3e..c2cd6b0010 100644
--- a/graphics/VectorRenderer.h
+++ b/graphics/VectorRenderer.h
@@ -32,7 +32,7 @@
#include "graphics/surface.h"
#include "graphics/colormasks.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
namespace Graphics {
class VectorRenderer;
diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp
index 4819ea8336..a84a3d6f23 100644
--- a/graphics/VectorRendererSpec.cpp
+++ b/graphics/VectorRendererSpec.cpp
@@ -30,7 +30,7 @@
#include "graphics/surface.h"
#include "graphics/colormasks.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "graphics/VectorRenderer.h"
#include "graphics/VectorRendererSpec.h"
@@ -128,10 +128,10 @@ namespace Graphics {
VectorRenderer *createRenderer(int mode) {
switch (mode) {
- case GUI::ThemeRenderer::kGfxStandard16bit:
+ case GUI::ThemeEngine::kGfxStandard16bit:
return new VectorRendererSpec<uint16, ColorMasks<565> >;
- case GUI::ThemeRenderer::kGfxAntialias16bit:
+ case GUI::ThemeEngine::kGfxAntialias16bit:
return new VectorRendererAA<uint16, ColorMasks<565> >;
default:
diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeEngine.cpp
index 43659eeb16..006a8768a6 100644
--- a/gui/ThemeRenderer.cpp
+++ b/gui/ThemeEngine.cpp
@@ -34,7 +34,7 @@
#include "graphics/cursorman.h"
#include "gui/launcher.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "gui/ThemeEval.h"
#include "graphics/VectorRenderer.h"
@@ -44,13 +44,65 @@ namespace GUI {
using namespace Graphics;
-const char *ThemeRenderer::rendererModeLabels[] = {
+const char *ThemeEngine::rendererModeLabels[] = {
"Disabled GFX",
"Stardard Renderer (16bpp)",
"Antialiased Renderer (16bpp)"
};
-const ThemeRenderer::DrawDataInfo ThemeRenderer::kDrawDataDefaults[] = {
+
+/**********************************************************
+ * ThemeItem functions for drawing queues.
+ *********************************************************/
+void ThemeItemDrawData::drawSelf(bool draw, bool restore) {
+
+ Common::Rect extendedRect = _area;
+ extendedRect.grow(_engine->kDirtyRectangleThreshold + _data->_backgroundOffset);
+
+ if (restore)
+ _engine->restoreBackground(extendedRect);
+
+ if (draw) {
+ Common::List<Graphics::DrawStep>::const_iterator step;
+ for (step = _data->_steps.begin(); step != _data->_steps.end(); ++step)
+ _engine->renderer()->drawStep(_area, *step, _dynamicData);
+ }
+
+ _engine->addDirtyRect(extendedRect);
+}
+
+void ThemeItemTextData::drawSelf(bool draw, bool restore) {
+ if (_restoreBg || restore)
+ _engine->restoreBackground(_area);
+
+ if (draw) {
+ _engine->renderer()->setFgColor(_data->_color.r, _data->_color.g, _data->_color.b);
+ _engine->renderer()->drawString(_data->_fontPtr, _text, _area, _alignH, _alignV, _deltax, _ellipsis);
+ }
+
+ _engine->addDirtyRect(_area);
+}
+
+void ThemeItemBitmap::drawSelf(bool draw, bool restore) {
+ if (restore)
+ _engine->restoreBackground(_area);
+
+ if (draw) {
+ if (_alpha)
+ _engine->renderer()->blitAlphaBitmap(_bitmap, _area);
+ else
+ _engine->renderer()->blitSubSurface(_bitmap, _area);
+ }
+
+ _engine->addDirtyRect(_area);
+}
+
+
+
+/**********************************************************
+ * Data definitions for theme engine elements
+ *********************************************************/
+const ThemeEngine::DrawDataInfo ThemeEngine::kDrawDataDefaults[] = {
{kDDMainDialogBackground, "mainmenu_bg", true, kDDNone},
{kDDSpecialColorBackground, "special_bg", true, kDDNone},
{kDDPlainColorBackground, "plain_bg", true, kDDNone},
@@ -93,7 +145,7 @@ const ThemeRenderer::DrawDataInfo ThemeRenderer::kDrawDataDefaults[] = {
{kDDSeparator, "separator", true, kDDNone},
};
-const ThemeRenderer::TextDataInfo ThemeRenderer::kTextDataDefaults[] = {
+const ThemeEngine::TextDataInfo ThemeEngine::kTextDataDefaults[] = {
{kTextDataDefault, "text_default"},
{kTextDataHover, "text_hover"},
{kTextDataDisabled, "text_disabled"},
@@ -104,7 +156,10 @@ const ThemeRenderer::TextDataInfo ThemeRenderer::kTextDataDefaults[] = {
};
-ThemeRenderer::ThemeRenderer(Common::String fileName, GraphicsMode mode) :
+/**********************************************************
+ * ThemeEngine class
+ *********************************************************/
+ThemeEngine::ThemeEngine(Common::String fileName, GraphicsMode mode) :
_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled), _font(0),
_screen(0), _backBuffer(0), _bytesPerPixel(0), _initOk(false),
_themeOk(false), _enabled(false), _buffering(false), _cursor(0) {
@@ -127,7 +182,7 @@ ThemeRenderer::ThemeRenderer(Common::String fileName, GraphicsMode mode) :
_initOk = false;
}
-ThemeRenderer::~ThemeRenderer() {
+ThemeEngine::~ThemeEngine() {
freeRenderer();
freeScreen();
freeBackbuffer();
@@ -140,7 +195,11 @@ ThemeRenderer::~ThemeRenderer() {
ImageMan.unregisterSurface(i->_key);
}
-bool ThemeRenderer::init() {
+
+/**********************************************************
+ * Theme setup/initialization
+ *********************************************************/
+bool ThemeEngine::init() {
// reset everything and reload the graphics
deinit();
setGraphicsMode(_graphicsMode);
@@ -164,7 +223,7 @@ bool ThemeRenderer::init() {
return true;
}
-void ThemeRenderer::deinit() {
+void ThemeEngine::deinit() {
if (_initOk) {
_system->hideOverlay();
freeRenderer();
@@ -174,7 +233,7 @@ void ThemeRenderer::deinit() {
}
}
-void ThemeRenderer::unloadTheme() {
+void ThemeEngine::unloadTheme() {
if (!_themeOk)
return;
@@ -200,7 +259,7 @@ void ThemeRenderer::unloadTheme() {
_themeOk = false;
}
-void ThemeRenderer::clearAll() {
+void ThemeEngine::clearAll() {
if (!_initOk)
return;
@@ -208,7 +267,7 @@ void ThemeRenderer::clearAll() {
_system->grabOverlay((OverlayColor*)_screen->pixels, _screen->w);
}
-void ThemeRenderer::refresh() {
+void ThemeEngine::refresh() {
init();
if (_enabled) {
_system->showOverlay();
@@ -220,7 +279,7 @@ void ThemeRenderer::refresh() {
}
}
-void ThemeRenderer::enable() {
+void ThemeEngine::enable() {
init();
resetDrawArea();
@@ -232,7 +291,7 @@ void ThemeRenderer::enable() {
_enabled = true;
}
-void ThemeRenderer::disable() {
+void ThemeEngine::disable() {
_system->hideOverlay();
if (_useCursor) {
@@ -244,7 +303,7 @@ void ThemeRenderer::disable() {
}
template<typename PixelType>
-void ThemeRenderer::screenInit(bool backBuffer) {
+void ThemeEngine::screenInit(bool backBuffer) {
uint32 width = _system->getOverlayWidth();
uint32 height = _system->getOverlayHeight();
@@ -260,7 +319,7 @@ void ThemeRenderer::screenInit(bool backBuffer) {
_system->clearOverlay();
}
-void ThemeRenderer::setGraphicsMode(GraphicsMode mode) {
+void ThemeEngine::setGraphicsMode(GraphicsMode mode) {
switch (mode) {
case kGfxStandard16bit:
case kGfxAntialias16bit:
@@ -277,14 +336,50 @@ void ThemeRenderer::setGraphicsMode(GraphicsMode mode) {
_vectorRenderer->setSurface(_screen);
}
-void ThemeRenderer::addDrawStep(const Common::String &drawDataId, Graphics::DrawStep step) {
+bool ThemeEngine::isWidgetCached(DrawData type, const Common::Rect &r) {
+ return _widgets[type] && _widgets[type]->_cached &&
+ _widgets[type]->_surfaceCache->w == r.width() &&
+ _widgets[type]->_surfaceCache->h == r.height();
+}
+
+void ThemeEngine::drawCached(DrawData type, const Common::Rect &r) {
+ assert(_widgets[type]->_surfaceCache->bytesPerPixel == _screen->bytesPerPixel);
+ _vectorRenderer->blitSurface(_widgets[type]->_surfaceCache, r);
+}
+
+void ThemeEngine::calcBackgroundOffset(DrawData type) {
+ uint maxShadow = 0;
+ for (Common::List<Graphics::DrawStep>::const_iterator step = _widgets[type]->_steps.begin();
+ step != _widgets[type]->_steps.end(); ++step) {
+ if ((step->autoWidth || step->autoHeight) && step->shadow > maxShadow)
+ maxShadow = step->shadow;
+
+ if (step->drawingCall == &Graphics::VectorRenderer::drawCallback_BEVELSQ && step->bevel > maxShadow)
+ maxShadow = step->bevel;
+ }
+
+ _widgets[type]->_backgroundOffset = maxShadow;
+}
+
+void ThemeEngine::restoreBackground(Common::Rect r, bool special) {
+ r.clip(_screen->w, _screen->h); // AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA... Oh god. :(
+ _vectorRenderer->blitSurface(_backBuffer, r);
+}
+
+
+
+
+/**********************************************************
+ * Theme elements management
+ *********************************************************/
+void ThemeEngine::addDrawStep(const Common::String &drawDataId, Graphics::DrawStep step) {
DrawData id = getDrawDataId(drawDataId);
assert(_widgets[id] != 0);
_widgets[id]->_steps.push_back(step);
}
-bool ThemeRenderer::addTextData(const Common::String &drawDataId, const Common::String &textDataId, TextAlign alignH, TextAlignVertical alignV) {
+bool ThemeEngine::addTextData(const Common::String &drawDataId, const Common::String &textDataId, TextAlign alignH, TextAlignVertical alignV) {
DrawData id = getDrawDataId(drawDataId);
TextData textId = getTextDataId(textDataId);
@@ -298,7 +393,7 @@ bool ThemeRenderer::addTextData(const Common::String &drawDataId, const Common::
return true;
}
-bool ThemeRenderer::addFont(const Common::String &fontId, const Common::String &file, int r, int g, int b) {
+bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &file, int r, int g, int b) {
TextData textId = getTextDataId(fontId);
if (textId == -1)
@@ -331,7 +426,7 @@ bool ThemeRenderer::addFont(const Common::String &fontId, const Common::String &
}
-bool ThemeRenderer::addBitmap(const Common::String &filename) {
+bool ThemeEngine::addBitmap(const Common::String &filename) {
if (_bitmaps.contains(filename)) {
ImageMan.unregisterSurface(filename);
}
@@ -342,7 +437,7 @@ bool ThemeRenderer::addBitmap(const Common::String &filename) {
return _bitmaps[filename] != 0;
}
-bool ThemeRenderer::addDrawData(const Common::String &data, bool cached) {
+bool ThemeEngine::addDrawData(const Common::String &data, bool cached) {
DrawData data_id = getDrawDataId(data);
if (data_id == -1)
@@ -360,7 +455,11 @@ bool ThemeRenderer::addDrawData(const Common::String &data, bool cached) {
return true;
}
-bool ThemeRenderer::loadTheme(Common::String fileName) {
+
+/**********************************************************
+ * Theme XML loading
+ *********************************************************/
+bool ThemeEngine::loadTheme(Common::String fileName) {
unloadTheme();
if (fileName != "builtin") {
@@ -396,7 +495,7 @@ bool ThemeRenderer::loadTheme(Common::String fileName) {
return true;
}
-bool ThemeRenderer::loadDefaultXML() {
+bool ThemeEngine::loadDefaultXML() {
// The default XML theme is included on runtime from a pregenerated
// file inside the themes directory.
@@ -421,7 +520,7 @@ bool ThemeRenderer::loadDefaultXML() {
#endif
}
-bool ThemeRenderer::loadThemeXML(Common::String themeName) {
+bool ThemeEngine::loadThemeXML(Common::String themeName) {
assert(_parser);
_themeName.clear();
@@ -512,26 +611,19 @@ bool ThemeRenderer::loadThemeXML(Common::String themeName) {
return (parseCount > 0 && _themeName.empty() == false);
}
-bool ThemeRenderer::isWidgetCached(DrawData type, const Common::Rect &r) {
- return _widgets[type] && _widgets[type]->_cached &&
- _widgets[type]->_surfaceCache->w == r.width() &&
- _widgets[type]->_surfaceCache->h == r.height();
-}
-void ThemeRenderer::drawCached(DrawData type, const Common::Rect &r) {
- assert(_widgets[type]->_surfaceCache->bytesPerPixel == _screen->bytesPerPixel);
- _vectorRenderer->blitSurface(_widgets[type]->_surfaceCache, r);
-}
-void ThemeRenderer::queueDD(DrawData type, const Common::Rect &r, uint32 dynamic) {
+/**********************************************************
+ * Drawing Queue management
+ *********************************************************/
+void ThemeEngine::queueDD(DrawData type, const Common::Rect &r, uint32 dynamic) {
if (_widgets[type] == 0)
return;
- DrawQueue q;
- q.type = type;
- q.area = r;
- q.area.clip(_screen->w, _screen->h);
- q.dynData = dynamic;
+ Common::Rect area = r;
+ area.clip(_screen->w, _screen->h);
+
+ ThemeItemDrawData *q = new ThemeItemDrawData(this, _widgets[type], area, dynamic);
if (_buffering) {
if (_widgets[type]->_buffer) {
@@ -543,108 +635,51 @@ void ThemeRenderer::queueDD(DrawData type, const Common::Rect &r, uint32 dynamic
_screenQueue.push_back(q);
}
} else {
- drawDD(q, !_widgets[type]->_buffer, _widgets[type]->_buffer);
+ q->drawSelf(!_widgets[type]->_buffer, _widgets[type]->_buffer);
+ delete q;
}
}
-void ThemeRenderer::queueDDText(TextData type, const Common::Rect &r, const Common::String &text, bool restoreBg,
+void ThemeEngine::queueDDText(TextData type, const Common::Rect &r, const Common::String &text, bool restoreBg,
bool ellipsis, TextAlign alignH, TextAlignVertical alignV, int deltax) {
if (_texts[type] == 0)
return;
-
- DrawQueueText q;
- q.type = type;
- q.area = r;
- q.area.clip(_screen->w, _screen->h);
- q.text = text;
- q.alignH = alignH;
- q.alignV = alignV;
- q.restoreBg = restoreBg;
- q.deltax = deltax;
- q.ellipsis = ellipsis;
+
+ Common::Rect area = r;
+ area.clip(_screen->w, _screen->h);
+
+ ThemeItemTextData *q = new ThemeItemTextData(this, _texts[type], area, text, alignH, alignV, ellipsis, restoreBg, deltax);
if (_buffering) {
- _textQueue.push_back(q);
+ _screenQueue.push_back(q);
} else {
- drawDDText(q);
+ q->drawSelf(true, false);
+ delete q;
}
}
-void ThemeRenderer::queueBitmap(const Graphics::Surface *bitmap, const Common::Rect &area, bool alpha) {
- BitmapQueue q;
- q.bitmap = bitmap;
- q.area = area;
- q.alpha = alpha;
+void ThemeEngine::queueBitmap(const Graphics::Surface *bitmap, const Common::Rect &r, bool alpha) {
+
+ Common::Rect area = r;
+ area.clip(_screen->w, _screen->h);
+
+ ThemeItemBitmap *q = new ThemeItemBitmap(this, area, bitmap, alpha);
if (_buffering) {
- _bitmapQueue.push_back(q);
+ _bufferQueue.push_back(q);
} else {
- drawBitmap(q);
- }
-}
-
-void ThemeRenderer::drawDD(const DrawQueue &q, bool draw, bool restore) {
- Common::Rect extendedRect = q.area;
- extendedRect.grow(kDirtyRectangleThreshold + _widgets[q.type]->_backgroundOffset);
-// extendedRect.right += _widgets[q.type]->_backgroundOffset;
-// extendedRect.bottom += _widgets[q.type]->_backgroundOffset;
-
- if (restore)
- restoreBackground(extendedRect);
-
- if (draw) {
- if (isWidgetCached(q.type, q.area)) {
- drawCached(q.type, q.area);
- } else {
- for (Common::List<Graphics::DrawStep>::const_iterator step = _widgets[q.type]->_steps.begin();
- step != _widgets[q.type]->_steps.end(); ++step)
- _vectorRenderer->drawStep(q.area, *step, q.dynData);
- }
+ q->drawSelf(true, false);
+ delete q;
}
-
- addDirtyRect(extendedRect);
-}
-
-void ThemeRenderer::drawDDText(const DrawQueueText &q) {
- if (q.restoreBg)
- restoreBackground(q.area);
-
- _vectorRenderer->setFgColor(_texts[q.type]->_color.r, _texts[q.type]->_color.g, _texts[q.type]->_color.b);
- _vectorRenderer->drawString(_texts[q.type]->_fontPtr, q.text, q.area, q.alignH, q.alignV, q.deltax, q.ellipsis);
- addDirtyRect(q.area);
-}
-
-void ThemeRenderer::drawBitmap(const BitmapQueue &q) {
-
- if (q.alpha)
- _vectorRenderer->blitAlphaBitmap(q.bitmap, q.area);
- else
- _vectorRenderer->blitSubSurface(q.bitmap, q.area);
-
- addDirtyRect(q.area);
}
-void ThemeRenderer::calcBackgroundOffset(DrawData type) {
- uint maxShadow = 0;
- for (Common::List<Graphics::DrawStep>::const_iterator step = _widgets[type]->_steps.begin();
- step != _widgets[type]->_steps.end(); ++step) {
- if ((step->autoWidth || step->autoHeight) && step->shadow > maxShadow)
- maxShadow = step->shadow;
-
- if (step->drawingCall == &Graphics::VectorRenderer::drawCallback_BEVELSQ && step->bevel > maxShadow)
- maxShadow = step->bevel;
- }
-
- _widgets[type]->_backgroundOffset = maxShadow;
-}
-void ThemeRenderer::restoreBackground(Common::Rect r, bool special) {
- r.clip(_screen->w, _screen->h); // AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA... Oh god. :(
- _vectorRenderer->blitSurface(_backBuffer, r);
-}
-void ThemeRenderer::drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints) {
+/**********************************************************
+ * Widget drawing functions
+ *********************************************************/
+void ThemeEngine::drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints) {
if (!ready())
return;
@@ -661,14 +696,14 @@ void ThemeRenderer::drawButton(const Common::Rect &r, const Common::String &str,
queueDDText(getTextData(dd), r, str, false, false, _widgets[dd]->_textAlignH, _widgets[dd]->_textAlignV);
}
-void ThemeRenderer::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {
+void ThemeEngine::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {
if (!ready())
return;
queueDD(kDDSeparator, r);
}
-void ThemeRenderer::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
+void ThemeEngine::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
if (!ready())
return;
@@ -695,7 +730,7 @@ void ThemeRenderer::drawCheckbox(const Common::Rect &r, const Common::String &st
queueDDText(td, r2, str, false, false, _widgets[kDDCheckboxDefault]->_textAlignH, _widgets[dd]->_textAlignV);
}
-void ThemeRenderer::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
+void ThemeEngine::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
if (!ready())
return;
@@ -716,7 +751,7 @@ void ThemeRenderer::drawSlider(const Common::Rect &r, int width, WidgetStateInfo
queueDD(dd, r2);
}
-void ThemeRenderer::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scrollState, WidgetStateInfo state) {
+void ThemeEngine::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scrollState, WidgetStateInfo state) {
if (!ready())
return;
@@ -742,7 +777,7 @@ void ThemeRenderer::drawScrollbar(const Common::Rect &r, int sliderY, int slider
queueDD(scrollState == kScrollbarStateSlider ? kDDScrollbarHandleHover : kDDScrollbarHandleIdle, r2);
}
-void ThemeRenderer::drawDialogBackground(const Common::Rect &r, DialogBackground bgtype, WidgetStateInfo state) {
+void ThemeEngine::drawDialogBackground(const Common::Rect &r, DialogBackground bgtype, WidgetStateInfo state) {
if (!ready())
return;
@@ -765,7 +800,7 @@ void ThemeRenderer::drawDialogBackground(const Common::Rect &r, DialogBackground
}
}
-void ThemeRenderer::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state) {
+void ThemeEngine::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state) {
if (!ready())
return;
@@ -776,7 +811,7 @@ void ThemeRenderer::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo
queueDD(kDDCaret, r);
}
-void ThemeRenderer::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align) {
+void ThemeEngine::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align) {
if (!ready())
return;
@@ -790,14 +825,14 @@ void ThemeRenderer::drawPopUpWidget(const Common::Rect &r, const Common::String
}
}
-void ThemeRenderer::drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans) {
+void ThemeEngine::drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans) {
if (!ready())
return;
queueBitmap(&surface, r, themeTrans);
}
-void ThemeRenderer::drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, WidgetStateInfo state) {
+void ThemeEngine::drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, WidgetStateInfo state) {
if (!ready())
return;
@@ -820,7 +855,7 @@ void ThemeRenderer::drawWidgetBackground(const Common::Rect &r, uint16 hints, Wi
}
}
-void ThemeRenderer::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state) {
+void ThemeEngine::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state) {
if (!ready())
return;
@@ -847,7 +882,7 @@ void ThemeRenderer::drawTab(const Common::Rect &r, int tabHeight, int tabWidth,
}
}
-void ThemeRenderer::drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {
+void ThemeEngine::drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {
if (!ready())
return;
@@ -881,7 +916,7 @@ void ThemeRenderer::drawText(const Common::Rect &r, const Common::String &str, W
}
}
-void ThemeRenderer::drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state) {
+void ThemeEngine::drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state) {
if (!ready())
return;
@@ -890,7 +925,7 @@ void ThemeRenderer::drawChar(const Common::Rect &r, byte ch, const Graphics::Fon
addDirtyRect(r);
}
-void ThemeRenderer::debugWidgetPosition(const char *name, const Common::Rect &r) {
+void ThemeEngine::debugWidgetPosition(const char *name, const Common::Rect &r) {
_font->drawString(_screen, name, r.left, r.top, r.width(), 0xFFFF, Graphics::kTextAlignRight, 0, true);
_screen->hLine(r.left, r.top, r.right, 0xFFFF);
_screen->hLine(r.left, r.bottom, r.right, 0xFFFF);
@@ -898,12 +933,21 @@ void ThemeRenderer::debugWidgetPosition(const char *name, const Common::Rect &r)
_screen->vLine(r.right, r.top, r.bottom, 0xFFFF);
}
-void ThemeRenderer::updateScreen() {
+
+
+/**********************************************************
+ * Screen/overlay management
+ *********************************************************/
+void ThemeEngine::updateScreen() {
+ ThemeItem *item = 0;
+
if (!_bufferQueue.empty()) {
_vectorRenderer->setSurface(_backBuffer);
- for (Common::List<DrawQueue>::const_iterator q = _bufferQueue.begin(); q != _bufferQueue.end(); ++q)
- drawDD(*q, true, false);
+ for (Common::List<ThemeItem*>::iterator q = _bufferQueue.begin(); q != _bufferQueue.end(); ++q) {
+ (*q)->drawSelf(true, false);
+ delete *q;
+ }
_vectorRenderer->setSurface(_screen);
_vectorRenderer->blitSurface(_backBuffer, Common::Rect(0, 0, _screen->w, _screen->h));
@@ -912,35 +956,19 @@ void ThemeRenderer::updateScreen() {
if (!_screenQueue.empty()) {
_vectorRenderer->disableShadows();
- for (Common::List<DrawQueue>::const_iterator q = _screenQueue.begin(); q != _screenQueue.end(); ++q)
- drawDD(*q, true, false);
+ for (Common::List<ThemeItem*>::iterator q = _screenQueue.begin(); q != _screenQueue.end(); ++q) {
+ (*q)->drawSelf(true, false);
+ delete *q;
+ }
_vectorRenderer->enableShadows();
_screenQueue.clear();
}
-
- if (!_bitmapQueue.empty()) {
- for (Common::List<BitmapQueue>::const_iterator q = _bitmapQueue.begin(); q != _bitmapQueue.end(); ++q)
- drawBitmap(*q);
-
- _bitmapQueue.clear();
- }
-
- if (!_textQueue.empty()) {
- for (Common::List<DrawQueueText>::const_iterator q = _textQueue.begin(); q != _textQueue.end(); ++q)
- drawDDText(*q);
-
- _textQueue.clear();
- }
renderDirtyScreen();
-
-// _vectorRenderer->fillSurface();
-// themeEval()->debugDraw(_screen, _font);
-// _vectorRenderer->copyWholeFrame(_system);
}
-void ThemeRenderer::renderDirtyScreen() {
+void ThemeEngine::renderDirtyScreen() {
if (_dirtyScreen.empty())
return;
@@ -956,7 +984,7 @@ void ThemeRenderer::renderDirtyScreen() {
_dirtyScreen.clear();
}
-void ThemeRenderer::openDialog(bool doBuffer, ShadingStyle style) {
+void ThemeEngine::openDialog(bool doBuffer, ShadingStyle style) {
if (doBuffer)
_buffering = true;
@@ -970,13 +998,13 @@ void ThemeRenderer::openDialog(bool doBuffer, ShadingStyle style) {
_vectorRenderer->setSurface(_screen);
}
-void ThemeRenderer::setUpCursor() {
+void ThemeEngine::setUpCursor() {
CursorMan.pushCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
CursorMan.pushCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
CursorMan.showMouse(true);
}
-bool ThemeRenderer::createCursor(const Common::String &filename, int hotspotX, int hotspotY, int scale) {
+bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int hotspotY, int scale) {
if (!_system->hasFeature(OSystem::kFeatureCursorHasPalette))
return false;
diff --git a/gui/ThemeRenderer.h b/gui/ThemeEngine.h
index e8f6d76ee2..9f7fe35d82 100644
--- a/gui/ThemeRenderer.h
+++ b/gui/ThemeEngine.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef INTERFACE_MANAGER_H
-#define INTERFACE_MANAGER_H
+#ifndef THEME_ENGINE_H
+#define THEME_ENGINE_H
#include "common/scummsys.h"
#include "graphics/surface.h"
@@ -83,8 +83,65 @@ struct WidgetDrawData {
}
};
-class ThemeRenderer : public Theme {
+class ThemeItem {
+public:
+ ThemeItem(ThemeEngine *engine, const Common::Rect &area) :
+ _engine(engine), _area(area) {}
+
+ virtual void drawSelf(bool doDraw, bool doRestore) = 0;
+
+protected:
+ Common::Rect _area;
+ ThemeEngine *_engine;
+};
+
+class ThemeItemDrawData : public ThemeItem {
+public:
+ ThemeItemDrawData(ThemeEngine *engine, const WidgetDrawData *data, const Common::Rect &area, uint32 dynData) :
+ ThemeItem(engine, area), _dynamicData(dynData), _data(data) {}
+
+ void drawSelf(bool draw, bool restore);
+
+protected:
+ uint32 _dynamicData;
+ const WidgetDrawData *_data;
+};
+
+class ThemeItemTextData : public ThemeItem {
+public:
+ ThemeItemTextData(ThemeEngine *engine, const TextDrawData *data, const Common::Rect &area, const Common::String &text,
+ GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV,
+ bool ellipsis, bool restoreBg, int deltaX) :
+ ThemeItem(engine, area), _data(data), _text(text), _alignH(alignH), _alignV(alignV),
+ _ellipsis(ellipsis), _restoreBg(restoreBg), _deltax(deltaX) {}
+
+ void drawSelf(bool draw, bool restore);
+
+protected:
+ const TextDrawData *_data;
+ Common::String _text;
+ GUI::Theme::TextAlign _alignH;
+ GUI::Theme::TextAlignVertical _alignV;
+ bool _ellipsis;
+ bool _restoreBg;
+ int _deltax;
+};
+
+class ThemeItemBitmap : public ThemeItem {
+public:
+ ThemeItemBitmap(ThemeEngine *engine, const Common::Rect &area, const Graphics::Surface *bitmap, bool alpha) :
+ ThemeItem(engine, area), _bitmap(bitmap), _alpha(alpha) {}
+
+ void drawSelf(bool draw, bool restore);
+
+protected:
+ const Graphics::Surface *_bitmap;
+ bool _alpha;
+};
+
+
+class ThemeEngine : public Theme {
protected:
typedef Common::String String;
typedef GUI::Dialog Dialog;
@@ -92,9 +149,6 @@ protected:
friend class GUI::Dialog;
friend class GUI::GuiObject;
-
- /** Constant value to expand dirty rectangles, to make sure they are fully copied */
- static const int kDirtyRectangleThreshold = 1;
/** Sets whether backcaching is enabled */
static const bool kEnableBackCaching = true;
@@ -158,16 +212,6 @@ protected:
DrawData parent; /** Parent DrawData item, for items that overlay. E.g. kButtonIdle -> kButtonHover */
} kDrawDataDefaults[];
- /**
- * Queue Node for the drawing queue.
- * Specifies the exact drawing to be done when processing
- * the drawing queues.
- */
- struct DrawQueue {
- DrawData type; /** DrawData item to draw. */
- Common::Rect area; /** Place on screen to draw it. */
- uint32 dynData; /** Dynamic data which modifies the DrawData item (optional)*/
- };
enum TextData {
kTextDataNone = -1,
@@ -186,23 +230,6 @@ protected:
const char *name;
} kTextDataDefaults[];
- struct DrawQueueText {
- TextData type;
- Common::Rect area;
- Common::String text;
-
- GUI::Theme::TextAlign alignH;
- GUI::Theme::TextAlignVertical alignV;
- bool ellipsis;
- bool restoreBg;
- int deltax;
- };
-
- struct BitmapQueue {
- const Graphics::Surface *bitmap;
- Common::Rect area;
- bool alpha;
- };
public:
/** Graphics mode enumeration.
@@ -215,21 +242,24 @@ public:
kGfxAntialias16bit, /** 2BPP with the optimized AA renderer. */
kGfxMAX
};
+
+ /** Constant value to expand dirty rectangles, to make sure they are fully copied */
+ static const int kDirtyRectangleThreshold = 1;
static const char *rendererModeLabels[];
/** Default constructor */
- ThemeRenderer(Common::String fileName, GraphicsMode mode);
+ ThemeEngine(Common::String fileName, GraphicsMode mode);
/** Default destructor */
- ~ThemeRenderer();
+ ~ThemeEngine();
GUI::ThemeEval *themeEval() { return _themeEval; }
/**
* VIRTUAL METHODS
* This is the implementation of the GUI::Theme API to allow
- * the ThemeRenderer class to be plugged in as any other GUI
+ * the ThemeEngine class to be plugged in as any other GUI
* theme. In fact, the renderer works like any other GUI theme,
* but supports extensive customization of the drawn widgets.
*/
@@ -453,13 +483,14 @@ public:
/**
- * Finishes buffering: widgets from there one will be drawn straight on the screen
+ * Finishes buffering: widgets from then on will be drawn straight on the screen
* without drawing queues.
*/
void finishBuffering() { _buffering = false; }
void startBuffering() { _buffering = true; }
ThemeEval *evaluator() { return _themeEval; }
+ VectorRenderer *renderer() { return _vectorRenderer; }
bool supportsImages() const { return true; }
bool ownCursor() const { return _useCursor; }
@@ -486,11 +517,29 @@ public:
*/
bool createCursor(const Common::String &filename, int hotspotX, int hotspotY, int scale);
+ /**
+ * Wrapper for restoring data from the Back Buffer to the screen.
+ * The actual processing is done in the VectorRenderer.
+ *
+ * @param r Area to restore.
+ * @param special Deprecated.
+ */
+ void restoreBackground(Common::Rect r, bool special = false);
+
+ /**
+ * Checks if a given DrawData set for a widget has been cached beforehand
+ * and is ready to be blit into the screen.
+ *
+ * @param type DrawData type of the widget.
+ * @param r Size of the widget which is expected to be cached.
+ */
+ bool isWidgetCached(DrawData type, const Common::Rect &r);
+
protected:
const Common::String &getThemeName() const { return _themeName; }
const Common::String &getThemeFileName() const { return _themeFileName; }
- int getThemeRenderer() const { return _graphicsMode; }
+ int getGraphicsMode() const { return _graphicsMode; }
/**
* Initializes the drawing screen surfaces, _screen and _backBuffer.
@@ -503,7 +552,7 @@ protected:
template<typename PixelType> void screenInit(bool backBuffer = true);
/**
- * Loads the given theme into the ThemeRenderer.
+ * Loads the given theme into the ThemeEngine.
* Note that ThemeName is an identifier, not a filename.
*
* @param ThemeName Theme identifier.
@@ -575,15 +624,6 @@ protected:
}
/**
- * Checks if a given DrawData set for a widget has been cached beforehand
- * and is ready to be blit into the screen.
- *
- * @param type DrawData type of the widget.
- * @param r Size of the widget which is expected to be cached.
- */
- bool isWidgetCached(DrawData type, const Common::Rect &r);
-
- /**
* Draws a cached widget directly on the screen. Currently deprecated.
*
* @param type DrawData type of the widget.
@@ -601,19 +641,6 @@ protected:
* @param type DrawData type of the widget.
*/
void calcBackgroundOffset(DrawData type);
-
- /**
- * Draws a DrawQueue item (which contains DrawData information and a screen
- * position) into the screen.
- *
- * This is the only way the Theme has to drawn on the screen.
- *
- * @param draw Sets if the DrawData info will be actually drawn.
- * @param restore Sets if the background behind the widget will be restored before drawing.
- */
- inline void drawDD(const DrawQueue &q, bool draw = true, bool restore = false);
- inline void drawDDText(const DrawQueueText &q);
- inline void drawBitmap(const BitmapQueue &q);
/**
* Generates a DrawQueue item and enqueues it so it's drawn to the screen
@@ -636,16 +663,6 @@ protected:
*/
inline void debugWidgetPosition(const char *name, const Common::Rect &r);
-
- /**
- * Wrapper for restoring data from the Back Buffer to the screen.
- * The actual processing is done in the VectorRenderer.
- *
- * @param r Area to restore.
- * @param special Deprecated.
- */
- void restoreBackground(Common::Rect r, bool special = false);
-
/**
* Default values from GUI::Theme
@@ -697,15 +714,10 @@ protected:
Common::List<Common::Rect> _dirtyScreen;
/** Queue with all the drawing that must be done to the Back Buffer */
- Common::List<DrawQueue> _bufferQueue;
+ Common::List<ThemeItem*> _bufferQueue;
/** Queue with all the drawing that must be done to the screen */
- Common::List<DrawQueue> _screenQueue;
-
- /** Queue with all the text drawing that must be done to the screen */
- Common::List<DrawQueueText> _textQueue;
-
- Common::List<BitmapQueue> _bitmapQueue;
+ Common::List<ThemeItem*> _screenQueue;
bool _initOk; /** Class and renderer properly initialized */
bool _themeOk; /** Theme data successfully loaded. */
diff --git a/gui/ThemeEval.cpp b/gui/ThemeEval.cpp
index 614f2089d1..112cda59a1 100644
--- a/gui/ThemeEval.cpp
+++ b/gui/ThemeEval.cpp
@@ -31,150 +31,11 @@
#include "common/xmlparser.h"
#include "graphics/scaler.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "gui/ThemeParser.h"
#include "gui/ThemeEval.h"
namespace GUI {
-
-bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
- if (name == _name) {
- x = _x; y = _y;
- w = _w; h = _h;
- return true;
- }
-
- return false;
-}
-
-bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
- for (uint i = 0; i < _children.size(); ++i) {
- if (_children[i]->getWidgetData(name, x, y, w, h))
- return true;
- }
-
- return false;
-}
-
-void ThemeLayoutMain::reflowLayout() {
- assert(_children.size() <= 1);
-
- if (_children.size()) {
- _children[0]->resetLayout();
- _children[0]->setWidth(_w);
- _children[0]->setHeight(_h);
- _children[0]->reflowLayout();
-
- if (_w == -1)
- _w = _children[0]->getWidth();
-
- if (_h == -1)
- _h = _children[0]->getHeight();
-
- if (_y == -1)
- _y = (g_system->getOverlayHeight() >> 1) - (_h >> 1);
-
- if (_x == -1)
- _x = (g_system->getOverlayWidth() >> 1) - (_w >> 1);
- }
-}
-
-void ThemeLayoutVertical::reflowLayout() {
- int curX, curY;
- int resize[8];
- int rescount = 0;
-
- curX = _paddingLeft;
- curY = _paddingTop;
- _h = _paddingTop + _paddingBottom;
-
- for (uint i = 0; i < _children.size(); ++i) {
-
- _children[i]->resetLayout();
- _children[i]->reflowLayout();
-
- if (_children[i]->getWidth() == -1)
- _children[i]->setWidth((_w == -1 ? getParentW() : _w) - _paddingLeft - _paddingRight);
-
- if (_children[i]->getHeight() == -1) {
- resize[rescount++] = i;
- _children[i]->setHeight(0);
- }
-
- _children[i]->setY(curY);
-
- if (_centered && _children[i]->getWidth() < _w && _w != -1) {
- _children[i]->setX((_w >> 1) - (_children[i]->getWidth() >> 1));
- }
- else
- _children[i]->setX(curX);
-
- curY += _children[i]->getHeight() + _spacing;
- _w = MAX(_w, (int16)(_children[i]->getWidth() + _paddingLeft + _paddingRight));
- _h += _children[i]->getHeight() + _spacing;
- }
-
- _h -= _spacing;
-
- if (rescount) {
- int newh = (getParentH() - _h - _paddingBottom) / rescount;
-
- for (int i = 0; i < rescount; ++i) {
- _children[resize[i]]->setHeight(newh);
- _h += newh;
- for (uint j = resize[i] + 1; j < _children.size(); ++j)
- _children[j]->setY(newh);
- }
- }
-}
-
-void ThemeLayoutHorizontal::reflowLayout() {
- int curX, curY;
- int resize[8];
- int rescount = 0;
-
- curX = _paddingLeft;
- curY = _paddingTop;
- _w = _paddingLeft + _paddingRight;
-
- for (uint i = 0; i < _children.size(); ++i) {
-
- _children[i]->resetLayout();
- _children[i]->reflowLayout();
-
- if (_children[i]->getHeight() == -1)
- _children[i]->setHeight((_h == -1 ? getParentH() : _h) - _paddingTop - _paddingBottom);
-
- if (_children[i]->getWidth() == -1) {
- resize[rescount++] = i;
- _children[i]->setWidth(0);
- }
-
- _children[i]->setX(curX);
-
- if (_centered && _children[i]->getHeight() < _h && _h != -1)
- _children[i]->setY((_h >> 1) - (_children[i]->getHeight() >> 1));
- else
- _children[i]->setY(curY);
-
- curX += (_children[i]->getWidth() + _spacing);
- _w += _children[i]->getWidth() + _spacing;
- _h = MAX(_h, (int16)(_children[i]->getHeight() + _paddingTop + _paddingBottom));
- }
-
- _w -= _spacing;
-
- if (rescount) {
- int neww = (getParentW() - _w - _paddingRight) / rescount;
-
- for (int i = 0; i < rescount; ++i) {
- _children[resize[i]]->setWidth(neww);
- _w += neww;
- for (uint j = resize[i] + 1; j < _children.size(); ++j)
- _children[j]->setX(neww);
- }
- }
-}
ThemeEval::~ThemeEval() {
reset();
@@ -199,6 +60,35 @@ void ThemeEval::buildBuiltinVars() {
_builtin["kBigWidgetSize"] = GUI::kBigWidgetSize;
}
+void ThemeEval::reset() {
+ _vars.clear();
+ _curDialog.clear();
+ _curLayout.clear();
+
+ for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
+ delete i->_value;
+
+ _layouts.clear();
+}
+
+bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) {
+ Common::StringTokenizer tokenizer(widget, ".");
+
+ if (widget.hasPrefix("Dialog."))
+ tokenizer.nextToken();
+
+ Common::String dialogName = "Dialog." + tokenizer.nextToken();
+ Common::String widgetName = tokenizer.nextToken();
+
+ if (!_layouts.contains(dialogName))
+ return false;
+
+ if (widgetName.empty())
+ return _layouts[dialogName]->getDialogData(x, y, w, h);
+
+ return _layouts[dialogName]->getWidgetData(widgetName, x, y, w, h);
+}
+
void ThemeEval::addWidget(const Common::String &name, int w, int h, const Common::String &type, bool enabled) {
int typeW = -1;
diff --git a/gui/ThemeEval.h b/gui/ThemeEval.h
index 8d55ff6066..a25ff21a88 100644
--- a/gui/ThemeEval.h
+++ b/gui/ThemeEval.h
@@ -33,267 +33,13 @@
#include "common/hash-str.h"
#include "common/xmlparser.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "gui/ThemeParser.h"
#include "gui/ThemeEval.h"
+#include "gui/ThemeLayout.h"
namespace GUI {
-class ThemeLayout {
-
-public:
- enum LayoutType {
- kLayoutMain,
- kLayoutVertical,
- kLayoutHorizontal,
- kLayoutWidget
- };
-
- ThemeLayout(ThemeLayout *p, const Common::String &name) :
- _parent(p), _name(name), _x(0), _y(0), _w(-1), _h(-1),
- _paddingLeft(0), _paddingRight(0), _paddingTop(0), _paddingBottom(0),
- _centered(false), _defaultW(-1), _defaultH(-1) { }
-
- virtual ~ThemeLayout() {
- for (uint i = 0; i < _children.size(); ++i)
- delete _children[i];
- }
-
- virtual void reflowLayout() = 0;
-
- virtual void resetLayout() {
- _x = 0;
- _y = 0;
- _w = _defaultW;
- _h = _defaultH;
- }
-
- void addChild(ThemeLayout *child) { _children.push_back(child); }
-
- void setPadding(int8 left, int8 right, int8 top, int8 bottom) {
- _paddingLeft = left;
- _paddingRight = right;
- _paddingTop = top;
- _paddingBottom = bottom;
- }
-
- void setSpacing(int8 spacing) {
- _spacing = spacing;
- }
-
- int16 getParentX() { return _parent ? _parent->_x : 0; }
- int16 getParentY() { return _parent ? _parent->_y : 0; }
-
- int16 getParentW() {
- ThemeLayout *p = _parent;
- int width = 0;
-
- while (p && p->getLayoutType() != kLayoutMain) {
- width += p->_paddingRight + p->_paddingLeft;
- if (p->getLayoutType() == kLayoutHorizontal) {
- for (uint i = 0; i < p->_children.size(); ++i)
- width += p->_children[i]->getHeight() + p->_spacing;
- }
- p = p->_parent;
- }
-
- return p->getWidth() - width;
- }
-
- int16 getParentH() {
- ThemeLayout *p = _parent;
- int height = 0;
-
- while (p && p->getLayoutType() != kLayoutMain) {
- height += p->_paddingBottom + p->_paddingTop;
- if (p->getLayoutType() == kLayoutVertical) {
- for (uint i = 0; i < p->_children.size(); ++i)
- height += p->_children[i]->getHeight() + p->_spacing;
- }
- p = p->_parent;
- }
-
- return p->getHeight() - height;
- }
-
- int16 getX() { return _x; }
- int16 getY() { return _y; }
- int16 getWidth() { return _w; }
- int16 getHeight() { return _h; }
-
- void setX(int newX) {
- _x += newX;
- for (uint i = 0; i < _children.size(); ++i)
- _children[i]->setX(newX);
- }
-
- void setY(int newY) {
- _y += newY;
- for (uint i = 0; i < _children.size(); ++i)
- _children[i]->setY(newY);
- }
-
- void setWidth(int16 width) { _w = width; }
- void setHeight(int16 height) { _h = height; }
-
- void debugDraw(Graphics::Surface *screen, const Graphics::Font *font) {
- uint16 color = 0xFFFF;
- font->drawString(screen, getName(), _x, _y, _w, color, Graphics::kTextAlignRight, 0, true);
- screen->hLine(_x, _y, _x + _w, color);
- screen->hLine(_x, _y + _h, _x + _w , color);
- screen->vLine(_x, _y, _y + _h, color);
- screen->vLine(_x + _w, _y, _y + _h, color);
-
- for (uint i = 0; i < _children.size(); ++i)
- _children[i]->debugDraw(screen, font);
- }
-
- virtual LayoutType getLayoutType() = 0;
- virtual const char *getName() { return _name.c_str(); }
-
- virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
-
- virtual bool getDialogData(int16 &x, int16 &y, uint16 &w, uint16 &h) {
- assert(getLayoutType() == kLayoutMain);
- x = _x; y = _y;
- w = _w; h = _h;
- return true;
- }
-
- virtual ThemeLayout *buildCopy() = 0;
-
- void importLayout(ThemeLayout *layout) {
- assert(layout->getLayoutType() == kLayoutMain);
-
- if (layout->_children.size() == 0)
- return;
-
- layout = layout->_children[0];
-
- if (getLayoutType() == layout->getLayoutType()) {
- for (uint i = 0; i < layout->_children.size(); ++i)
- _children.push_back(layout->_children[i]->buildCopy());
- } else {
- _children.push_back(layout->buildCopy());
- }
- }
-
-protected:
- int16 _x, _y, _w, _h;
- int16 _defaultW, _defaultH;
- int8 _paddingTop, _paddingBottom, _paddingLeft, _paddingRight;
- int8 _spacing;
- Common::Array<ThemeLayout*> _children;
- ThemeLayout *_parent;
- bool _centered;
- Common::String _name;
-};
-
-class ThemeLayoutMain : public ThemeLayout {
-public:
- ThemeLayoutMain(int16 x, int16 y, int16 w, int16 h) : ThemeLayout(0, "") {
- _w = _defaultW = w;
- _h = _defaultH = h;
- _x = _defaultX = x;
- _y = _defaultY = y;
- }
- void reflowLayout();
-
- void resetLayout() {
- ThemeLayout::resetLayout();
- _x = _defaultX;
- _y = _defaultY;
- }
-
- const char *getName() { return "Global Layout"; }
- LayoutType getLayoutType() { return kLayoutMain; }
-
- ThemeLayout *buildCopy() { assert(!"Do not copy Main Layouts!"); return 0; }
-
-protected:
- int16 _defaultX;
- int16 _defaultY;
-};
-
-class ThemeLayoutVertical : public ThemeLayout {
-public:
- ThemeLayoutVertical(ThemeLayout *p, int spacing, bool center) :
- ThemeLayout(p, "") {
- _spacing = spacing;
- _centered = center;
- }
-
- void reflowLayout();
- const char *getName() { return "Vertical Layout"; }
- LayoutType getLayoutType() { return kLayoutVertical; }
-
-
- ThemeLayout *buildCopy() {
- ThemeLayoutVertical *n = new ThemeLayoutVertical(*this);
-
- for (uint i = 0; i < n->_children.size(); ++ i)
- n->_children[i] = n->_children[i]->buildCopy();
-
- return n;
- }
-};
-
-class ThemeLayoutHorizontal : public ThemeLayout {
-public:
- ThemeLayoutHorizontal(ThemeLayout *p, int spacing, bool center) :
- ThemeLayout(p, "") {
- _spacing = spacing;
- _centered = center;
- }
-
- void reflowLayout();
- const char *getName() { return "Horizontal Layout"; }
- LayoutType getLayoutType() { return kLayoutHorizontal; }
-
- ThemeLayout *buildCopy() {
- ThemeLayoutHorizontal *n = new ThemeLayoutHorizontal(*this);
-
- for (uint i = 0; i < n->_children.size(); ++ i)
- n->_children[i] = n->_children[i]->buildCopy();
-
- return n;
- }
-};
-
-class ThemeLayoutWidget : public ThemeLayout {
-public:
- ThemeLayoutWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h) : ThemeLayout(p, name) {
- _w = _defaultW = w;
- _h = _defaultH = h;
- }
-
- bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
- void reflowLayout() {}
- LayoutType getLayoutType() { return kLayoutWidget; }
-
- ThemeLayout *buildCopy() { return new ThemeLayoutWidget(*this); }
-};
-
-class ThemeLayoutSpacing : public ThemeLayout {
-public:
- ThemeLayoutSpacing(ThemeLayout *p, int size) : ThemeLayout(p, "") {
- if (p->getLayoutType() == kLayoutHorizontal) {
- _w = _defaultW = size;
- _h = _defaultH = 1;
- } else if (p->getLayoutType() == kLayoutVertical) {
- _w = _defaultW = 1;
- _h = _defaultH = size;
- }
- }
-
- bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) { return false; }
- void reflowLayout() {}
- LayoutType getLayoutType() { return kLayoutWidget; }
- const char *getName() { return "SPACE"; }
-
- ThemeLayout *buildCopy() { return new ThemeLayoutSpacing(*this); }
-};
-
class ThemeEval {
typedef Common::HashMap<Common::String, int> VariablesMap;
@@ -339,55 +85,20 @@ public:
bool addImportedLayout(const Common::String &name);
void addSpace(int size);
- void addPadding(int16 l, int16 r, int16 t, int16 b) {
- _curLayout.top()->setPadding(l, r, t, b);
- }
+ void addPadding(int16 l, int16 r, int16 t, int16 b) { _curLayout.top()->setPadding(l, r, t, b); }
void closeLayout() { _curLayout.pop(); }
void closeDialog() { _curLayout.pop()->reflowLayout(); _curDialog.clear(); }
- bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) {
- Common::StringTokenizer tokenizer(widget, ".");
-
- if (widget.hasPrefix("Dialog."))
- tokenizer.nextToken();
-
- Common::String dialogName = "Dialog." + tokenizer.nextToken();
- Common::String widgetName = tokenizer.nextToken();
-
- if (!_layouts.contains(dialogName))
- return false;
-
- if (widgetName.empty())
- return _layouts[dialogName]->getDialogData(x, y, w, h);
-
- return _layouts[dialogName]->getWidgetData(widgetName, x, y, w, h);
- }
-
- void debugPrint() {
- printf("Debug variable list:\n");
-
- VariablesMap::const_iterator i;
- for (i = _vars.begin(); i != _vars.end(); ++i) {
- printf(" '%s' = %d\n", i->_key.c_str(), i->_value);
- }
- }
+ bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h);
+#ifdef LAYOUT_DEBUG_DIALOG
void debugDraw(Graphics::Surface *screen, const Graphics::Font *font) {
- _layouts["Dialog.Launcher"]->debugDraw(screen, font);
-// _layouts["Dialog.GameOptions_Graphics"]->debugDraw(screen, font);
+ _layouts[LAYOUT_DEBUG_DIALOG]->debugDraw(screen, font);
}
+#endif
- void reset() {
- _vars.clear();
- _curDialog.clear();
- _curLayout.clear();
-
- for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
- delete i->_value;
-
- _layouts.clear();
- }
+ void reset();
private:
VariablesMap _vars;
diff --git a/gui/ThemeLayout.cpp b/gui/ThemeLayout.cpp
new file mode 100644
index 0000000000..a70fb6cdc6
--- /dev/null
+++ b/gui/ThemeLayout.cpp
@@ -0,0 +1,227 @@
+/* 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$
+ *
+ */
+#include "common/util.h"
+#include "common/system.h"
+#include "common/events.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+#include "common/xmlparser.h"
+#include "graphics/scaler.h"
+
+#include "gui/ThemeEval.h"
+#include "gui/ThemeLayout.h"
+
+namespace GUI {
+
+void ThemeLayout::importLayout(ThemeLayout *layout) {
+ assert(layout->getLayoutType() == kLayoutMain);
+
+ if (layout->_children.size() == 0)
+ return;
+
+ layout = layout->_children[0];
+
+ if (getLayoutType() == layout->getLayoutType()) {
+ for (uint i = 0; i < layout->_children.size(); ++i)
+ _children.push_back(layout->_children[i]->buildCopy());
+ } else {
+ _children.push_back(layout->buildCopy());
+ }
+}
+
+bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
+ for (uint i = 0; i < _children.size(); ++i) {
+ if (_children[i]->getWidgetData(name, x, y, w, h))
+ return true;
+ }
+
+ return false;
+}
+
+int16 ThemeLayout::getParentW() {
+ ThemeLayout *p = _parent;
+ int width = 0;
+
+ while (p && p->getLayoutType() != kLayoutMain) {
+ width += p->_paddingRight + p->_paddingLeft;
+ if (p->getLayoutType() == kLayoutHorizontal) {
+ for (uint i = 0; i < p->_children.size(); ++i)
+ width += p->_children[i]->getHeight() + p->_spacing;
+ }
+ p = p->_parent;
+ }
+
+ return p->getWidth() - width;
+}
+
+int16 ThemeLayout::getParentH() {
+ ThemeLayout *p = _parent;
+ int height = 0;
+
+ while (p && p->getLayoutType() != kLayoutMain) {
+ height += p->_paddingBottom + p->_paddingTop;
+ if (p->getLayoutType() == kLayoutVertical) {
+ for (uint i = 0; i < p->_children.size(); ++i)
+ height += p->_children[i]->getHeight() + p->_spacing;
+ }
+ p = p->_parent;
+ }
+
+ return p->getHeight() - height;
+}
+
+
+bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
+ if (name == _name) {
+ x = _x; y = _y;
+ w = _w; h = _h;
+ return true;
+ }
+
+ return false;
+}
+
+void ThemeLayoutMain::reflowLayout() {
+ assert(_children.size() <= 1);
+
+ if (_children.size()) {
+ _children[0]->resetLayout();
+ _children[0]->setWidth(_w);
+ _children[0]->setHeight(_h);
+ _children[0]->reflowLayout();
+
+ if (_w == -1)
+ _w = _children[0]->getWidth();
+
+ if (_h == -1)
+ _h = _children[0]->getHeight();
+
+ if (_y == -1)
+ _y = (g_system->getOverlayHeight() >> 1) - (_h >> 1);
+
+ if (_x == -1)
+ _x = (g_system->getOverlayWidth() >> 1) - (_w >> 1);
+ }
+}
+
+void ThemeLayoutVertical::reflowLayout() {
+ int curX, curY;
+ int resize[8];
+ int rescount = 0;
+
+ curX = _paddingLeft;
+ curY = _paddingTop;
+ _h = _paddingTop + _paddingBottom;
+
+ for (uint i = 0; i < _children.size(); ++i) {
+
+ _children[i]->resetLayout();
+ _children[i]->reflowLayout();
+
+ if (_children[i]->getWidth() == -1)
+ _children[i]->setWidth((_w == -1 ? getParentW() : _w) - _paddingLeft - _paddingRight);
+
+ if (_children[i]->getHeight() == -1) {
+ resize[rescount++] = i;
+ _children[i]->setHeight(0);
+ }
+
+ _children[i]->setY(curY);
+
+ if (_centered && _children[i]->getWidth() < _w && _w != -1) {
+ _children[i]->setX((_w >> 1) - (_children[i]->getWidth() >> 1));
+ }
+ else
+ _children[i]->setX(curX);
+
+ curY += _children[i]->getHeight() + _spacing;
+ _w = MAX(_w, (int16)(_children[i]->getWidth() + _paddingLeft + _paddingRight));
+ _h += _children[i]->getHeight() + _spacing;
+ }
+
+ _h -= _spacing;
+
+ if (rescount) {
+ int newh = (getParentH() - _h - _paddingBottom) / rescount;
+
+ for (int i = 0; i < rescount; ++i) {
+ _children[resize[i]]->setHeight(newh);
+ _h += newh;
+ for (uint j = resize[i] + 1; j < _children.size(); ++j)
+ _children[j]->setY(newh);
+ }
+ }
+}
+
+void ThemeLayoutHorizontal::reflowLayout() {
+ int curX, curY;
+ int resize[8];
+ int rescount = 0;
+
+ curX = _paddingLeft;
+ curY = _paddingTop;
+ _w = _paddingLeft + _paddingRight;
+
+ for (uint i = 0; i < _children.size(); ++i) {
+
+ _children[i]->resetLayout();
+ _children[i]->reflowLayout();
+
+ if (_children[i]->getHeight() == -1)
+ _children[i]->setHeight((_h == -1 ? getParentH() : _h) - _paddingTop - _paddingBottom);
+
+ if (_children[i]->getWidth() == -1) {
+ resize[rescount++] = i;
+ _children[i]->setWidth(0);
+ }
+
+ _children[i]->setX(curX);
+
+ if (_centered && _children[i]->getHeight() < _h && _h != -1)
+ _children[i]->setY((_h >> 1) - (_children[i]->getHeight() >> 1));
+ else
+ _children[i]->setY(curY);
+
+ curX += (_children[i]->getWidth() + _spacing);
+ _w += _children[i]->getWidth() + _spacing;
+ _h = MAX(_h, (int16)(_children[i]->getHeight() + _paddingTop + _paddingBottom));
+ }
+
+ _w -= _spacing;
+
+ if (rescount) {
+ int neww = (getParentW() - _w - _paddingRight) / rescount;
+
+ for (int i = 0; i < rescount; ++i) {
+ _children[resize[i]]->setWidth(neww);
+ _w += neww;
+ for (uint j = resize[i] + 1; j < _children.size(); ++j)
+ _children[j]->setX(neww);
+ }
+ }
+}
+
+
+} \ No newline at end of file
diff --git a/gui/ThemeLayout.h b/gui/ThemeLayout.h
new file mode 100644
index 0000000000..293804d822
--- /dev/null
+++ b/gui/ThemeLayout.h
@@ -0,0 +1,239 @@
+/* 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 THEME_LAYOUT_H
+#define THEME_LAYOUT_H
+
+namespace GUI {
+
+class ThemeLayout {
+
+public:
+ enum LayoutType {
+ kLayoutMain,
+ kLayoutVertical,
+ kLayoutHorizontal,
+ kLayoutWidget
+ };
+
+ ThemeLayout(ThemeLayout *p, const Common::String &name) :
+ _parent(p), _name(name), _x(0), _y(0), _w(-1), _h(-1),
+ _paddingLeft(0), _paddingRight(0), _paddingTop(0), _paddingBottom(0),
+ _centered(false), _defaultW(-1), _defaultH(-1) { }
+
+ virtual ~ThemeLayout() {
+ for (uint i = 0; i < _children.size(); ++i)
+ delete _children[i];
+ }
+
+ virtual void reflowLayout() = 0;
+
+ virtual void resetLayout() { _x = 0; _y = 0; _w = _defaultW; _h = _defaultH; }
+
+ void addChild(ThemeLayout *child) { _children.push_back(child); }
+
+ void setPadding(int8 left, int8 right, int8 top, int8 bottom) {
+ _paddingLeft = left;
+ _paddingRight = right;
+ _paddingTop = top;
+ _paddingBottom = bottom;
+ }
+
+ void setSpacing(int8 spacing) {
+ _spacing = spacing;
+ }
+
+ int16 getParentX() { return _parent ? _parent->_x : 0; }
+ int16 getParentY() { return _parent ? _parent->_y : 0; }
+ int16 getParentW();
+ int16 getParentH();
+ int16 getX() { return _x; }
+ int16 getY() { return _y; }
+ int16 getWidth() { return _w; }
+ int16 getHeight() { return _h; }
+
+ void setX(int newX) {
+ _x += newX;
+ for (uint i = 0; i < _children.size(); ++i)
+ _children[i]->setX(newX);
+ }
+
+ void setY(int newY) {
+ _y += newY;
+ for (uint i = 0; i < _children.size(); ++i)
+ _children[i]->setY(newY);
+ }
+
+ void setWidth(int16 width) { _w = width; }
+ void setHeight(int16 height) { _h = height; }
+
+#ifdef LAYOUT_DEBUG_DIALOG
+ void debugDraw(Graphics::Surface *screen, const Graphics::Font *font) {
+ uint16 color = 0xFFFF;
+ font->drawString(screen, getName(), _x, _y, _w, color, Graphics::kTextAlignRight, 0, true);
+ screen->hLine(_x, _y, _x + _w, color);
+ screen->hLine(_x, _y + _h, _x + _w , color);
+ screen->vLine(_x, _y, _y + _h, color);
+ screen->vLine(_x + _w, _y, _y + _h, color);
+
+ for (uint i = 0; i < _children.size(); ++i)
+ _children[i]->debugDraw(screen, font);
+ }
+#endif
+
+ virtual LayoutType getLayoutType() = 0;
+ virtual const char *getName() { return _name.c_str(); }
+
+ virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
+
+ virtual bool getDialogData(int16 &x, int16 &y, uint16 &w, uint16 &h) {
+ assert(getLayoutType() == kLayoutMain);
+ x = _x; y = _y;
+ w = _w; h = _h;
+ return true;
+ }
+
+ virtual ThemeLayout *buildCopy() = 0;
+ void importLayout(ThemeLayout *layout);
+
+protected:
+ int16 _x, _y, _w, _h;
+ int16 _defaultW, _defaultH;
+ int8 _paddingTop, _paddingBottom, _paddingLeft, _paddingRight;
+ int8 _spacing;
+ Common::Array<ThemeLayout*> _children;
+ ThemeLayout *_parent;
+ bool _centered;
+ Common::String _name;
+};
+
+class ThemeLayoutMain : public ThemeLayout {
+public:
+ ThemeLayoutMain(int16 x, int16 y, int16 w, int16 h) : ThemeLayout(0, "") {
+ _w = _defaultW = w;
+ _h = _defaultH = h;
+ _x = _defaultX = x;
+ _y = _defaultY = y;
+ }
+ void reflowLayout();
+
+ void resetLayout() {
+ ThemeLayout::resetLayout();
+ _x = _defaultX;
+ _y = _defaultY;
+ }
+
+ const char *getName() { return "Global Layout"; }
+ LayoutType getLayoutType() { return kLayoutMain; }
+
+ ThemeLayout *buildCopy() { assert(!"Do not copy Main Layouts!"); return 0; }
+
+protected:
+ int16 _defaultX;
+ int16 _defaultY;
+};
+
+class ThemeLayoutVertical : public ThemeLayout {
+public:
+ ThemeLayoutVertical(ThemeLayout *p, int spacing, bool center) :
+ ThemeLayout(p, "") {
+ _spacing = spacing;
+ _centered = center;
+ }
+
+ void reflowLayout();
+ const char *getName() { return "Vertical Layout"; }
+ LayoutType getLayoutType() { return kLayoutVertical; }
+
+
+ ThemeLayout *buildCopy() {
+ ThemeLayoutVertical *n = new ThemeLayoutVertical(*this);
+
+ for (uint i = 0; i < n->_children.size(); ++ i)
+ n->_children[i] = n->_children[i]->buildCopy();
+
+ return n;
+ }
+};
+
+class ThemeLayoutHorizontal : public ThemeLayout {
+public:
+ ThemeLayoutHorizontal(ThemeLayout *p, int spacing, bool center) :
+ ThemeLayout(p, "") {
+ _spacing = spacing;
+ _centered = center;
+ }
+
+ void reflowLayout();
+ const char *getName() { return "Horizontal Layout"; }
+ LayoutType getLayoutType() { return kLayoutHorizontal; }
+
+ ThemeLayout *buildCopy() {
+ ThemeLayoutHorizontal *n = new ThemeLayoutHorizontal(*this);
+
+ for (uint i = 0; i < n->_children.size(); ++ i)
+ n->_children[i] = n->_children[i]->buildCopy();
+
+ return n;
+ }
+};
+
+class ThemeLayoutWidget : public ThemeLayout {
+public:
+ ThemeLayoutWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h) : ThemeLayout(p, name) {
+ _w = _defaultW = w;
+ _h = _defaultH = h;
+ }
+
+ bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
+ void reflowLayout() {}
+ LayoutType getLayoutType() { return kLayoutWidget; }
+
+ ThemeLayout *buildCopy() { return new ThemeLayoutWidget(*this); }
+};
+
+class ThemeLayoutSpacing : public ThemeLayout {
+public:
+ ThemeLayoutSpacing(ThemeLayout *p, int size) : ThemeLayout(p, "") {
+ if (p->getLayoutType() == kLayoutHorizontal) {
+ _w = _defaultW = size;
+ _h = _defaultH = 1;
+ } else if (p->getLayoutType() == kLayoutVertical) {
+ _w = _defaultW = 1;
+ _h = _defaultH = size;
+ }
+ }
+
+ bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) { return false; }
+ void reflowLayout() {}
+ LayoutType getLayoutType() { return kLayoutWidget; }
+ const char *getName() { return "SPACE"; }
+
+ ThemeLayout *buildCopy() { return new ThemeLayoutSpacing(*this); }
+};
+
+}
+
+#endif \ No newline at end of file
diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp
index 2656f2a898..52fb90b2a6 100644
--- a/gui/ThemeParser.cpp
+++ b/gui/ThemeParser.cpp
@@ -30,7 +30,7 @@
#include "common/hash-str.h"
#include "common/xmlparser.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "gui/ThemeParser.h"
#include "gui/newgui.h"
#include "graphics/VectorRenderer.h"
@@ -40,7 +40,7 @@ namespace GUI {
using namespace Graphics;
using namespace Common;
-ThemeParser::ThemeParser(ThemeRenderer *parent) : XMLParser() {
+ThemeParser::ThemeParser(ThemeEngine *parent) : XMLParser() {
_drawFunctions["circle"] = &Graphics::VectorRenderer::drawCallback_CIRCLE;
_drawFunctions["square"] = &Graphics::VectorRenderer::drawCallback_SQUARE;
diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h
index 098bdb0540..67da93ff6c 100644
--- a/gui/ThemeParser.h
+++ b/gui/ThemeParser.h
@@ -36,19 +36,19 @@
#include "common/xmlparser.h"
#include "graphics/VectorRenderer.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
namespace GUI {
using namespace Graphics;
using namespace Common;
-class ThemeRenderer;
+class ThemeEngine;
class ThemeParser : public XMLParser {
typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const DrawStep &);
public:
- ThemeParser(GUI::ThemeRenderer *parent);
+ ThemeParser(GUI::ThemeEngine *parent);
virtual ~ThemeParser() {
delete _defaultStepGlobal;
@@ -69,7 +69,7 @@ public:
}
protected:
- ThemeRenderer *_theme;
+ ThemeEngine *_theme;
CUSTOM_XML_PARSER(ThemeParser) {
XML_KEY(render_info)
diff --git a/gui/module.mk b/gui/module.mk
index f1ba840459..f87ef36599 100644
--- a/gui/module.mk
+++ b/gui/module.mk
@@ -9,7 +9,7 @@ MODULE_OBJS := \
dialog.o \
editable.o \
EditTextWidget.o \
- ThemeRenderer.o \
+ ThemeEngine.o \
launcher.o \
ListWidget.o \
massadd.o \
@@ -24,6 +24,7 @@ MODULE_OBJS := \
widget.o \
theme.o \
ThemeEval.o \
+ ThemeLayout.o \
ThemeParser.o
# Include common rules
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index 2291d9e3c1..097a38291a 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -28,7 +28,7 @@
#include "graphics/cursorman.h"
#include "gui/newgui.h"
#include "gui/dialog.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
#include "common/config-manager.h"
@@ -96,7 +96,7 @@ NewGui::NewGui() : _redrawStatus(kRedrawDisabled),
// themefile += ".zip";
ConfMan.registerDefault("gui_renderer", 2);
- ThemeRenderer::GraphicsMode gfxMode = (ThemeRenderer::GraphicsMode)ConfMan.getInt("gui_renderer");
+ ThemeEngine::GraphicsMode gfxMode = (ThemeEngine::GraphicsMode)ConfMan.getInt("gui_renderer");
loadNewTheme(themefile, gfxMode);
_themeChange = false;
@@ -106,14 +106,14 @@ NewGui::~NewGui() {
delete _theme;
}
-bool NewGui::loadNewTheme(const Common::String &filename, ThemeRenderer::GraphicsMode gfx) {
- if (_theme && filename == _theme->getThemeFileName() && gfx == _theme->getThemeRenderer())
+bool NewGui::loadNewTheme(const Common::String &filename, ThemeEngine::GraphicsMode gfx) {
+ if (_theme && filename == _theme->getThemeFileName() && gfx == _theme->getGraphicsMode())
return true;
Common::String oldTheme = (_theme != 0) ? _theme->getThemeFileName() : "";
- if (gfx == ThemeRenderer::kGfxDisabled)
- gfx = (ThemeRenderer::GraphicsMode)ConfMan.getInt("gui_renderer");
+ if (gfx == ThemeEngine::kGfxDisabled)
+ gfx = (ThemeEngine::GraphicsMode)ConfMan.getInt("gui_renderer");
if (_theme)
_theme->disable();
@@ -126,7 +126,7 @@ bool NewGui::loadNewTheme(const Common::String &filename, ThemeRenderer::Graphic
delete _theme;
_theme = 0;
- _theme = new ThemeRenderer(filename, gfx);
+ _theme = new ThemeEngine(filename, gfx);
if (!_theme)
return (!oldTheme.empty() ? loadNewTheme(oldTheme) : false);
diff --git a/gui/newgui.h b/gui/newgui.h
index cc9e6b9f3c..9dace522ab 100644
--- a/gui/newgui.h
+++ b/gui/newgui.h
@@ -33,7 +33,7 @@
#include "gui/theme.h"
#include "gui/widget.h"
-#include "gui/ThemeRenderer.h"
+#include "gui/ThemeEngine.h"
class OSystem;
@@ -78,7 +78,7 @@ public:
bool isActive() const { return ! _dialogStack.empty(); }
- bool loadNewTheme(const Common::String &file, ThemeRenderer::GraphicsMode gfx = ThemeRenderer::kGfxDisabled);
+ bool loadNewTheme(const Common::String &file, ThemeEngine::GraphicsMode gfx = ThemeEngine::kGfxDisabled);
Theme *theme() { return _theme; }
ThemeEval *xmlEval() { return _theme->evaluator(); }
diff --git a/gui/options.cpp b/gui/options.cpp
index c24b338af6..110f7c9b69 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -736,8 +736,8 @@ GlobalOptionsDialog::GlobalOptionsDialog()
_rendererPopUp = new PopUpWidget(tab, "GlobalOptions_Misc.Renderer", "GUI Renderer:", labelWidth);
- for (int i = 1; i < GUI::ThemeRenderer::kGfxMAX; ++i) {
- _rendererPopUp->appendEntry(GUI::ThemeRenderer::rendererModeLabels[i], i);
+ for (int i = 1; i < GUI::ThemeEngine::kGfxMAX; ++i) {
+ _rendererPopUp->appendEntry(GUI::ThemeEngine::rendererModeLabels[i], i);
}
_autosavePeriodPopUp = new PopUpWidget(tab, "GlobalOptions_Misc.AutosavePeriod", "Autosave:", labelWidth);
@@ -845,7 +845,7 @@ void GlobalOptionsDialog::close() {
ConfMan.setInt("autosave_period", _autosavePeriodPopUp->getSelectedTag(), _domain);
if ((int)_rendererPopUp->getSelectedTag() != ConfMan.getInt("gui_renderer")) {
- g_gui.loadNewTheme(g_gui.theme()->getThemeFileName(), (GUI::ThemeRenderer::GraphicsMode)_rendererPopUp->getSelectedTag());
+ g_gui.loadNewTheme(g_gui.theme()->getThemeFileName(), (GUI::ThemeEngine::GraphicsMode)_rendererPopUp->getSelectedTag());
ConfMan.setInt("gui_renderer", _rendererPopUp->getSelectedTag(), _domain);
}
}
diff --git a/gui/theme.h b/gui/theme.h
index 50b2951ae5..57744db584 100644
--- a/gui/theme.h
+++ b/gui/theme.h
@@ -310,7 +310,7 @@ public:
virtual const Common::String &getThemeFileName() const = 0;
virtual const Common::String &getThemeName() const = 0;
- virtual int getThemeRenderer() const = 0;
+ virtual int getGraphicsMode() const = 0;
/**
* Checks if the theme renderer supports drawing of images.