Themes now load from system directories.

~ and . are now expanded in theme image paths.
Theme percentages should now work properly.
See changelog (August 10) for more.
This commit is contained in:
Aloshi 2012-08-10 23:17:52 -05:00
parent 2bd9c51447
commit 878b384b02
8 changed files with 78 additions and 23 deletions

View file

@ -1,3 +1,10 @@
August 10
-Themes now load from system directories (and thus you can set a different theme for each system)
-Theme paths now expand . (to directory of this theme.xml) and ~ (to $HOME).
-Added --ignore-gamelist switch. Does as it says, and forces the simple GuiGameList.
-Folders that do not contain games will not be added.
-Fixed float percentages in GuiTheme being converted to integers before they were converted to pixels...woops!
August 9 August 9
-Removed multithreaded image loading -Removed multithreaded image loading
-Improved GuiImage rendering speed by adding additional processing at load time (SDL_DisplayFormat) -Improved GuiImage rendering speed by adding additional processing at load time (SDL_DisplayFormat)

View file

@ -39,6 +39,11 @@ void GuiComponent::removeChild(GuiComponent* comp)
std::cerr << "Error - tried to remove GuiComponent child, but couldn't find it!\n"; std::cerr << "Error - tried to remove GuiComponent child, but couldn't find it!\n";
} }
void GuiComponent::clearChildren()
{
mChildren.clear();
}
void GuiComponent::processTicks(int deltaTime) void GuiComponent::processTicks(int deltaTime)
{ {
for(unsigned int i = 0; i < sComponentVector.size(); i++) for(unsigned int i = 0; i < sComponentVector.size(); i++)
@ -72,3 +77,4 @@ void GuiComponent::resume()
for(unsigned int i = 0; i < mChildren.size(); i++) for(unsigned int i = 0; i < mChildren.size(); i++)
mChildren.at(i)->resume(); mChildren.at(i)->resume();
} }

View file

@ -24,6 +24,7 @@ public:
void addChild(GuiComponent* comp); void addChild(GuiComponent* comp);
void removeChild(GuiComponent* comp); void removeChild(GuiComponent* comp);
void clearChildren();
unsigned int getChildCount() { return mChildren.size(); } unsigned int getChildCount() { return mChildren.size(); }
GuiComponent* getChild(unsigned int i) { return mChildren.at(i); } GuiComponent* getChild(unsigned int i) { return mChildren.at(i); }

View file

