2013-11-12 23:28:15 +00:00
|
|
|
#pragma once
|
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"
|
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
|
|
|
{
|
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);
|
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
inline void setFiles(const std::deque<std::string>& deque)
|
2013-12-31 03:48:28 +00:00
|
|
|
{
|
2018-01-29 22:50:10 +00:00
|
|
|
*this << "from theme \"" << deque.front() << "\"\n";
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto it = deque.cbegin() + 1; it != deque.cend(); it++)
|
2018-01-29 22:50:10 +00:00
|
|
|
*this << " (from included file \"" << (*it) << "\")\n";
|
2013-12-31 03:48:28 +00:00
|
|
|
*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
|
|
|
|
{
|
2018-01-29 22:50:10 +00:00
|
|
|
std::string path;
|
2014-05-01 02:12:45 +00:00
|
|
|
|
2018-01-29 22:50:10 +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:
|
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-11-29 19:57:43 +00:00
|
|
|
struct Property
|
|
|
|
{
|
|
|
|
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; }
|
|
|
|
|
|
|
|
Vector2f v;
|
|
|
|
std::string s;
|
|
|
|
unsigned int i;
|
|
|
|
float f;
|
|
|
|
bool b;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map< std::string, Property > properties;
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
template<typename T>
|
2017-11-29 19:57:43 +00:00
|
|
|
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;
|
|
|
|
return T();
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
inline bool has(const std::string& prop) const { return (properties.find(prop) != properties.cend()); }
|
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();
|
2018-01-29 22:50:10 +00:00
|
|
|
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:
|
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
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
std::deque<std::string> 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
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_THEME_DATA_H
|