aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorJohannes Schickel2006-10-08 12:00:19 +0000
committerJohannes Schickel2006-10-08 12:00:19 +0000
commit25486c789e1fdfb46e8aeff31252f6590a8d3066 (patch)
tree76111a7150c65b32a7e9ace1dd0338dc74f9dab3 /gui
parent9c88c9d9edde324f7ff1e7792447cb667df78d4e (diff)
downloadscummvm-rg350-25486c789e1fdfb46e8aeff31252f6590a8d3066.tar.gz
scummvm-rg350-25486c789e1fdfb46e8aeff31252f6590a8d3066.tar.bz2
scummvm-rg350-25486c789e1fdfb46e8aeff31252f6590a8d3066.zip
- added auto detection of the Theme style to use
- fixed a bug which would lead to a crash when loading the modern theme config with the classic theme svn-id: r24201
Diffstat (limited to 'gui')
-rw-r--r--gui/ThemeClassic.cpp21
-rw-r--r--gui/ThemeNew.cpp12
-rw-r--r--gui/newgui.cpp24
-rw-r--r--gui/theme.cpp66
-rw-r--r--gui/theme.h5
5 files changed, 111 insertions, 17 deletions
diff --git a/gui/ThemeClassic.cpp b/gui/ThemeClassic.cpp
index 0c06cd396e..31efd12d51 100644
--- a/gui/ThemeClassic.cpp
+++ b/gui/ThemeClassic.cpp
@@ -25,8 +25,8 @@
#define THEME_VERSION 1
namespace GUI {
-ThemeClassic::ThemeClassic(OSystem *system) : Theme() {
- _stylefile = "classic";
+ThemeClassic::ThemeClassic(OSystem *system, const Common::String &config, const Common::ConfigFile *cfg) : Theme() {
+ _stylefile = config;
_system = system;
_initOk = false;
_font = 0;
@@ -37,7 +37,10 @@ ThemeClassic::ThemeClassic(OSystem *system) : Theme() {
#endif
_font = 0;
- loadConfigFile(_stylefile);
+ if (cfg)
+ _configFile = *cfg;
+ else
+ loadConfigFile(_stylefile);
}
ThemeClassic::~ThemeClassic() {
@@ -625,8 +628,8 @@ void ThemeClassic::blendScreenToDialog() {
void ThemeClassic::setupConfig() {
if (_configFile.hasSection("theme")) {
- loadConfig();
- return;
+ if (loadConfig())
+ return;
}
static const uint8 colors[][3] = {
@@ -646,6 +649,10 @@ bool ThemeClassic::loadConfig() {
if (atoi(temp.c_str()) != THEME_VERSION) {
// TODO: improve this detection and handle it nicer
warning("Theme config uses a different version (you have: '%s', needed is: '%d')", temp.c_str(), THEME_VERSION);
+ _configFile.clear();
+
+ // force a theme reload here
+ loadTheme(_defaultConfig);
return false;
}
@@ -653,6 +660,10 @@ bool ThemeClassic::loadConfig() {
_configFile.getKey("type", "theme", temp);
if (0 != temp.compareToIgnoreCase("classic")) {
warning("Theme config is not for the classic style theme");
+ _configFile.clear();
+
+ // force a theme reload here
+ loadTheme(_defaultConfig);
return false;
}
diff --git a/gui/ThemeNew.cpp b/gui/ThemeNew.cpp
index 00ddc2e7e0..fc8aadcd51 100644
--- a/gui/ThemeNew.cpp
+++ b/gui/ThemeNew.cpp
@@ -55,7 +55,7 @@ OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos, int max
#pragma mark -
-ThemeNew::ThemeNew(OSystem *system, const Common::String &stylefile) : Theme(), _system(system), _screen(), _initOk(false),
+ThemeNew::ThemeNew(OSystem *system, const Common::String &stylefile, const Common::ConfigFile *cfg) : Theme(), _system(system), _screen(), _initOk(false),
_lastUsedBitMask(0), _forceRedraw(false), _imageHandles(0), _images(0), _colors(), _fonts(), _cursor(0), _gradientFactors() {
_stylefile = stylefile;
_initOk = false;
@@ -71,9 +71,13 @@ _lastUsedBitMask(0), _forceRedraw(false), _imageHandles(0), _images(0), _colors(
clearAll();
}
- if (!loadConfigFile(stylefile)) {
- warning("Can not find theme config file '%s'", (stylefile + ".ini").c_str());
- return;
+ if (cfg) {
+ _configFile = *cfg;
+ } else {
+ if (!loadConfigFile(stylefile)) {
+ warning("Can not find theme config file '%s'", (stylefile + ".ini").c_str());
+ return;
+ }
}
ImageMan.addArchive(stylefile + ".zip");
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index 9c1015b0c5..94924f1e84 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -85,6 +85,7 @@ void GuiObject::reflowLayout() {
// Constructor
NewGui::NewGui() : _needRedraw(false),
_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
+ _theme = 0;
_system = g_system;
_lastScreenChangeID = _system->getScreenChangeID();
@@ -99,17 +100,28 @@ NewGui::NewGui() : _needRedraw(false),
ConfMan.registerDefault("gui_theme", "default");
Common::String style(ConfMan.get("gui_theme"));
// The default theme for now is the 'modern' theme.
- if (scumm_stricmp(style.c_str(), "default") == 0)
+ if (style.compareToIgnoreCase("default") == 0)
style = "modern";
- if (scumm_stricmp(style.c_str(), "classic") == 0) {
-#endif
- _theme = new ThemeClassic(_system);
-#ifndef DISABLE_FANCY_THEMES
+ Common::String styleType;
+ Common::ConfigFile cfg;
+
+ if (Theme::themeConfigUseable(style, "", &styleType, &cfg)) {
+ if (0 == styleType.compareToIgnoreCase("classic"))
+ _theme = new ThemeClassic(_system, style, &cfg);
+ else if (0 == styleType.compareToIgnoreCase("modern"))
+ _theme = new ThemeNew(_system, style, &cfg);
+ else
+ warning("Unsupported theme type '%s'", styleType.c_str());
} else {
- _theme = new ThemeNew(_system, style.c_str());
+ warning("Config '%s' is NOT usable for themes or not found", style.c_str());
}
+ cfg.clear();
#endif
+
+ if (!_theme)
+ _theme = new ThemeClassic(_system);
+
assert(_theme);
// Init the theme
diff --git a/gui/theme.cpp b/gui/theme.cpp
index c0c4d32e05..4e9e295763 100644
--- a/gui/theme.cpp
+++ b/gui/theme.cpp
@@ -187,4 +187,70 @@ bool Theme::loadConfigFile(const String &stylefile) {
return true;
}
+bool Theme::themeConfigUseable(const String &stylefile, const String &style, String *cStyle, Common::ConfigFile *cfg) {
+ 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"));
+
+ Common::File file;
+ Common::ConfigFile configFile;
+ if (!cfg && (cStyle || !style.empty()))
+ cfg = &configFile;
+
+ if (!file.open(stylefile + ".ini")) {
+#ifdef USE_ZLIB
+ // Maybe find a nicer solution to this
+ unzFile zipFile = unzOpen((stylefile + ".zip").c_str());
+ if (zipFile && unzLocateFile(zipFile, (stylefile + ".ini").c_str(), 2) == UNZ_OK) {
+ if (!style.empty() || cStyle || cfg) {
+ unz_file_info fileInfo;
+ unzOpenCurrentFile(zipFile);
+ unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
+ uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
+ assert(buffer);
+ memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
+ unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
+ unzCloseCurrentFile(zipFile);
+ Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
+ if (!cfg->loadFromStream(stream)) {
+ unzClose(zipFile);
+ return false;
+ }
+ delete [] buffer;
+ buffer = 0;
+ }
+ } else {
+ unzClose(zipFile);
+ return false;
+ }
+ unzClose(zipFile);
+#else
+ return false;
+#endif
+ }
+
+ if (!style.empty() || cStyle || cfg) {
+ if (file.isOpen()) {
+ if (!cfg->loadFromStream(file))
+ return false;
+ file.close();
+ }
+
+ Common::String temp;
+ cfg->getKey("type", "theme", temp);
+ if (cStyle)
+ *cStyle = temp;
+ if (0 != temp.compareToIgnoreCase(style) && !style.empty())
+ return false;
+ }
+
+ return true;
+}
+
} // End of namespace GUI
diff --git a/gui/theme.h b/gui/theme.h
index 72253e5285..4cf3358e30 100644
--- a/gui/theme.h
+++ b/gui/theme.h
@@ -212,6 +212,7 @@ public:
Eval *_evaluator;
+ static bool themeConfigUseable(const String &file, const String &style="", String *cStyle=0, Common::ConfigFile *cfg=0);
protected:
bool loadConfigFile(const String &file);
void getColorFromConfig(const String &name, OverlayColor &col);
@@ -236,7 +237,7 @@ private:
class ThemeClassic : public Theme {
public:
- ThemeClassic(OSystem *system);
+ ThemeClassic(OSystem *system, const Common::String &config = "classic", const Common::ConfigFile *cfg = 0);
virtual ~ThemeClassic();
bool init();
@@ -329,7 +330,7 @@ private:
class ThemeNew : public Theme {
typedef Common::String String;
public:
- ThemeNew(OSystem *system, const String &stylefile);
+ ThemeNew(OSystem *system, const String &stylefile, const Common::ConfigFile *cfg = 0);
virtual ~ThemeNew();
bool init();