@ -11,6 +11,7 @@ std::vector<SystemData*> SystemData::sSystemVector;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
extern bool PARSEGAMELISTONLY; extern bool PARSEGAMELISTONLY;
extern bool IGNOREGAMELIST;
std::string SystemData::getStartPath() { return mStartPath; } std::string SystemData::getStartPath() { return mStartPath; }
std::string SystemData::getExtension() { return mSearchExtension; } std::string SystemData::getExtension() { return mSearchExtension; }
@ -44,6 +45,7 @@ SystemData::SystemData(std::string name, std::string startPath, std::string exte
if(!PARSEGAMELISTONLY) if(!PARSEGAMELISTONLY)
populateFolder(mRootFolder); populateFolder(mRootFolder);
if(!IGNOREGAMELIST)
parseGamelist(this); parseGamelist(this);
mRootFolder->sort(); mRootFolder->sort();
@ -103,6 +105,11 @@ void SystemData::populateFolder(FolderData* folder)
{ {
FolderData* newFolder = new FolderData(this, filePath.string(), filePath.stem().string()); FolderData* newFolder = new FolderData(this, filePath.string(), filePath.stem().string());
populateFolder(newFolder); populateFolder(newFolder);
//ignore folders that do not contain games
if(newFolder->getFileCount() == 0)
delete newFolder;
else
folder->pushFileData(newFolder); folder->pushFileData(newFolder);
}else{ }else{
if(filePath.extension().string() == mSearchExtension) if(filePath.extension().string() == mSearchExtension)

View file

@ -4,7 +4,7 @@
#include "GuiMenu.h" #include "GuiMenu.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
//#define DRAWFRAMERATE #define DRAWFRAMERATE
#ifdef DRAWFRAMERATE #ifdef DRAWFRAMERATE
#include <sstream> #include <sstream>
@ -24,8 +24,8 @@ GuiGameList::GuiGameList(bool useDetail)
mList = new GuiList<FileData*>(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2); mList = new GuiList<FileData*>(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2);
mTheme = new GuiTheme(); mTheme = new GuiTheme();
//addChild(mTheme); //addChild(mTheme); //currently manually rendered before everything else in GuiGameList::onRender
updateTheme(); //updateTheme();
mScreenshot = new GuiImage(Renderer::getScreenWidth() * 0.2, Renderer::getFontHeight(Renderer::LARGE) + 2, "", Renderer::getScreenWidth() * 0.3); mScreenshot = new GuiImage(Renderer::getScreenWidth() * 0.2, Renderer::getFontHeight(Renderer::LARGE) + 2, "", Renderer::getScreenWidth() * 0.3);
addChild(mScreenshot); addChild(mScreenshot);
@ -79,16 +79,16 @@ void GuiGameList::setSystemId(int id)
mFolder = mSystem->getRootFolder(); mFolder = mSystem->getRootFolder();
updateTheme();
updateList(); updateList();
} }
void GuiGameList::onRender() void GuiGameList::onRender()
{ {
if(mTheme)
mTheme->render();
else
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF); Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF);
if(mTheme)
mTheme->render();
#ifdef DRAWFRAMERATE #ifdef DRAWFRAMERATE
std::stringstream ss; std::stringstream ss;
@ -192,13 +192,15 @@ void GuiGameList::updateList()
void GuiGameList::updateTheme() void GuiGameList::updateTheme()
{ {
std::string themePath = getenv("HOME"); if(!mTheme)
themePath += "/.emulationstation/theme.xml"; return;
std::string themePath = mSystem->getStartPath() + "/theme.xml";
if(boost::filesystem::exists(themePath)) if(boost::filesystem::exists(themePath))
{
mTheme->readXML(themePath); mTheme->readXML(themePath);
} else
mTheme->readXML(""); //clears any current theme
} }
//these are called when the menu opens/closes //these are called when the menu opens/closes

View file

@ -2,6 +2,7 @@
#include "../MathExp.h" #include "../MathExp.h"
#include <iostream> #include <iostream>
#include "GuiImage.h" #include "GuiImage.h"
#include <boost/filesystem.hpp>
GuiTheme::GuiTheme(std::string path) GuiTheme::GuiTheme(std::string path)
{ {
@ -22,6 +23,8 @@ void GuiTheme::deleteComponents()
} }
mComponentVector.clear(); mComponentVector.clear();
clearChildren();
} }
@ -30,6 +33,11 @@ void GuiTheme::readXML(std::string path)
{ {
deleteComponents(); deleteComponents();
mPath = path;
if(path.empty())
return;
std::cout << "Loading theme \"" << path << "\"...\n"; std::cout << "Loading theme \"" << path << "\"...\n";
pugi::xml_document doc; pugi::xml_document doc;
@ -58,7 +66,14 @@ GuiComponent* GuiTheme::createElement(pugi::xml_node data, GuiComponent* parent)
if(type == "image") if(type == "image")
{ {
std::string path = data.child("path").text().get(); std::string path = expandPath(data.child("path").text().get());
if(!boost::filesystem::exists(path))
{
std::cerr << "Error - theme image \"" << path << "\" does not exist.\n";
return NULL;
}
std::string pos = data.child("pos").text().get(); std::string pos = data.child("pos").text().get();
std::string dim = data.child("dim").text().get(); std::string dim = data.child("dim").text().get();
@ -79,7 +94,7 @@ GuiComponent* GuiTheme::createElement(pugi::xml_node data, GuiComponent* parent)
int w = resolveExp(dimW) * Renderer::getScreenWidth(); int w = resolveExp(dimW) * Renderer::getScreenWidth();
int h = resolveExp(dimH) * Renderer::getScreenHeight(); int h = resolveExp(dimH) * Renderer::getScreenHeight();
std::cout << "w: " << w << " h: " << h << "\n"; std::cout << "w: " << w << "px, h: " << h << "px\n";
GuiComponent* comp = new GuiImage(x, y, path, w, h, true); GuiComponent* comp = new GuiImage(x, y, path, w, h, true);
parent->addChild(comp); parent->addChild(comp);
@ -92,7 +107,17 @@ GuiComponent* GuiTheme::createElement(pugi::xml_node data, GuiComponent* parent)
return NULL; return NULL;
} }
int GuiTheme::resolveExp(std::string str) std::string GuiTheme::expandPath(std::string path)
{
if(path[0] == '~')
path = getenv("HOME") + path.substr(1, path.length() - 1);
else if(path[0] == '.')
path = boost::filesystem::path(mPath).parent_path().string() + path.substr(1, path.length() - 1);
return path;
}
float GuiTheme::resolveExp(std::string str)
{ {
MathExp exp; MathExp exp;
exp.setExpression(str); exp.setExpression(str);
@ -100,5 +125,5 @@ int GuiTheme::resolveExp(std::string str)
//set variables //set variables
exp.setVariable("headerHeight", Renderer::getFontHeight(Renderer::LARGE) / Renderer::getScreenHeight()); exp.setVariable("headerHeight", Renderer::getFontHeight(Renderer::LARGE) / Renderer::getScreenHeight());
return (int)exp.eval(); return exp.eval();
} }

View file

@ -14,11 +14,12 @@ public:
private: private:
void deleteComponents(); void deleteComponents();
GuiComponent* createElement(pugi::xml_node data, GuiComponent* parent); GuiComponent* createElement(pugi::xml_node data, GuiComponent* parent);
int resolveExp(std::string str); std::string expandPath(std::string path);
float resolveExp(std::string str);
std::vector<GuiComponent*> mComponentVector; std::vector<GuiComponent*> mComponentVector;
std::string mPath;
}; };
#endif #endif

