aboutsummaryrefslogtreecommitdiff
path: root/gui/theme-config.cpp
diff options
context:
space:
mode:
authorTorbjörn Andersson2006-06-10 10:09:40 +0000
committerTorbjörn Andersson2006-06-10 10:09:40 +0000
commit8ef6ff17653e54c8b799bc89350e8d3342849d13 (patch)
tree22d4d226083a314bdc87937bcb90e95dc782a906 /gui/theme-config.cpp
parentc78409da15bf79a69151f640aef914437402f2e6 (diff)
downloadscummvm-rg350-8ef6ff17653e54c8b799bc89350e8d3342849d13.tar.gz
scummvm-rg350-8ef6ff17653e54c8b799bc89350e8d3342849d13.tar.bz2
scummvm-rg350-8ef6ff17653e54c8b799bc89350e8d3342849d13.zip
This may cut down a little on unnecessary strings / mallocs:
* Only create the self.[xywh] aliases and its variables if prefixedname has no periods in it, e.g. MusicText.x, but not MusicText.align.x * Set the .r, .g and .b variables directly, rather than aliasing them through .x, .y and .w svn-id: r23000
Diffstat (limited to 'gui/theme-config.cpp')
-rw-r--r--gui/theme-config.cpp62
1 files changed, 35 insertions, 27 deletions
diff --git a/gui/theme-config.cpp b/gui/theme-config.cpp
index 5c58aeb56c..fe4b5952a4 100644
--- a/gui/theme-config.cpp
+++ b/gui/theme-config.cpp
@@ -413,30 +413,36 @@ void Theme::processSingleLine(const String &section, const String &prefix, const
uint i;
int value;
const char *selfpostfixes[] = {"self.x", "self.y", "self.w", "self.h"};
- const char *postfixes[] = {".x", ".y", ".w", ".h"};
+ const char *postfixesXYWH[] = {".x", ".y", ".w", ".h"};
+ const char *postfixesRGB[] = {".r", ".g", ".b"};
int npostfix = 0;
const String prefixedname(prefix + name);
- // Make self.BLAH work
- for (i = 0; i < ARRAYSIZE(postfixes); i++) {
- String to(prefixedname);
+ // Make self.BLAH work, but not self.ANYTHING.BLAH
+ if (!strchr(prefixedname.c_str(), '.')) {
+ for (i = 0; i < ARRAYSIZE(postfixesXYWH); i++) {
+ String to(prefixedname);
- to += postfixes[i];
+ to += postfixesXYWH[i];
- _evaluator->setAlias(selfpostfixes[i], to);
- _evaluator->setVar(to, EVAL_UNDEF_VAR);
+ _evaluator->setAlias(selfpostfixes[i], to);
+ _evaluator->setVar(to, EVAL_UNDEF_VAR);
+ }
}
+ // Count the number of parameters, so that we know if they're meant to
+ // be XY[WH] or RGB.
+
+ int ntmppostfix = 0;
+
for (i = 0; i < str.size(); i++) {
if (isspace(str[i]) && level == 0) {
- value = _evaluator->eval(String(&(str.c_str()[start]), i - start), section, name + postfixes[npostfix], start);
- _evaluator->setVar(prefixedname + postfixes[npostfix++], value);
- start = i + 1;
+ ntmppostfix++;
}
+
if (str[i] == '(')
level++;
-
- if (str[i] == ')') {
+ else if (str[i] == ')') {
if (level == 0) {
error("Extra ')' in section: [%s] expression: \"%s\" start is at: %d",
section.c_str(), name.c_str(), start);
@@ -449,6 +455,23 @@ void Theme::processSingleLine(const String &section, const String &prefix, const
error("Missing ')' in section: [%s] expression: \"%s\" start is at: %d",
section.c_str(), name.c_str(), start);
+ const char **postfixes = (ntmppostfix == 2) ? postfixesRGB : postfixesXYWH;
+
+ // Now do it for real, only this time we already know the parantheses
+ // are balanced.
+
+ for (i = 0; i < str.size(); i++) {
+ if (isspace(str[i]) && level == 0) {
+ value = _evaluator->eval(String(&(str.c_str()[start]), i - start), section, name + postfixes[npostfix], start);
+ _evaluator->setVar(prefixedname + postfixes[npostfix++], value);
+ start = i + 1;
+ }
+ if (str[i] == '(')
+ level++;
+ else if (str[i] == ')')
+ level--;
+ }
+
value = _evaluator->eval(String(&(str.c_str()[start]), i - start), section, name + postfixes[npostfix], start);
if (value == EVAL_STRING_VAR)
@@ -466,8 +489,6 @@ void Theme::processSingleLine(const String &section, const String &prefix, const
_evaluator->getVar(prefixedname + ".x") + _evaluator->getVar(prefixedname + ".w"));
_evaluator->setVar(prefixedname + ".y2",
_evaluator->getVar(prefixedname + ".y") + _evaluator->getVar(prefixedname + ".h"));
- } else if (npostfix == 2) { // Specify shortcuts for R G B
- setRGBAlias(prefixedname);
}
if (npostfix != 0)
@@ -544,19 +565,6 @@ void Theme::setSpecialAlias(const String &alias, const String &name) {
}
}
-void Theme::setRGBAlias(const String &name) {
- const char *frompostfixes[] = {".x", ".y", ".w"};
- const char *topostfixes[] = {".r", ".g", ".b"};
- int i;
-
- for (i = 0; i < ARRAYSIZE(frompostfixes); i++) {
- String from(name + frompostfixes[i]);
- String to(name + topostfixes[i]);
-
- _evaluator->setAlias(to.c_str(), from);
- }
-}
-
bool Theme::isThemeLoadingRequired() {
int x = g_system->getOverlayWidth(), y = g_system->getOverlayHeight();