From 1b0c29cb015e00d26db44391f994867f15d26f53 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 15 Aug 2008 11:05:25 +0000 Subject: Added popup widget in Options menu to change GUI renderer on the fly. svn-id: r33898 --- gui/ThemeRenderer.cpp | 8 +++++++- gui/ThemeRenderer.h | 6 +++++- gui/newgui.cpp | 17 ++++++++++++----- gui/newgui.h | 4 +++- gui/options.cpp | 16 +++++++++++++++- gui/options.h | 2 +- gui/theme.h | 1 + gui/themes/default.inc | 3 +++ gui/themes/scummclassic.zip | Bin 28291 -> 28494 bytes gui/themes/scummclassic/classic_layout.stx | 3 +++ gui/themes/scummodern.zip | Bin 122557 -> 123017 bytes gui/themes/scummodern/scummodern_layout.stx | 3 +++ gui/themes/scummodern/scummodern_layout_320.stx | 3 +++ gui/themes/scummtheme.py | 2 +- 14 files changed, 57 insertions(+), 11 deletions(-) diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp index f018910944..f33e152630 100644 --- a/gui/ThemeRenderer.cpp +++ b/gui/ThemeRenderer.cpp @@ -43,6 +43,12 @@ namespace GUI { using namespace Graphics; +const char *ThemeRenderer::rendererModeLabels[] = { + "Disabled GFX", + "Stardard Renderer (16bpp)", + "Antialiased Renderer (16bpp)" +}; + const ThemeRenderer::DrawDataInfo ThemeRenderer::kDrawDataDefaults[] = { {kDDMainDialogBackground, "mainmenu_bg", true, kDDNone}, {kDDSpecialColorBackground, "special_bg", true, kDDNone}, @@ -256,7 +262,7 @@ void ThemeRenderer::setGraphicsMode(GraphicsMode mode) { break; default: - return; + error("Invalid graphics mode"); } freeRenderer(); diff --git a/gui/ThemeRenderer.h b/gui/ThemeRenderer.h index 2b77121da0..e8f6d76ee2 100644 --- a/gui/ThemeRenderer.h +++ b/gui/ThemeRenderer.h @@ -212,9 +212,12 @@ public: enum GraphicsMode { kGfxDisabled = 0, /** No GFX */ kGfxStandard16bit, /** 2BPP with the standard (aliased) renderer. */ - kGfxAntialias16bit /** 2BPP with the optimized AA renderer. */ + kGfxAntialias16bit, /** 2BPP with the optimized AA renderer. */ + kGfxMAX }; + static const char *rendererModeLabels[]; + /** Default constructor */ ThemeRenderer(Common::String fileName, GraphicsMode mode); @@ -487,6 +490,7 @@ protected: const Common::String &getThemeName() const { return _themeName; } const Common::String &getThemeFileName() const { return _themeFileName; } + int getThemeRenderer() const { return _graphicsMode; } /** * Initializes the drawing screen surfaces, _screen and _backBuffer. diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 2fa0dc8620..d90431503d 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -58,8 +58,6 @@ void GuiObject::reflowLayout() { if (!g_gui.xmlEval()->getWidgetData(_name, _x, _y, _w, _h)) { warning("Could not load widget position for '%s'", _name.c_str()); } - - return; if (_x < 0) error("Widget <%s> has x < 0: %d", _name.c_str(), _x); @@ -96,8 +94,11 @@ NewGui::NewGui() : _redrawStatus(kRedrawDisabled), if (themefile != "builtin" && !themefile.hasSuffix(".zip")) themefile += ".zip"; + + ConfMan.registerDefault("gui_renderer", 2); + ThemeRenderer::GraphicsMode gfxMode = (ThemeRenderer::GraphicsMode)ConfMan.getInt("gui_renderer"); - loadNewTheme(themefile); + loadNewTheme(themefile, gfxMode); _themeChange = false; } @@ -105,8 +106,14 @@ NewGui::~NewGui() { delete _theme; } -bool NewGui::loadNewTheme(const Common::String &filename) { +bool NewGui::loadNewTheme(const Common::String &filename, ThemeRenderer::GraphicsMode gfx) { + if (_theme && filename == _theme->getThemeFileName() && gfx == _theme->getThemeRenderer()) + return true; + Common::String oldTheme = (_theme != 0) ? _theme->getThemeFileName() : ""; + + if (gfx == ThemeRenderer::kGfxDisabled) + gfx = (ThemeRenderer::GraphicsMode)ConfMan.getInt("gui_renderer"); if (_theme) _theme->disable(); @@ -119,7 +126,7 @@ bool NewGui::loadNewTheme(const Common::String &filename) { delete _theme; _theme = 0; - _theme = new ThemeRenderer(filename, GUI::ThemeRenderer::kGfxAntialias16bit); + _theme = new ThemeRenderer(filename, gfx); if (!_theme) return (!oldTheme.empty() ? loadNewTheme(oldTheme) : false); diff --git a/gui/newgui.h b/gui/newgui.h index b7ef589f07..cc9e6b9f3c 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -33,6 +33,8 @@ #include "gui/theme.h" #include "gui/widget.h" +#include "gui/ThemeRenderer.h" + class OSystem; namespace GUI { @@ -76,7 +78,7 @@ public: bool isActive() const { return ! _dialogStack.empty(); } - bool loadNewTheme(const Common::String &file); + bool loadNewTheme(const Common::String &file, ThemeRenderer::GraphicsMode gfx = ThemeRenderer::kGfxDisabled); Theme *theme() { return _theme; } ThemeEval *xmlEval() { return _theme->evaluator(); } diff --git a/gui/options.cpp b/gui/options.cpp index 6377bd6377..05b0f790a2 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -724,9 +724,16 @@ GlobalOptionsDialog::GlobalOptionsDialog() new ButtonWidget(tab, "GlobalOptions_Misc.ThemeButton", "Theme:", kChooseThemeCmd, 0); _curTheme = new StaticTextWidget(tab, "GlobalOptions_Misc.CurTheme", g_gui.theme()->getThemeName()); + int labelWidth = g_gui.xmlEval()->getVar("Globals.TabLabelWidth"); - + + _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); + } + _autosavePeriodPopUp = new PopUpWidget(tab, "GlobalOptions_Misc.AutosavePeriod", "Autosave:", labelWidth); for (int i = 0; savePeriodLabels[i]; i++) { @@ -799,6 +806,8 @@ void GlobalOptionsDialog::open() { if (value == savePeriodValues[i]) _autosavePeriodPopUp->setSelected(i); } + + _rendererPopUp->setSelected(ConfMan.getInt("gui_renderer") - 1); } void GlobalOptionsDialog::close() { @@ -828,6 +837,11 @@ void GlobalOptionsDialog::close() { #endif 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()); + ConfMan.setInt("gui_renderer", _rendererPopUp->getSelectedTag(), _domain); + } } OptionsDialog::close(); } diff --git a/gui/options.h b/gui/options.h index af13663b29..39f2918ce2 100644 --- a/gui/options.h +++ b/gui/options.h @@ -170,7 +170,7 @@ protected: // Misc controls // StaticTextWidget *_curTheme; - + PopUpWidget *_rendererPopUp; PopUpWidget *_autosavePeriodPopUp; }; diff --git a/gui/theme.h b/gui/theme.h index 4c1ab2e195..f4709067ef 100644 --- a/gui/theme.h +++ b/gui/theme.h @@ -310,6 +310,7 @@ public: virtual const Common::String &getThemeFileName() const = 0; virtual const Common::String &getThemeName() const = 0; + virtual int getThemeRenderer() const = 0; /** * Checks if the theme renderer supports drawing of images. diff --git a/gui/themes/default.inc b/gui/themes/default.inc index d87a1f5632..55d1211e24 100644 --- a/gui/themes/default.inc +++ b/gui/themes/default.inc @@ -704,6 +704,9 @@ "height = 'Globals.Line.Height' " "/> " " " +" " " " diff --git a/gui/themes/scummclassic.zip b/gui/themes/scummclassic.zip index 653f789baf..334d2a2274 100644 Binary files a/gui/themes/scummclassic.zip and b/gui/themes/scummclassic.zip differ diff --git a/gui/themes/scummclassic/classic_layout.stx b/gui/themes/scummclassic/classic_layout.stx index bfb09a511b..e404aa37da 100644 --- a/gui/themes/scummclassic/classic_layout.stx +++ b/gui/themes/scummclassic/classic_layout.stx @@ -456,6 +456,9 @@ height = 'Globals.Line.Height' /> + diff --git a/gui/themes/scummodern.zip b/gui/themes/scummodern.zip index 1cd8471709..3c68cc7df3 100644 Binary files a/gui/themes/scummodern.zip and b/gui/themes/scummodern.zip differ diff --git a/gui/themes/scummodern/scummodern_layout.stx b/gui/themes/scummodern/scummodern_layout.stx index 808004ab66..4d7d07c51b 100644 --- a/gui/themes/scummodern/scummodern_layout.stx +++ b/gui/themes/scummodern/scummodern_layout.stx @@ -343,6 +343,9 @@ height = 'Globals.Line.Height' /> + diff --git a/gui/themes/scummodern/scummodern_layout_320.stx b/gui/themes/scummodern/scummodern_layout_320.stx index 07ea81371f..a84fa97cd7 100644 --- a/gui/themes/scummodern/scummodern_layout_320.stx +++ b/gui/themes/scummodern/scummodern_layout_320.stx @@ -325,6 +325,9 @@ height = 'Globals.Line.Height' /> + diff --git a/gui/themes/scummtheme.py b/gui/themes/scummtheme.py index 202372cfea..da0b88cf61 100644 --- a/gui/themes/scummtheme.py +++ b/gui/themes/scummtheme.py @@ -6,7 +6,7 @@ import os import zipfile def buildTheme(themeName): - if not os.path.isdir(themeName): + if not os.path.isdir(themeName) or not os.path.isfile(os.path.join(themeName, "THEMERC")): print "Invalid theme name: " + themeName return -- cgit v1.2.3