View file

@ -8,6 +8,7 @@
#include "components/GuiInputConfig.h" #include "components/GuiInputConfig.h"
bool PARSEGAMELISTONLY = false; bool PARSEGAMELISTONLY = false;
bool IGNOREGAMELIST = false;
float FRAMERATE = 0; float FRAMERATE = 0;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
@ -46,6 +47,9 @@ int main(int argc, char* argv[])
}else if(strcmp(argv[i], "--gamelist-only") == 0) }else if(strcmp(argv[i], "--gamelist-only") == 0)
{ {
PARSEGAMELISTONLY = true; PARSEGAMELISTONLY = true;
}else if(strcmp(argv[i], "--ignore-gamelist") == 0)
{
IGNOREGAMELIST = true;
} }
} }
} }
@ -113,6 +117,8 @@ int main(int argc, char* argv[])
bool useDetail = false; bool useDetail = false;
//see if any systems had gamelists present, if so we'll use the detailed GuiGameList //see if any systems had gamelists present, if so we'll use the detailed GuiGameList
if(!IGNOREGAMELIST)
{
for(unsigned int i = 0; i < SystemData::sSystemVector.size(); i++) for(unsigned int i = 0; i < SystemData::sSystemVector.size(); i++)
{ {
if(SystemData::sSystemVector.at(i)->hasGamelist()) if(SystemData::sSystemVector.at(i)->hasGamelist())
@ -121,7 +127,7 @@ int main(int argc, char* argv[])
break; break;
} }
} }
}
//choose which Gui to open up //choose which Gui to open up
if(boost::filesystem::exists(InputManager::getConfigPath())) if(boost::filesystem::exists(InputManager::getConfigPath()))