TDME2 1.9.121
GUIScreenNode.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <unordered_map>
5#include <unordered_set>
6#include <vector>
7
8#include <tdme/tdme.h>
11#include <tdme/gui/fwd-tdme.h>
17
18using std::string;
19using std::to_string;
20using std::unordered_map;
21using std::unordered_set;
22using std::vector;
23
47using tdme::gui::GUI;
49
50/**
51 * GUI screen node that represents a screen that can be rendered via GUI system
52 * @author Andreas Drewke
53 * @version $Id$
54 */
56 : public GUIParentNode
57{
58 friend class tdme::gui::GUI;
60 friend class GUIElementNode;
61 friend class GUINode;
62 friend class GUINodeConditions;
63 friend class GUIParentNode;
64
65private:
68 string fileName;
69 GUI* gui { nullptr };
73 unordered_map<string, GUINode*> nodesById;
74 unordered_map<string, GUINode*> tickNodesById;
75 vector<GUINode*> floatingNodes;
76 vector<GUIActionListener*> actionListener;
77 vector<GUIChangeListener*> changeListener;
78 vector<GUIMouseOverListener*> mouseOverListener;
79 vector<GUIContextMenuRequestListener*> contextMenuRequestListener;
80 vector<GUIFocusListener*> focusListener;
82 vector<GUINode*> childControllerNodes;
84 unordered_set<string> invalidateLayoutNodeIds;
85 unordered_map<string, unordered_set<string>> elementNodeToNodeMapping;
86
87 bool visible;
88 bool popUp;
89
90 unordered_map<int64_t, string> timedExpressions;
91
93 string node;
94 string toNode;
95 };
96
97 vector<ScrollToNodeStruct> scrollToNodesX;
98 vector<ScrollToNodeStruct> scrollToNodesY;
99
100public:
101 /**
102 * @return screen filename or complete file path
103 */
104 inline const string& getFileName() {
105 return fileName;
106 }
107
108 /**
109 * @return application root path name
110 */
111 inline const string& getApplicationRootPathName() {
113 }
114
115 /**
116 * @return application sub folder path name
117 */
118 inline const string& getApplicationSubPathName() {
120 }
121
122 /**
123 * @return GUI
124 */
125 GUI* getGUI();
126
127 /**
128 * Set GUI
129 * @param gui gui
130 */
131 void setGUI(GUI* gui);
132
133 /**
134 * @return screen width
135 */
136 inline int getScreenWidth() {
137 return screenWidth;
138 }
139
140 /**
141 * @return screen height
142 */
143 inline int getScreenHeight() {
144 return screenHeight;
145 }
146
147 /**
148 * @return is visible
149 */
150 inline bool isVisible() {
151 return visible;
152 }
153
154 /**
155 * Set visible
156 * @param visible visible
157 */
158 void setVisible(bool visible);
159
160 /**
161 * @return is pop up
162 */
163 inline bool isPopUp() {
164 return popUp;
165 }
166
167 /**
168 * Set pop up
169 * @param popUp pop up
170 */
171 void setPopUp(bool popUp);
172
173 /**
174 * @return floating nodes
175 */
176 const vector<GUINode*>& getFloatingNodes();
177
178 /**
179 * Register deferred scroll to node X
180 * @param node node
181 * @param toNode to node
182 */
183 inline void scrollToNodeX(const string& node, const string& toNode) {
184 scrollToNodesX.push_back(
185 {
186 .node = node,
187 .toNode = toNode
188 }
189 );
190 }
191
192 /**
193 * Register deferred scroll to node Y
194 * @param node node
195 * @param toNode to node
196 */
197 inline void scrollToNodeY(const string& node, const string& toNode) {
198 scrollToNodesY.push_back(
199 {
200 .node = node,
201 .toNode = toNode
202 }
203 );
204 }
205
206protected:
207 /**
208 * Constructor
209 * @oaram fileName file name or complete file path
210 * @param applicationRootPath application root path
211 * @param applicationSubPathName application sub path name which is usually "engine" or "project"
212 * @param flow flow
213 * @param overflowX overflow x
214 * @param overflowY overflow y
215 * @param alignments alignments
216 * @param requestedConstraints requested constraints
217 * @param backgroundColor background color
218 * @param backgroundImage background image
219 * @param backgroundImageScale9Grid background image scale 9 grid
220 * @param backgroundImageEffectColorMul background image effect color mul
221 * @param backgroundImageEffectColorAdd background image effect color add
222 * @param border border
223 * @param padding padding
224 * @param sizeConstraints size constraints
225 * @param showOn show on
226 * @param hideOn hide on
227 * @param scrollable scrollable
228 * @param popUp pop up
229 * @throws tdme::gui::GUIParserException
230 */
232 const string& fileName,
233 const string& applicationRootPathName,
234 const string& applicationSubPathName,
235 const string& id,
242 const string& backgroundImage,
246 const GUINode_Border& border,
251 bool scrollable,
252 bool popUp
253 );
254
255 /**
256 * Destructor
257 */
259
260 // overridden methods
261 bool isContentNode() override;
262 const string getNodeType() override;
263
264private:
265 /**
266 * Add node
267 * @param node node
268 * @return success
269 */
270 bool addNode(GUINode* node);
271
272 /**
273 * Add node
274 * @param node node
275 * @return success
276 */
277 bool removeNode(GUINode* node);
278
279 /**
280 * Calls registered tick nodes controller tick method
281 */
282 void tick();
283
284public:
285 /**
286 * @return content width
287 */
288 int getContentWidth() override;
289
290 /**
291 * @return content height
292 */
293 int getContentHeight() override;
294
295 /**
296 * Layout
297 */
298 void layout() override;
299
300 /**
301 * Mark a node to be invalidated regarding layout
302 * @param node node
303 * @return first node that requires a layout in tree
304 */
305 inline void invalidateLayout(GUINode* node) {
306 invalidateLayoutNodeIds.insert(node->getId());
307 }
308
309 /**
310 * Actually do the invalidate layout
311 * @param node node
312 * @return (parent)node thats need a layout
313 */
315
316 /**
317 * Actually do the nodes marked for layout invalidation
318 */
319 void invalidateLayouts();
320
321 /**
322 * Force layout node content (e.g. child nodes or content) without determining parent nodes to be layouted
323 * this does also does call layouted nodes post layout method
324 * @param node node
325 */
326 void forceLayout(GUINode* node);
327
328 /**
329 * Scroll to nodes
330 */
331 void scrollToNodes();
332
333 /**
334 * Set screen size
335 * @param width width
336 * @param height height
337 */
338 void setScreenSize(int width, int height);
339
340 /**
341 * Get GUI node by id
342 * @param nodeId nodeId
343 * @return GUI node or null
344 */
345 inline GUINode* getNodeById(const string& nodeId) {
346 auto nodesByIdIt = nodesById.find(nodeId);
347 if (nodesByIdIt == nodesById.end()) {
348 return nullptr;
349 }
350 return nodesByIdIt->second;
351 }
352
353 /**
354 * Remove GUI node by id
355 * @param nodeId nodeId
356 * @param resetScrollOffsets reset scroll offsets
357 */
358 void removeNodeById(const string& nodeId, bool resetScrollOffsets);
359
360 /**
361 * Get inner GUI node by id
362 * @param nodeId nodeId
363 * @return GUI node or null
364 */
365 inline GUINode* getInnerNodeById(const string& nodeId) {
366 return getNodeById(nodeId + "_inner");
367 }
368
369 /**
370 * Allocate node id
371 * @return node id
372 */
373 inline const string allocateNodeId() {
374 return "<" + to_string(nodeCounter++) + ">";
375 }
376
377 /**
378 * Render screen
379 * @param guiRenderer gui renderer
380 */
381 void render(GUIRenderer* guiRenderer) override;
382
383 /**
384 * Render floating nodes
385 * @param guiRenderer gui renderer
386 */
387 void renderFloatingNodes(GUIRenderer* guiRenderer);
388
389 /**
390 * Determine focussed nodes
391 * @param parentNode parent node
392 * @param focusableNodes focusable nodes
393 */
394 void determineFocussedNodes(GUIParentNode* parentNode, vector<GUIElementNode*>& focusableNodes);
395
396 // overridden methods
397 void determineMouseEventNodes(GUIMouseEvent* event, bool floatingNode, unordered_set<string>& eventNodeIds, unordered_set<string>& eventFloatingNodeIds) override;
398
399 /**
400 * Add action listener
401 * @param listener listener
402 */
403 void addActionListener(GUIActionListener* listener);
404
405 /**
406 * Remove action listener
407 * @param listener listener
408 */
410
411 /**
412 * @return input event handler
413 */
415
416 /**
417 * Set input event handler
418 * @param inputEventHandler input event handler
419 */
421
422 /**
423 * Delegate action performed
424 * @param type type
425 * @param node node
426 */
428
429 /**
430 * Add change listener
431 * @param listener listener
432 */
433 void addChangeListener(GUIChangeListener* listener);
434
435 /**
436 * Remove change listener
437 * @param listener listener
438 */
440
441 /**
442 * Delegate value changed
443 * @param node node
444 */
446
447 /**
448 * Add mouse over listener
449 * @param listener listener
450 */
452
453 /**
454 * Remove mouse over listener
455 * @param listener listener
456 */
458
459 /**
460 * Delegate mouse over event
461 * @param node node
462 */
464
465 /**
466 * Add context menu request listener
467 * @param listener listener
468 */
470
471 /**
472 * Remove context menu request listener
473 * @param listener listener
474 */
476
477 /**
478 * Delegate mouse over event
479 * @param node node
480 * @param mouseX unscaled mouse X position
481 * @param mouseY unscaled mouse Y position
482 */
483 void delegateContextMenuRequest(GUIElementNode* node, int mouseX, int mouseY);
484
485 /**
486 * Add focus listener
487 * @param listener listener
488 */
489 void addFocusListener(GUIFocusListener* listener);
490
491 /**
492 * Remove focus listener
493 * @param listener listener
494 */
496
497 /**
498 * Delegate focus event
499 * @param node node
500 */
501 void delegateFocus(GUIElementNode* node);
502
503 /**
504 * Delegate unfocus event
505 * @param node node
506 */
508
509 /**
510 * Add tick node, registered node controllers will have a tick once per frame
511 * @param
512 */
513 inline void addTickNode(GUINode* node) {
514 tickNodesById[node->getId()] = node;
515 }
516
517 /**
518 * Remove tick node
519 */
520 inline void removeTickNode(GUINode* node) {
521 tickNodesById.erase(node->getId());
522 }
523
524 /**
525 * Get values
526 * @param values values
527 */
528 void getValues(unordered_map<string, MutableString>& values);
529
530 /**
531 * Set values
532 * @param values values
533 */
534 void setValues(const unordered_map<string, MutableString>& values);
535
536 /**
537 * @return size constraints
538 */
540 return sizeConstraints;
541 }
542
543 /**
544 * Create size constraints
545 * @param minWidth min width
546 * @param minHeight min height
547 * @param maxWidth max width
548 * @param maxHeight max height
549 */
550 static GUIScreenNode_SizeConstraints createSizeConstraints(const string& minWidth, const string& minHeight, const string& maxWidth, const string& maxHeight);
551
552 /**
553 * Add a timed expression
554 * @param time time
555 * @param expression expression
556 */
557 inline void addTimedExpression(int64_t time, const string& expression) {
558 timedExpressions[time]+= timedExpressions[time].empty() == false?";" + expression:expression;
559 }
560
561 /**
562 * Add node to element node dependency
563 * @param elementNodeId element node id
564 * @param nodeId node id that depends on element node condition changes
565 */
566 inline void addNodeElementNodeDependency(const string& elementNodeId, const string& nodeId) {
567 elementNodeToNodeMapping[elementNodeId].insert(nodeId);
568 }
569};
GUI parser.
Definition: GUIParser.h:39
GUI module class.
Definition: GUI.h:66
GUI element node conditions.
GUI node base class.
Definition: GUINode.h:63
GUINodeConditions hideOn
Definition: GUINode.h:161
GUIColor backgroundImageEffectColorMul
Definition: GUINode.h:156
GUINode_Border border
Definition: GUINode.h:159
GUINode_Scale9Grid backgroundImageScale9Grid
Definition: GUINode.h:155
GUIColor backgroundImageEffectColorAdd
Definition: GUINode.h:157
GUIParentNode * parentNode
Definition: GUINode.h:147
GUINode_Padding padding
Definition: GUINode.h:158
GUINode_RequestedConstraints requestedConstraints
Definition: GUINode.h:150
const string & getId()
Definition: GUINode.h:329
GUINode_Alignments alignments
Definition: GUINode.h:149
GUINodeConditions showOn
Definition: GUINode.h:160
GUINode_Flow * flow
Definition: GUINode.h:85
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:43
GUIParentNode_Overflow * overflowX
Definition: GUIParentNode.h:67
GUIParentNode_Overflow * overflowY
Definition: GUIParentNode.h:68
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:57
GUIInputEventHandler * inputEventHandler
Definition: GUIScreenNode.h:81
void delegateUnfocus(GUIElementNode *node)
Delegate unfocus event.
void setInputEventHandler(GUIInputEventHandler *inputEventHandler)
Set input event handler.
void invalidateLayout(GUINode *node)
Mark a node to be invalidated regarding layout.
const string getNodeType() override
void determineFocussedNodes(GUIParentNode *parentNode, vector< GUIElementNode * > &focusableNodes)
Determine focussed nodes.
void setVisible(bool visible)
Set visible.
bool removeNode(GUINode *node)
Add node.
void scrollToNodeX(const string &node, const string &toNode)
Register deferred scroll to node X.
void scrollToNodeY(const string &node, const string &toNode)
Register deferred scroll to node Y.
GUIInputEventHandler * getInputEventHandler()
unordered_map< string, GUINode * > tickNodesById
Definition: GUIScreenNode.h:74
void addContextMenuRequestListener(GUIContextMenuRequestListener *listener)
Add context menu request listener.
vector< GUIMouseOverListener * > mouseOverListener
Definition: GUIScreenNode.h:78
void addTimedExpression(int64_t time, const string &expression)
Add a timed expression.
vector< GUINode * > childControllerNodes
Definition: GUIScreenNode.h:82
void scrollToNodes()
Scroll to nodes.
void addChangeListener(GUIChangeListener *listener)
Add change listener.
void removeContextMenuRequestListener(GUIContextMenuRequestListener *listener)
Remove context menu request listener.
void setPopUp(bool popUp)
Set pop up.
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
vector< GUIChangeListener * > changeListener
Definition: GUIScreenNode.h:77
void setValues(const unordered_map< string, MutableString > &values)
Set values.
GUINode * forceInvalidateLayout(GUINode *node)
Actually do the invalidate layout.
void removeChangeListener(GUIChangeListener *listener)
Remove change listener.
void removeNodeById(const string &nodeId, bool resetScrollOffsets)
Remove GUI node by id.
void layout() override
Layout.
void delegateFocus(GUIElementNode *node)
Delegate focus event.
void removeActionListener(GUIActionListener *listener)
Remove action listener.
void removeFocusListener(GUIFocusListener *listener)
Remove focus listener.
void removeMouseOverListener(GUIMouseOverListener *listener)
Remove mouse over listener.
void delegateMouseOver(GUIElementNode *node)
Delegate mouse over event.
void delegateValueChanged(GUIElementNode *node)
Delegate value changed.
vector< GUIFocusListener * > focusListener
Definition: GUIScreenNode.h:80
GUIScreenNode_SizeConstraints & getSizeConstraints()
static GUIScreenNode_SizeConstraints createSizeConstraints(const string &minWidth, const string &minHeight, const string &maxWidth, const string &maxHeight)
Create size constraints.
void tick()
Calls registered tick nodes controller tick method.
void addMouseOverListener(GUIMouseOverListener *listener)
Add mouse over listener.
void renderFloatingNodes(GUIRenderer *guiRenderer)
Render floating nodes.
void removeTickNode(GUINode *node)
Remove tick node.
void determineMouseEventNodes(GUIMouseEvent *event, bool floatingNode, unordered_set< string > &eventNodeIds, unordered_set< string > &eventFloatingNodeIds) override
Determine mouse event nodes.
GUIScreenNode_SizeConstraints sizeConstraints
Definition: GUIScreenNode.h:83
vector< ScrollToNodeStruct > scrollToNodesY
Definition: GUIScreenNode.h:98
void setScreenSize(int width, int height)
Set screen size.
void delegateActionPerformed(GUIActionListenerType type, GUIElementNode *node)
Delegate action performed.
void getValues(unordered_map< string, MutableString > &values)
Get values.
vector< GUIActionListener * > actionListener
Definition: GUIScreenNode.h:76
void render(GUIRenderer *guiRenderer) override
Render screen.
void addActionListener(GUIActionListener *listener)
Add action listener.
const string allocateNodeId()
Allocate node id.
unordered_map< string, GUINode * > nodesById
Definition: GUIScreenNode.h:73
GUINode * getInnerNodeById(const string &nodeId)
Get inner GUI node by id.
vector< GUINode * > floatingNodes
Definition: GUIScreenNode.h:75
bool addNode(GUINode *node)
Add node.
void invalidateLayouts()
Actually do the nodes marked for layout invalidation.
unordered_map< int64_t, string > timedExpressions
Definition: GUIScreenNode.h:90
unordered_map< string, unordered_set< string > > elementNodeToNodeMapping
Definition: GUIScreenNode.h:85
void setGUI(GUI *gui)
Set GUI.
void delegateContextMenuRequest(GUIElementNode *node, int mouseX, int mouseY)
Delegate mouse over event.
const string & getApplicationSubPathName()
const string & getApplicationRootPathName()
vector< ScrollToNodeStruct > scrollToNodesX
Definition: GUIScreenNode.h:97
void addFocusListener(GUIFocusListener *listener)
Add focus listener.
void addTickNode(GUINode *node)
Add tick node, registered node controllers will have a tick once per frame.
unordered_set< string > invalidateLayoutNodeIds
Definition: GUIScreenNode.h:84
void forceLayout(GUINode *node)
Force layout node content (e.g.
vector< GUIContextMenuRequestListener * > contextMenuRequestListener
Definition: GUIScreenNode.h:79
void addNodeElementNodeDependency(const string &elementNodeId, const string &nodeId)
Add node to element node dependency.
const vector< GUINode * > & getFloatingNodes()
Mutable string class.
Definition: MutableString.h:16
GUI action listener interface.
GUI change listener interface.
GUI focus listener interface.
GUI input event handler interface.
GUI node border entity.
GUI node padding entity.
GUI node scale 9 grid entity.