TDME2 1.9.121
GUIMenuHeaderItemController.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
18#include <tdme/gui/GUI.h>
22
23using std::to_string;
24
37using tdme::gui::GUI;
41
42string GUIMenuHeaderItemController::CONDITION_OPENED = "opened";
43string GUIMenuHeaderItemController::CONDITION_CLOSED = "closed";
44string GUIMenuHeaderItemController::CONDITION_SELECTED = "selected";
45string GUIMenuHeaderItemController::CONDITION_UNSELECTED = "unselected";
46
47
48GUIMenuHeaderItemController::GUIMenuHeaderItemController(GUINode* node)
50{
51 this->selected = required_dynamic_cast<GUIElementNode*>(node)->isSelected();
52 this->open = false;
53}
54
56{
57 return selected;
58}
59
61{
62 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
63 nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
64 this->selected = true;
65 nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
66}
67
69{
70 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
71 nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
72 this->selected = false;
73 nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
74}
75
77{
78 required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions().add(open == true?CONDITION_OPENED:CONDITION_CLOSED);
79
80 //
81 GUIElementController::initialize();
82
83 //
84 if (this->selected == true) select(); else unselect();
85
86 //
88 while (true == true) {
89 if (dynamic_cast<GUIMenuHeaderController*>(menuHeaderNode->getController()) != nullptr) {
90 break;
91 }
93 }
94}
95
97{
98 GUIElementController::dispose();
99}
100
102{
103}
104
106{
107 return open;
108}
109
111{
112 required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions().remove(open == true?CONDITION_OPENED:CONDITION_CLOSED);
113 open = open == true?false:true;
114 required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions().add(open == true?CONDITION_OPENED:CONDITION_CLOSED);
115 if (open == true) select(); else unselect();
116}
117
119{
120 vector<GUINode*> childControllerNodes;
121 menuItemControllers.clear();
122 required_dynamic_cast<GUIParentNode*>(node)->getChildControllerNodes(childControllerNodes);
123 for (auto i = 0; i < childControllerNodes.size(); i++) {
124 auto childControllerNode = childControllerNodes[i];
125 auto childController = childControllerNode->getController();
126 auto menuItemController = dynamic_cast<GUIMenuItemController*>(childController);
127 if (menuItemController != nullptr) {
128 menuItemControllers.push_back(menuItemController);
129 }
130 }
131}
132
134{
135 if (selectedMenuItemControllerIdx == -1) return;
136 if (menuItemControllers.empty() == true) return;
138}
139
141{
143 if (menuItemControllers.empty() == true) return;
145 selectNext();
146}
147
149{
151 if (menuItemControllers.empty() == true) return;
152
153 auto disabledItems = 0;
154 while (disabledItems < menuItemControllers.size()) {
159 disabledItems++;
160 }
161
162 if (disabledItems == menuItemControllers.size()) {
164 return;
165 }
166
168}
169
171{
173 if (menuItemControllers.empty() == true) return;
175
176 auto disabledItems = 0;
177 while (disabledItems < menuItemControllers.size()) {
182 disabledItems++;
183 }
184
185 if (disabledItems == menuItemControllers.size()) {
187 return;
188 }
189
191
193{
195 if (selectedMenuItemControllerIdx == -1) return;
196 menuItemControllers[selectedMenuItemControllerIdx]->handleKeyboardEvent(event);
197}
198
200{
201 GUIElementController::handleMouseEvent(node, event);
202 if (isDisabled() == true) return;
203 auto elementNode = required_dynamic_cast<GUIElementNode*>(this->node);
204 auto menuHeaderController = required_dynamic_cast<GUIMenuHeaderController*>(menuHeaderNode->getController());
205 auto menuOpened = menuHeaderController->isOpen();
206 if (menuOpened == false) {
207 if (node == this->node &&
208 event->getButton() == MOUSE_BUTTON_LEFT &&
209 event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED &&
210 node->isEventBelongingToNode(event) == true) {
211 if (open == false) {
212 event->setProcessed(true);
213 unselect();
214 menuHeaderController->select(required_dynamic_cast<GUIElementNode*>(this->node));
215 }
216 }
217 } else {
219 if (open == true &&
220 node == this->node &&
221 event->getButton() == MOUSE_BUTTON_LEFT &&
222 event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
223 auto innerNode = this->node->getScreenNode()->getNodeById(this->node->getId() + "_inner");
224 if (innerNode->isEventBelongingToNode(event) == false) {
225 event->setProcessed(true);
227 menuHeaderController->unselect();
228 }
229 } else
230 if (node == this->node &&
231 event->getType() == GUIMouseEvent::MOUSEEVENT_MOVED) {
232 if (node == this->node && node->isEventBelongingToNode(event) == true) {
233 if (open == false) {
234 event->setProcessed(true);
236 menuHeaderController->select(required_dynamic_cast<GUIElementNode*>(this->node)); }
237 }
238 }
239 }
240}
241
243{
244 GUIElementController::handleKeyboardEvent(event);
245}
246
248{
249 GUIElementController::tick();
250 if (open == true) node->getScreenNode()->getGUI()->addMouseOutClickCandidateElementNode(required_dynamic_cast<GUIElementNode*>(this->node));
251}
252
254{
255}
256
258{
259}
260
262{
263 return true;
264}
265
267{
268 value.reset();
269 return value;
270}
271
273{
275}
276
280}
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:66
void addMouseOutClickCandidateElementNode(GUINode *node)
Add node that is a possible mouse click out candidate as it received a mouse click.
Definition: GUI.h:118
void setFoccussedNode(GUIElementNode *newFoccussedNode)
Set focussed node.
Definition: GUI.cpp:359
void initialize() override
Initialize controller after element has been created.
void handleKeyboardEvent(GUIKeyboardEvent *event) override
Handle keyboard event.
void handleCurrentMenuItemKeyboardEvent(GUIKeyboardEvent *event)
Handle current menu item keyboard event.
void determineMenuItemControllers()
Determine menu item controllers.
void setValue(const MutableString &value) override
Set value.
void handleMouseEvent(GUINode *node, GUIMouseEvent *event) override
Handle mouse event.
void tick() override
Tick method will be executed once per frame.
GUI element node conditions.
GUI node base class.
Definition: GUINode.h:63
GUIParentNode * getParentControllerNode()
Definition: GUINode.cpp:1053
const string & getId()
Definition: GUINode.h:329
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &position)
Is event belonging to node.
Definition: GUINode.cpp:973
GUIScreenNode * getScreenNode()
Definition: GUINode.h:315
GUINodeController * getController()
Definition: GUINode.h:586
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:43
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:57
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
Console class.
Definition: Console.h:26
Mutable string class.
Definition: MutableString.h:16
MutableString & reset()
Reset.
String tools class.
Definition: StringTools.h:20