2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// ThemeData.h
|
|
|
|
//
|
2020-06-22 15:27:53 +00:00
|
|
|
// Finds available themes on the file system and loads these,
|
|
|
|
// including the parsing of individual theme components
|
|
|
|
// (includes, features, variables, views, elements).
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_THEME_DATA_H
|
|
|
|
#define ES_CORE_THEME_DATA_H
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "math/Vector2f.h"
|
2019-07-06 14:50:50 +00:00
|
|
|
#include "math/Vector4f.h"
|
2018-01-29 22:50:10 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2013-12-31 03:48:28 +00:00
|
|
|
#include <deque>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <map>
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <memory>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <sstream>
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <vector>
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2017-11-10 19:16:42 +00:00
|
|
|
namespace pugi { class xml_node; }
|
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
template<typename T>
|
|
|
|
class TextListComponent;
|
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
class GuiComponent;
|
2013-12-30 23:23:34 +00:00
|
|
|
class ImageComponent;
|
|
|
|
class NinePatchComponent;
|
2017-11-01 22:21:10 +00:00
|
|
|
class Sound;
|
2013-12-30 23:23:34 +00:00
|
|
|
class TextComponent;
|
|
|
|
class Window;
|
|
|
|
|
|
|
|
namespace ThemeFlags
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
enum PropertyFlags : unsigned int {
|
|
|
|
PATH = 1,
|
|
|
|
POSITION = 2,
|
|
|
|
SIZE = 4,
|
|
|
|
ORIGIN = 8,
|
|
|
|
COLOR = 16,
|
|
|
|
FONT_PATH = 32,
|
|
|
|
FONT_SIZE = 64,
|
|
|
|
SOUND = 128,
|
|
|
|
ALIGNMENT = 256,
|
|
|
|
TEXT = 512,
|
|
|
|
FORCE_UPPERCASE = 1024,
|
|
|
|
LINE_SPACING = 2048,
|
|
|
|
DELAY = 4096,
|
|
|
|
Z_INDEX = 8192,
|
|
|
|
ROTATION = 16384,
|
|
|
|
VISIBLE = 32768,
|
|
|
|
ALL = 0xFFFFFFFF
|
|
|
|
};
|
2013-12-30 23:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ThemeException : public std::exception
|
|
|
|
{
|
2013-12-31 03:48:28 +00:00
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string msg;
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual const char* what() const throw() { return msg.c_str(); }
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
template<typename T>
|
|
|
|
friend ThemeException& operator<<(ThemeException& e, T msg);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
inline void setFiles(const std::deque<std::string>& deque)
|
|
|
|
{
|
2020-08-18 15:48:21 +00:00
|
|
|
*this << "From theme \"" << deque.front() << "\"\n";
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto it = deque.cbegin() + 1; it != deque.cend(); it++)
|
|
|
|
*this << " (from included file \"" << (*it) << "\")\n";
|
|
|
|
*this << " ";
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
};
|
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
template<typename T>
|
|
|
|
ThemeException& operator<<(ThemeException& e, T appendMsg)
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << e.msg << appendMsg;
|
|
|
|
e.msg = ss.str();
|
|
|
|
return e;
|
2013-12-30 23:23:34 +00:00
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
struct ThemeSet
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string path;
|
2014-05-01 02:12:45 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
inline std::string getName() const { return Utils::FileSystem::getStem(path); }
|
|
|
|
inline std::string getThemePath(const std::string& system) const
|
|
|
|
{ return path + "/" + system + "/theme.xml"; }
|
2014-05-01 02:12:45 +00:00
|
|
|
};
|
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
class ThemeData
|
|
|
|
{
|
2014-01-01 05:39:22 +00:00
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
class ThemeElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool extra;
|
|
|
|
std::string type;
|
|
|
|
|
|
|
|
struct Property {
|
2020-10-17 12:05:41 +00:00
|
|
|
void operator= (const Vector4f& value)
|
|
|
|
{
|
|
|
|
r = value;
|
|
|
|
const Vector4f initVector = value;
|
|
|
|
v = Vector2f(initVector.x(), initVector.y());
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
void operator= (const Vector2f& value) { v = value; }
|
|
|
|
void operator= (const std::string& value) { s = value; }
|
|
|
|
void operator= (const unsigned int& value) { i = value; }
|
|
|
|
void operator= (const float& value) { f = value; }
|
|
|
|
void operator= (const bool& value) { b = value; }
|
|
|
|
|
|
|
|
Vector4f r;
|
|
|
|
Vector2f v;
|
|
|
|
std::string s;
|
|
|
|
unsigned int i;
|
|
|
|
float f;
|
|
|
|
bool b;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map< std::string, Property > properties;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
const T get(const std::string& prop) const
|
|
|
|
{
|
|
|
|
if (std::is_same<T, Vector2f>::value)
|
|
|
|
return *(const T*)&properties.at(prop).v;
|
|
|
|
else if (std::is_same<T, std::string>::value)
|
|
|
|
return *(const T*)&properties.at(prop).s;
|
|
|
|
else if (std::is_same<T, unsigned int>::value)
|
|
|
|
return *(const T*)&properties.at(prop).i;
|
|
|
|
else if (std::is_same<T, float>::value)
|
|
|
|
return *(const T*)&properties.at(prop).f;
|
|
|
|
else if (std::is_same<T, bool>::value)
|
|
|
|
return *(const T*)&properties.at(prop).b;
|
|
|
|
else if (std::is_same<T, Vector4f>::value)
|
|
|
|
return *(const T*)&properties.at(prop).r;
|
|
|
|
return T();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool has(const std::string& prop) const
|
|
|
|
{ return (properties.find(prop) != properties.cend()); }
|
|
|
|
};
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-01-01 05:39:22 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
class ThemeView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::map<std::string, ThemeElement> elements;
|
|
|
|
std::vector<std::string> orderedKeys;
|
|
|
|
};
|
2013-11-12 23:28:15 +00:00
|
|
|
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeData();
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Throws ThemeException.
|
|
|
|
void loadFile(std::map<std::string, std::string> sysDataMap, const std::string& path);
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
enum ElementPropertyType {
|
|
|
|
NORMALIZED_RECT,
|
|
|
|
NORMALIZED_PAIR,
|
|
|
|
PATH,
|
|
|
|
STRING,
|
|
|
|
COLOR,
|
|
|
|
FLOAT,
|
|
|
|
BOOLEAN
|
|
|
|
};
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool hasView(const std::string& view);
|
2017-02-25 04:19:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// If expectedType is an empty string, will do no type checking.
|
|
|
|
const ThemeElement* getElement(const std::string& view, const std::string& element,
|
|
|
|
const std::string& expectedType) const;
|
2013-12-31 03:48:28 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static std::vector<GuiComponent*> makeExtras(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view, Window* window);
|
2014-01-03 14:26:39 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static const std::shared_ptr<ThemeData>& getDefault();
|
2014-01-03 16:40:36 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static std::map<std::string, ThemeSet> getThemeSets();
|
|
|
|
static std::string getThemeFromCurrentSet(const std::string& system);
|
2014-05-01 02:12:45 +00:00
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
static std::map< std::string, std::map<std::string, ElementPropertyType> > sElementMap;
|
|
|
|
static std::vector<std::string> sSupportedFeatures;
|
|
|
|
static std::vector<std::string> sSupportedViews;
|
|
|
|
|
|
|
|
std::deque<std::string> mPaths;
|
|
|
|
float mVersion;
|
|
|
|
|
|
|
|
void parseFeatures(const pugi::xml_node& themeRoot);
|
|
|
|
void parseIncludes(const pugi::xml_node& themeRoot);
|
|
|
|
void parseVariables(const pugi::xml_node& root);
|
|
|
|
void parseViews(const pugi::xml_node& themeRoot);
|
|
|
|
void parseView(const pugi::xml_node& viewNode, ThemeView& view);
|
|
|
|
void parseElement(const pugi::xml_node& elementNode,
|
|
|
|
const std::map<std::string, ElementPropertyType>& typeMap, ThemeElement& element);
|
|
|
|
|
|
|
|
std::map<std::string, ThemeView> mViews;
|
2013-11-12 23:28:15 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_THEME_DATA_H
|