aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/ListWidget.cpp2
-rw-r--r--gui/ThemeEval.h2
-rw-r--r--gui/ThemeRenderer.cpp89
-rw-r--r--gui/ThemeRenderer.h25
-rw-r--r--gui/newgui.cpp11
-rw-r--r--gui/options.cpp2
-rw-r--r--gui/theme.h8
-rw-r--r--gui/themebrowser.cpp35
-rw-r--r--gui/themebrowser.h1
9 files changed, 90 insertions, 85 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 4f829fd323..d6649fc7f2 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -510,6 +510,8 @@ void ListWidget::reflowLayout() {
_entriesPerPage += (1 << 16);
_entriesPerPage >>= 16;
+
+ assert(_entriesPerPage > 0);
delete[] _textWidth;
_textWidth = new int[_entriesPerPage];
diff --git a/gui/ThemeEval.h b/gui/ThemeEval.h
index aaab4cb2bf..eecd2db3ee 100644
--- a/gui/ThemeEval.h
+++ b/gui/ThemeEval.h
@@ -377,7 +377,7 @@ public:
}
void debugDraw(Graphics::Surface *screen, const Graphics::Font *font) {
- _layouts["Dialog.Launcher"]->debugDraw(screen, font);
+ _layouts["Dialog.Browser"]->debugDraw(screen, font);
// _layouts["Dialog.GameOptions_Graphics"]->debugDraw(screen, font);
}
diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp
index 6cfdb777ad..378e32649f 100644
--- a/gui/ThemeRenderer.cpp
+++ b/gui/ThemeRenderer.cpp
@@ -95,7 +95,7 @@ const ThemeRenderer::TextDataInfo ThemeRenderer::kTextDataDefaults[] = {
};
-ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
+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) {
@@ -119,11 +119,9 @@ ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
} else {
_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
}
-
- ImageMan.addArchive(themeName + ".zip");
+ _themeFileName = fileName;
_initOk = true;
- _themeName = themeName;
}
ThemeRenderer::~ThemeRenderer() {
@@ -134,12 +132,8 @@ ThemeRenderer::~ThemeRenderer() {
delete _parser;
delete _themeEval;
- for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) {
-// delete i->_value;
+ for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i)
ImageMan.unregisterSurface(i->_key);
- }
-
- ImageMan.remArchive(_stylefile + ".zip");
}
bool ThemeRenderer::init() {
@@ -154,7 +148,7 @@ bool ThemeRenderer::init() {
}
if (isThemeLoadingRequired() || !_themeOk) {
- loadTheme(_themeName);
+ loadTheme(_themeFileName);
}
return true;
@@ -170,6 +164,30 @@ void ThemeRenderer::deinit() {
}
}
+void ThemeRenderer::unloadTheme() {
+ if (!_themeOk)
+ return;
+
+ for (int i = 0; i < kDrawDataMAX; ++i) {
+ delete _widgets[i];
+ _widgets[i] = 0;
+ }
+
+ for (int i = 0; i < kTextDataMAX; ++i) {
+ delete _texts[i];
+ _texts[i] = 0;
+ }
+
+ for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i)
+ ImageMan.unregisterSurface(i->_key);
+
+ ImageMan.remArchive(_themeFileName + ".zip");
+
+ _themeName.clear();
+ _themeFileName.clear();
+ _themeOk = false;
+}
+
void ThemeRenderer::clearAll() {
if (!_initOk)
return;
@@ -281,7 +299,6 @@ bool ThemeRenderer::addFont(const Common::String &fontId, const Common::String &
bool ThemeRenderer::addBitmap(const Common::String &filename) {
if (_bitmaps.contains(filename)) {
- delete _bitmaps[filename];
ImageMan.unregisterSurface(filename);
}
@@ -309,14 +326,28 @@ bool ThemeRenderer::addDrawData(const Common::String &data, bool cached) {
return true;
}
-bool ThemeRenderer::loadTheme(Common::String themeName) {
+bool ThemeRenderer::loadTheme(Common::String fileName) {
unloadTheme();
- if (themeName == "builtin" && !loadDefaultXML())
- error("Could not load default embeded theme.");
+ if (fileName != "builtin") {
+ if (ConfMan.hasKey("themepath"))
+ Common::File::addDefaultDirectory(ConfMan.get("themepath"));
- if (!loadThemeXML(themeName)) {
- warning("Could not parse custom theme '%s'.\nFalling back to default theme", themeName.c_str());
+#ifdef DATA_PATH
+ Common::File::addDefaultDirectoryRecursive(DATA_PATH);
+#endif
+ if (ConfMan.hasKey("extrapath"))
+ Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
+
+ ImageMan.addArchive(fileName + ".zip");
+ }
+
+ if (fileName == "builtin") {
+ if (!loadDefaultXML())
+ error("Could not load default embeded theme");
+ }
+ else if (!loadThemeXML(fileName)) {
+ warning("Could not parse custom theme '%s'.\nFalling back to default theme", fileName.c_str());
if (!loadDefaultXML()) // if we can't load the embeded theme, this is a complete failure
error("Could not load default embeded theme");
@@ -333,9 +364,7 @@ bool ThemeRenderer::loadTheme(Common::String themeName) {
}
}
- // Debug print all the parsed variables. remove
- _themeEval->debugPrint();
-
+ _themeName = "DEBUG - A Theme name";
_themeOk = true;
return true;
}
@@ -346,6 +375,8 @@ bool ThemeRenderer::loadDefaultXML() {
// file inside the themes directory.
// Use the Python script "makedeftheme.py" to convert a normal XML theme
// into the "default.inc" file, which is ready to be included in the code.
+
+#ifdef GUI_ENABLE_BUILTIN_THEME
const char *defaultXML =
#include "themes/default.inc"
;
@@ -354,20 +385,14 @@ bool ThemeRenderer::loadDefaultXML() {
return false;
return parser()->parse();
+#else
+ warning("The built-in theme is not enabled in the current build. Please load an external theme");
+ return false;
+#endif
}
bool ThemeRenderer::loadThemeXML(Common::String themeName) {
assert(_parser);
-
- if (ConfMan.hasKey("themepath"))
- Common::File::addDefaultDirectory(ConfMan.get("themepath"));
-
-#ifdef DATA_PATH
- Common::File::addDefaultDirectoryRecursive(DATA_PATH);
-#endif
-
- if (ConfMan.hasKey("extrapath"))
- Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
if (!parser()->loadFile(themeName + ".stx")){
#ifdef USE_ZLIB
@@ -821,9 +846,9 @@ void ThemeRenderer::updateScreen() {
renderDirtyScreen();
-// _vectorRenderer->fillSurface();
-// themeEval()->debugDraw(_screen, _font);
-// _vectorRenderer->copyWholeFrame(_system);
+ // _vectorRenderer->fillSurface();
+ // themeEval()->debugDraw(_screen, _font);
+ // _vectorRenderer->copyWholeFrame(_system);
}
void ThemeRenderer::renderDirtyScreen() {
diff --git a/gui/ThemeRenderer.h b/gui/ThemeRenderer.h
index cb68b9ca5c..3c7d07b419 100644
--- a/gui/ThemeRenderer.h
+++ b/gui/ThemeRenderer.h
@@ -216,7 +216,7 @@ public:
};
/** Default constructor */
- ThemeRenderer(Common::String themeName, GraphicsMode mode);
+ ThemeRenderer(Common::String fileName, GraphicsMode mode);
/** Default destructor */
~ThemeRenderer();
@@ -470,10 +470,11 @@ public:
return 0;
}
-
- const Common::String &getThemeName() { return _themeName; }
protected:
+
+ const Common::String &getThemeName() const { return _themeName; }
+ const Common::String &getThemeFileName() const { return _themeFileName; }
/**
* Initializes the drawing screen surfaces, _screen and _backBuffer.
@@ -505,22 +506,7 @@ protected:
* Unloads the currently loaded theme so another one can
* be loaded.
*/
- void unloadTheme() {
- if (!_themeOk)
- return;
-
- for (int i = 0; i < kDrawDataMAX; ++i) {
- delete _widgets[i];
- _widgets[i] = 0;
- }
-
- for (int i = 0; i < kTextDataMAX; ++i) {
- delete _texts[i];
- _texts[i] = 0;
- }
-
- _themeOk = false;
- }
+ void unloadTheme();
/**
* Not implemented yet.
@@ -710,6 +696,7 @@ protected:
bool _enabled; /** Whether the Theme is currently shown on the overlay */
Common::String _themeName; /** Name of the currently loaded theme */
+ Common::String _themeFileName;
};
} // end of namespace GUI.
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index e83c86a451..f2e013bc0a 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -98,7 +98,7 @@ NewGui::NewGui() : _redrawStatus(kRedrawDisabled),
style = "builtin";
//DEBUG:
- style = "scummodern";
+// style = "scummodern";
loadNewTheme(style);
@@ -110,11 +110,8 @@ NewGui::~NewGui() {
delete _theme;
}
-bool NewGui::loadNewTheme(const Common::String &style) {
- Common::String styleType;
- Common::ConfigFile cfg;
-
- Common::String oldTheme = (_theme != 0) ? _theme->getThemeName() : "";
+bool NewGui::loadNewTheme(const Common::String &filename) {
+ Common::String oldTheme = (_theme != 0) ? _theme->getThemeFileName() : "";
if (_theme)
_theme->disable();
@@ -127,7 +124,7 @@ bool NewGui::loadNewTheme(const Common::String &style) {
delete _theme;
_theme = 0;
- _theme = new ThemeRenderer(style, GUI::ThemeRenderer::kGfxAntialias16bit);
+ _theme = new ThemeRenderer(filename, GUI::ThemeRenderer::kGfxAntialias16bit);
if (!_theme)
return (!oldTheme.empty() ? loadNewTheme(oldTheme) : false);
diff --git a/gui/options.cpp b/gui/options.cpp
index 12153469ef..96a8619cf7 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -907,7 +907,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
if (browser.runModal() > 0) {
// User made his choice...
const Common::String &theme = browser.selected();
- if (0 != theme.compareToIgnoreCase(g_gui.theme()->getStylefileName()))
+ if (0 != theme.compareToIgnoreCase(g_gui.theme()->getThemeFileName()))
if (g_gui.loadNewTheme(theme)) {
_curTheme->setLabel(g_gui.theme()->getThemeName());
ConfMan.set("gui_theme", theme);
diff --git a/gui/theme.h b/gui/theme.h
index 74158f473c..2a0b908330 100644
--- a/gui/theme.h
+++ b/gui/theme.h
@@ -370,12 +370,8 @@ public:
static bool themeConfigUseable(const Common::String &file, const Common::String &style="", Common::String *cStyle=0, Common::ConfigFile *cfg=0);
- const Common::String &getStylefileName() const { return _stylefile; }
- virtual const Common::String &getThemeName() const { return _stylename; }
-
- virtual bool isDynamic() {
- return false;
- }
+ virtual const Common::String &getThemeFileName() const = 0;
+ virtual const Common::String &getThemeName() const = 0;
/**
* Checks if the theme renderer supports drawing of images.
diff --git a/gui/themebrowser.cpp b/gui/themebrowser.cpp
index 98e6df8565..97184fda91 100644
--- a/gui/themebrowser.cpp
+++ b/gui/themebrowser.cpp
@@ -43,21 +43,21 @@ enum {
// but for now this simple browser works,
// also it will get its own theme config values
// and not use 'browser_' anymore
-ThemeBrowser::ThemeBrowser() : Dialog("browser") {
+ThemeBrowser::ThemeBrowser() : Dialog("Browser") {
_fileList = 0;
- new StaticTextWidget(this, "browser_headline", "Select a Theme");
+ new StaticTextWidget(this, "Browser.Headline", "Select a Theme");
// Add file list
- _fileList = new ListWidget(this, "browser_list");
+ _fileList = new ListWidget(this, "Browser.List");
_fileList->setNumberingMode(kListNumberingOff);
_fileList->setEditable(false);
_fileList->setHints(THEME_HINT_PLAIN_COLOR);
// Buttons
- new ButtonWidget(this, "browser_cancel", "Cancel", kCloseCmd, 0);
- new ButtonWidget(this, "browser_choose", "Choose", kChooseCmd, 0);
+ new ButtonWidget(this, "Browser.Cancel", "Cancel", kCloseCmd, 0);
+ new ButtonWidget(this, "Browser.Choose", "Choose", kChooseCmd, 0);
}
void ThemeBrowser::open() {
@@ -91,9 +91,8 @@ void ThemeBrowser::updateListing() {
// classic is always build in
Entry th;
- th.name = "Classic (Builtin)";
- th.type = "Classic";
- th.file = "Classic (Builtin)";
+ th.name = "Modern Development Theme (Builtin) - WIP";
+ th.file = "builtin";
_themes.push_back(th);
// we are using only the paths 'themepath', 'extrapath', DATA_PATH and '.'
@@ -172,10 +171,11 @@ void ThemeBrowser::addDir(ThList &list, const Common::String &dir, int level) {
}
bool ThemeBrowser::isTheme(const FilesystemNode &node, Entry &out) {
- Common::ConfigFile cfg;
- Common::String type;
-
out.file = node.getName();
+
+ if (!out.file.hasSuffix(".zip") && !out.file.hasSuffix(".stx"))
+ return false;
+
for (int i = out.file.size()-1; out.file[i] != '.' && i > 0; --i) {
out.file.deleteLastChar();
}
@@ -184,14 +184,13 @@ bool ThemeBrowser::isTheme(const FilesystemNode &node, Entry &out) {
if (out.file.empty())
return false;
- if (!Theme::themeConfigUseable(out.file, "", &type, &cfg))
- return false;
-
- out.type = type;
+// TODO: Check if theme is usable.
+// if (!Theme::themeConfigUseable(out.file, "", &type, &cfg))
+// return false;
- if (cfg.hasKey("name", "theme"))
- cfg.getKey("name", "theme", out.name);
- else
+// if (cfg.hasKey("name", "theme"))
+// cfg.getKey("name", "theme", out.name);
+// else
out.name = out.file;
return true;
diff --git a/gui/themebrowser.h b/gui/themebrowser.h
index 9351648d24..7a3bc2ca7d 100644
--- a/gui/themebrowser.h
+++ b/gui/themebrowser.h
@@ -46,7 +46,6 @@ public:
private:
struct Entry {
Common::String name;
- Common::String type;
Common::String file;
};