From 5d6733991a1094a77185e91de81410f4fc8a7f81 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Thu, 6 Mar 2014 21:35:13 -0600 Subject: [PATCH] Removed the overly-complicated "common" view. Replaced it with the ability to specify multiple views in a theme tag, just like for elements. --- THEMES.md | 20 ++++++++------------ src/ThemeData.cpp | 33 ++++++++++++++++----------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/THEMES.md b/THEMES.md index d3234b55d..d4526107d 100644 --- a/THEMES.md +++ b/THEMES.md @@ -81,7 +81,7 @@ It is recommended that if you are writing a theme you launch EmulationStation wi ### The `` tag -You can include theme files within theme files, similar to `#include` in C (though the mechanism is different, the effect is the same). Example: +You can include theme files within theme files, similar to `#include` in C (though the internal mechanism is different, the effect is the same). Example: `~/.emulationstation/all_themes.xml`: ```xml @@ -126,14 +126,14 @@ Notice that properties that were not specified got merged (``) and the -### The "common" view +### Theming multiple views simultaneously -Sometimes you want to apply the same values to the same element across many views. The "common" view is one way to do this. +Sometimes you want to apply the same properties to the same elements across multiple views. The `name` attribute actually works as a list (delimited by any characters of `\t\r\n ,` - that is, whitespace and commas). So, for example, to easily apply the same header to the basic, grid, and system views: ```xml 3 - + ./snes_art/snes_header.png @@ -146,7 +146,7 @@ Sometimes you want to apply the same values to the same element across many view ``` -Is equivalent to: +This is equivalent to: ```xml 3 @@ -174,15 +174,11 @@ Is equivalent to: ``` -Notice that you can still override the "common" view in a specific view definition (as shown in the "detailed" view). - -You probably should not use the "common" view for element positioning. You also should not use it to create "extra" elements. +### Theming multiple elements simultaneously -### Theming more than one elements at once - -You can theme multiple elements *of the same type* simultaneously. The `name` attribute actually works as a list (delimited by any characters of `\t\n ,` - that is, whitespace and commas). This is useful if you want to, say, apply the same color to all the metadata labels: +You can theme multiple elements *of the same type* simultaneously. The `name` attribute actually works as a list (delimited by any characters of `\t\r\n ,` - that is, whitespace and commas), just like it does for views, as long as the elements have the same type. This is useful if you want to, say, apply the same color to all the metadata labels: ```xml @@ -197,7 +193,7 @@ You can theme multiple elements *of the same type* simultaneously. The `name` a ``` -Is equivalent to: +Which is equivalent to: ```xml 3 diff --git a/src/ThemeData.cpp b/src/ThemeData.cpp index 02c6531ef..c958d7bd1 100644 --- a/src/ThemeData.cpp +++ b/src/ThemeData.cpp @@ -201,22 +201,26 @@ void ThemeData::parseViews(const pugi::xml_node& root) ThemeException error; error.setFiles(mPaths); - pugi::xml_node common = root.find_child_by_attribute("view", "name", "common"); - // parse views for(pugi::xml_node node = root.child("view"); node; node = node.next_sibling("view")) { if(!node.attribute("name")) throw error << "View missing \"name\" attribute!"; - const char* viewKey = node.attribute("name").as_string(); - ThemeView& view = mViews.insert(std::pair(viewKey, ThemeView())).first->second; - - // load common first - if(common && node != common) - parseView(common, view); - - parseView(node, view); + const char* delim = " \t\r\n,"; + const std::string nameAttr = node.attribute("name").as_string(); + size_t prevOff = nameAttr.find_first_not_of(delim, 0); + size_t off = nameAttr.find_first_of(delim, prevOff); + std::string viewKey; + while(off != std::string::npos || prevOff != std::string::npos) + { + viewKey = nameAttr.substr(prevOff, off - prevOff); + prevOff = nameAttr.find_first_not_of(delim, off); + off = nameAttr.find_first_of(delim, prevOff); + + ThemeView& view = mViews.insert(std::pair(viewKey, ThemeView())).first->second; + parseView(node, view); + } } } @@ -234,7 +238,7 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view) if(elemTypeIt == sElementMap.end()) throw error << "Unknown element of type \"" << node.name() << "\"!"; - const char* delim = " \t\n,"; + const char* delim = " \t\r\n,"; const std::string nameAttr = node.attribute("name").as_string(); size_t prevOff = nameAttr.find_first_not_of(delim, 0); size_t off = nameAttr.find_first_of(delim, prevOff); @@ -324,12 +328,7 @@ const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view, co { auto viewIt = mViews.find(view); if(viewIt == mViews.end()) - { - // also check common if the view never existed to begin with - viewIt = mViews.find("common"); - if(viewIt == mViews.end()) - return NULL; - } + return NULL; // not found auto elemIt = viewIt->second.elements.find(element); if(elemIt == viewIt->second.elements.end()) return NULL;