TDME2  1.9.200
GUIParser.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_map>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
10 #include <tdme/gui/fwd-tdme.h>
16 
17 #include <ext/tinyxml/tinyxml.h>
18 
19 using std::unordered_map;
20 using std::vector;
21 
32 
34 
35 /**
36  * GUI parser
37  * @author Andreas Drewke
38  */
40 {
41 
42 private:
43  STATIC_DLL_IMPEXT static unordered_map<string, GUIElement*> elements;
46 
47  static constexpr int FONTSIZE_FALLBACK { 14 };
48 
49 public:
50 
51  /**
52  * @return engine theme properties
53  */
54  inline static const Properties* getEngineThemeProperties() {
55  return &engineThemeProperties;
56  }
57 
58  /**
59  * @return project theme properties
60  */
61  inline static const Properties* getProjectThemeProperties() {
62  return &projectThemeProperties;
63  }
64 
65  /**
66  * Parses a XML file and returns root node as string
67  * @param pathName path name
68  * @param fileName file name
69  * @throws tdme::gui::GUIParserException
70  * @throws tdme::os::filesystem::FileSystemException
71  */
72  static const string getRootNode(const string& pathName, const string& fileName);
73 
74  /**
75  * Parses a XML string and returns root node as string
76  * @param xml xml
77  * @throws tdme::gui::GUIParserException
78  */
79  static const string getRootNode(const string& xml);
80 
81  /**
82  * Parses a GUI XML file
83  * @param pathName path name
84  * @param fileName file name
85  * @param variables variables
86  * @param miniScriptArguments mini script arguments
87  * @param context application logic context
88  * @return GUI screen node
89  * @throws tdme::gui::GUIParserException
90  * @throws tdme::os::filesystem::FileSystemException
91  */
92  static GUIScreenNode* parse(const string& pathName, const string& fileName, const unordered_map<string, string>& variables = {}, const EngineMiniScript::ScriptVariable& miniScriptArguments = EngineMiniScript::ScriptVariable(), Context* context = nullptr);
93 
94  /**
95  * Parses a GUI XML content
96  * @param xml xml
97  * @param variables variables
98  * @param pathName path name
99  * @param fileName file name
100  * @param miniScriptArguments mini script arguments
101  * @param context application logic context
102  * @return GUI screen node
103  * @throws tdme::gui::GUIParserException
104  * @throws tdme::os::filesystem::FileSystemException
105  */
106  static GUIScreenNode* parse(const string& xml, const unordered_map<string, string>& variables = {}, const string& pathName = string(), const string& fileName = string(), const EngineMiniScript::ScriptVariable& miniScriptArguments = EngineMiniScript::ScriptVariable(), Context* context = nullptr);
107 
108  /**
109  * Parses a GUI XML file into parent node
110  * @param parentNode parent node
111  * @param pathName path name
112  * @param fileName file name
113  * @throws tdme::gui::GUIParserException
114  * @throws tdme::os::filesystem::FileSystemException
115  */
116  static void parse(GUIParentNode* parentNode, const string& pathName, const string& fileName);
117 
118  /**
119  * Parses a GUI XML content into parent node
120  * @param parentNode parent node
121  * @param xml xml
122  * @throws tdme::gui::GUIParserException
123  * @throws tdme::os::filesystem::FileSystemException
124  */
125  static void parse(GUIParentNode* parentNode, const string& xml);
126 
127 private:
128 
129  /**
130  * Parse GUI effect
131  * @param guiNode GUI node
132  * @param effectPrefix effect prefix
133  * @param requiresCondition requires condition
134  * @param node node
135  */
136  static void parseEffect(GUINode* guiNode, const string& effectPrefix, bool requiresCondition, TiXmlElement* node);
137 
138  /**
139  * Parse GUI effect
140  * @param guiNode GUI node
141  * @param xmlParentNode xml parent node
142  */
143  static void parseEffects(GUINode* guiNode, TiXmlElement* xmlParentNode);
144 
145  /**
146  * Parse GUI node
147  * @param guiParentNode gui parent node
148  * @param parentElementId parent element id
149  * @param xmlParentNode xml parent node
150  * @param guiElement gui element
151  * @throws tdme::gui::GUIParserException
152  * @throws tdme::os::filesystem::FileSystemException
153  */
154  static void parseGUINode(GUIParentNode* guiParentNode, const string& parentElementId, TiXmlElement* xmlParentNode, GUIElement* guiElement);
155 
156  /**
157  * Returns immediate children tags
158  * @param parent parent
159  * @param name name
160  * @return children of parent node with given name
161  */
162  static const vector<TiXmlElement*> getChildrenByTagName(TiXmlElement* parent, const char* name);
163 
164  /**
165  * Get inner XML
166  * @param node node
167  * @return string
168  */
169  static const string getInnerXml(TiXmlElement* node);
170 
171  /**
172  * Parse template
173  * @param guiParentNode GUI parent node
174  * @param parentElementId parent element id
175  * @param node template xml node
176  * @param templateXML template xml
177  * @param attributes attributes
178  * @param guiElement GUI element
179  */
180  static void parseTemplate(GUIParentNode* guiParentNode, const string& parentElementId, TiXmlElement* node, const string& templateXML, const unordered_map<string, string>& attributes, GUIElement* guiElement);
181 
182  /**
183  * Parse inner XML
184  * @param guiParentNode GUI parent node
185  * @param parentElementId parent element id
186  * @param node template xml node
187  * @param innerXML inner xml
188  * @param attributes attributes
189  * @param guiElement GUI element
190  */
191  static void parseInnerXML(GUIParentNode* guiParentNode, const string& parentElementId, TiXmlElement* node, const string& innerXML, const unordered_map<string, string>& attributes, GUIElement* guiElement);
192 
193  /**
194  * Parse factor
195  * @param guiParentNode gui parent node
196  * @param factor factor
197  * @return factor
198  */
199  static int parseFactor(GUIParentNode* guiParentNode, const string& factor);
200 
201  /**
202  * Parse integer
203  * @param value value
204  * @param defaultValue default value
205  * @return size
206  */
207  static int parseInteger(const string& value, int defaultValue);
208 
209 public:
210  /**
211  * Parse template attributes
212  * @param templateXML template xml
213  * @param guiElement GUI element
214  * @return parsed template attributes
215  */
216  static unordered_map<string, string> parseTemplateAttributes(const string& templateXML);
217 
218  /**
219  * Get inner XML from XML string
220  * @param xml xml
221  * @return string
222  */
223  static const string getInnerXml(const string& xml);
224 
225  /**
226  * Unescape quotes and other special html characters
227  * @param str string
228  * @return string with unescaped quotes
229  */
230  static const string unescape(const string& str);
231 
232  /**
233  * Escape quotes and other special html characters
234  * @param str string
235  * @return string with escaped quotes
236  */
237  static const string escape(const string& str);
238 
239  /**
240  * Add GUI element
241  * @param guiElement guiElement
242  * @throws tdme::gui::GUIParserException
243  * @throws tdme::os::filesystem::FileSystemException
244  */
245  static void addElement(GUIElement* guiElement);
246 
247  /**
248  * Initialize GUI elements
249  */
250  static void initialize();
251 
252  /**
253  * Dispose GUI elements
254  */
255  static void dispose();
256 
257  /**
258  * Load project theme properties
259  * @param pathName path name
260  */
261  static void loadProjectThemeProperties(const string& pathName);
262 
263 };
GUI parser.
Definition: GUIParser.h:40
static void parseEffects(GUINode *guiNode, TiXmlElement *xmlParentNode)
Parse GUI effect.
Definition: GUIParser.cpp:381
static void parseInnerXML(GUIParentNode *guiParentNode, const string &parentElementId, TiXmlElement *node, const string &innerXML, const unordered_map< string, string > &attributes, GUIElement *guiElement)
Parse inner XML.
Definition: GUIParser.cpp:1638
static const string getInnerXml(TiXmlElement *node)
Get inner XML.
Definition: GUIParser.cpp:1726
static const string unescape(const string &str)
Unescape quotes and other special html characters.
Definition: GUIParser.cpp:1792
static void initialize()
Initialize GUI elements.
Definition: GUIParser.cpp:1826
static GUIScreenNode * parse(const string &xml, const unordered_map< string, string > &variables={}, const string &pathName=string(), const string &fileName=string(), const EngineMiniScript::ScriptVariable &miniScriptArguments=EngineMiniScript::ScriptVariable(), Context *context=nullptr)
Parses a GUI XML content.
static const Properties * getEngineThemeProperties()
Definition: GUIParser.h:54
static STATIC_DLL_IMPEXT Properties projectThemeProperties
Definition: GUIParser.h:45
static const Properties * getProjectThemeProperties()
Definition: GUIParser.h:61
static void addElement(GUIElement *guiElement)
Add GUI element.
Definition: GUIParser.cpp:1814
static int parseInteger(const string &value, int defaultValue)
Parse integer.
Definition: GUIParser.cpp:1708
static STATIC_DLL_IMPEXT unordered_map< string, GUIElement * > elements
Definition: GUIParser.h:43
static int parseFactor(GUIParentNode *guiParentNode, const string &factor)
Parse factor.
Definition: GUIParser.cpp:1683
static void parseGUINode(GUIParentNode *guiParentNode, const string &parentElementId, TiXmlElement *xmlParentNode, GUIElement *guiElement)
Parse GUI node.
Definition: GUIParser.cpp:396
static const string escape(const string &str)
Escape quotes and other special html characters.
Definition: GUIParser.cpp:1803
static void dispose()
Dispose GUI elements.
Definition: GUIParser.cpp:2066
static GUIScreenNode * parse(const string &pathName, const string &fileName, const unordered_map< string, string > &variables={}, const EngineMiniScript::ScriptVariable &miniScriptArguments=EngineMiniScript::ScriptVariable(), Context *context=nullptr)
Parses a GUI XML file.
static const string getRootNode(const string &pathName, const string &fileName)
Parses a XML file and returns root node as string.
Definition: GUIParser.cpp:168
static void loadProjectThemeProperties(const string &pathName)
Load project theme properties.
Definition: GUIParser.cpp:2071
static void parseTemplate(GUIParentNode *guiParentNode, const string &parentElementId, TiXmlElement *node, const string &templateXML, const unordered_map< string, string > &attributes, GUIElement *guiElement)
Parse template.
Definition: GUIParser.cpp:1562
static constexpr int FONTSIZE_FALLBACK
Definition: GUIParser.h:47
static const vector< TiXmlElement * > getChildrenByTagName(TiXmlElement *parent, const char *name)
Returns immediate children tags.
Definition: GUIParser.cpp:1717
static STATIC_DLL_IMPEXT Properties engineThemeProperties
Definition: GUIParser.h:44
static unordered_map< string, string > parseTemplateAttributes(const string &templateXML)
Parse template attributes.
Definition: GUIParser.cpp:1742
static void parseEffect(GUINode *guiNode, const string &effectPrefix, bool requiresCondition, TiXmlElement *node)
Parse GUI effect.
Definition: GUIParser.cpp:330
GUI effect base class.
Definition: GUIEffect.h:26
GUI element base class.
Definition: GUIElement.h:23
GUI node base class.
Definition: GUINode.h:64
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
Properties class, which helps out with storeing or loading key value pairs from/to property files.
Definition: Properties.h:23
The element is a container class.
Definition: tinyxml.h:886
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15