2013-11-12 23:28:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2013-11-12 23:28:15 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
2013-12-31 03:48:28 +00:00
|
|
|
#include <deque>
|
2013-11-12 23:28:15 +00:00
|
|
|
#include <string>
|
2013-12-30 23:23:34 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/variant.hpp>
|
2017-05-14 04:07:28 +00:00
|
|
|
#include <boost/xpressive/xpressive.hpp>
|
2017-04-03 18:45:28 +00:00
|
|
|
#include "pugixml/src/pugixml.hpp"
|
2013-12-30 23:23:34 +00:00
|
|
|
#include "GuiComponent.h"
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class TextListComponent;
|
|
|
|
|
|
|
|
class Sound;
|
|
|
|
class ImageComponent;
|
|
|
|
class NinePatchComponent;
|
|
|
|
class TextComponent;
|
|
|
|
class Window;
|
|
|
|
|
|
|
|
namespace ThemeFlags
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2013-12-30 23:23:34 +00:00
|
|
|
enum PropertyFlags : unsigned int
|
|
|
|
{
|
|
|
|
PATH = 1,
|
|
|
|
POSITION = 2,
|
|
|
|
SIZE = 4,
|
|
|
|
ORIGIN = 8,
|
|
|
|
COLOR = 16,
|
|
|
|
FONT_PATH = 32,
|
|
|
|
FONT_SIZE = 64,
|
2014-01-19 18:23:01 +00:00
|
|
|
SOUND = 128,
|
2014-01-22 02:43:33 +00:00
|
|
|
ALIGNMENT = 256,
|
2014-01-19 18:23:01 +00:00
|
|
|
TEXT = 512,
|
2014-05-03 19:51:50 +00:00
|
|
|
FORCE_UPPERCASE = 1024,
|
2014-05-14 22:01:40 +00:00
|
|
|
LINE_SPACING = 2048,
|
2016-12-04 23:47:34 +00:00
|
|
|
DELAY = 4096,
|
2017-04-22 14:15:16 +00:00
|
|
|
Z_INDEX = 8192,
|
2017-07-17 03:10:29 +00:00
|
|
|
ROTATION = 16384,
|
2014-01-03 14:26:39 +00:00
|
|
|
ALL = 0xFFFFFFFF
|
2013-12-30 23:23:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class ThemeException : public std::exception
|
|
|
|
{
|
2013-12-31 03:48:28 +00:00
|
|
|
public:
|
2013-12-30 23:23:34 +00:00
|
|
|
std::string msg;
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
virtual const char* what() const throw() { return msg.c_str(); }
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
template<typename T>
|
|
|
|
friend ThemeException& operator<<(ThemeException& e, T msg);
|
|
|
|
|
2013-12-31 03:48:28 +00:00
|
|
|
inline void setFiles(const std::deque<boost::filesystem::path>& deque)
|
|
|
|
{
|
|
|
|
*this << "from theme \"" << deque.front().string() << "\"\n";
|
|
|
|
for(auto it = deque.begin() + 1; it != deque.end(); it++)
|
|
|
|
*this << " (from included file \"" << (*it).string() << "\")\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
|
|
|
{
|
2013-12-30 23:23:34 +00:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << e.msg << appendMsg;
|
|
|
|
e.msg = ss.str();
|
|
|
|
return e;
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
struct ThemeSet
|
|
|
|
{
|
|
|
|
boost::filesystem::path path;
|
|
|
|
|
|
|
|
inline std::string getName() const { return path.stem().string(); }
|
|
|
|
inline boost::filesystem::path getThemePath(const std::string& system) const { return path/system/"theme.xml"; }
|
|
|
|
};
|
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
class ThemeData
|
|
|
|
{
|
2014-01-01 05:39:22 +00:00
|
|
|
public:
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
class ThemeElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool extra;
|
|
|
|
std::string type;
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
std::map< std::string, boost::variant<Vector2f, std::string, unsigned int, float, bool> > properties;
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
template<typename T>
|
2014-01-01 05:39:22 +00:00
|
|
|
T get(const std::string& prop) const { return boost::get<T>(properties.at(prop)); }
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-01-01 05:39:22 +00:00
|
|
|
inline bool has(const std::string& prop) const { return (properties.find(prop) != properties.end()); }
|
2013-12-30 23:23:34 +00:00
|
|
|
};
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-01-01 05:39:22 +00:00
|
|
|
private:
|
2013-12-30 23:23:34 +00:00
|
|
|
class ThemeView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::map<std::string, ThemeElement> elements;
|
2014-01-09 23:13:52 +00:00
|
|
|
std::vector<std::string> orderedKeys;
|
2013-12-30 23:23:34 +00:00
|
|
|
};
|
2013-11-12 23:28:15 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ThemeData();
|
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
// throws ThemeException
|
2017-05-14 04:07:28 +00:00
|
|
|
void loadFile(std::map<std::string, std::string> sysDataMap, const std::string& path);
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
enum ElementPropertyType
|
|
|
|
{
|
|
|
|
NORMALIZED_PAIR,
|
|
|
|
PATH,
|
|
|
|
STRING,
|
|
|
|
COLOR,
|
|
|
|
FLOAT,
|
|
|
|
BOOLEAN
|
|
|
|
};
|
|
|
|
|
2017-02-25 04:19:29 +00:00
|
|
|
bool hasView(const std::string& view);
|
|
|
|
|
2014-01-01 05:39:22 +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
|
|
|
|
2014-01-03 14:26:39 +00:00
|
|
|
static std::vector<GuiComponent*> makeExtras(const std::shared_ptr<ThemeData>& theme, const std::string& view, Window* window);
|
|
|
|
|
2014-01-03 16:40:36 +00:00
|
|
|
static const std::shared_ptr<ThemeData>& getDefault();
|
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
static std::map<std::string, ThemeSet> getThemeSets();
|
|
|
|
static boost::filesystem::path getThemeFromCurrentSet(const std::string& system);
|
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
private:
|
2013-12-30 23:23:34 +00:00
|
|
|
static std::map< std::string, std::map<std::string, ElementPropertyType> > sElementMap;
|
2017-03-10 18:49:15 +00:00
|
|
|
static std::vector<std::string> sSupportedFeatures;
|
|
|
|
static std::vector<std::string> sSupportedViews;
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2013-12-31 03:48:28 +00:00
|
|
|
std::deque<boost::filesystem::path> mPaths;
|
2013-12-30 23:23:34 +00:00
|
|
|
float mVersion;
|
|
|
|
|
2017-03-10 18:49:15 +00:00
|
|
|
void parseFeatures(const pugi::xml_node& themeRoot);
|
2013-12-31 03:48:28 +00:00
|
|
|
void parseIncludes(const pugi::xml_node& themeRoot);
|
2017-05-14 04:07:28 +00:00
|
|
|
void parseVariables(const pugi::xml_node& root);
|
2013-12-31 03:48:28 +00:00
|
|
|
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);
|
2013-12-30 23:23:34 +00:00
|
|
|
|
|
|
|
std::map<std::string, ThemeView> mViews;
|
2013-11-12 23:28:15 +00:00
|
|
|
};
|