TDME2 1.9.121
GUIMenuHeaderController.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
14#include <tdme/gui/GUI.h>
16
26using tdme::gui::GUI;
28
29GUIMenuHeaderController::GUIMenuHeaderController(GUINode* node)
30 : GUINodeController(node)
31{
32 this->focus = false;
33}
34
36{
37 return false;
38}
39
41{
42}
43
45{
46}
47
49{
50}
51
53{
54}
55
57{
58 return focus;
59}
60
62{
64 vector<GUINode*> childControllerNodes;
65 required_dynamic_cast<GUIParentNode*>(node)->getChildControllerNodes(childControllerNodes);
66 for (auto i = 0; i < childControllerNodes.size(); i++) {
67 auto childControllerNode = childControllerNodes[i];
68 auto childController = childControllerNode->getController();
69 if (dynamic_cast<GUIMenuHeaderItemController*>(childController) != nullptr) {
70 auto menuHeaderItemController = required_dynamic_cast<GUIMenuHeaderItemController*>(childController);
71 if (menuHeaderItemController == nullptr)
72 continue;
73 menuHeaderItemControllers.push_back(menuHeaderItemController);
74 }
75 }
76}
77
79 if (menuHeaderItemControllerIdx == -1) return false;
81}
82
84 if (menuHeaderItemControllerIdx == -1) return;
88 }
89}
90
92{
93 unselect();
94 if (menuHeaderItemControllers.empty() == true) return;
95
96 auto disabledItems = 0;
97 while (disabledItems < menuHeaderItemControllers.size()) {
102 disabledItems++;
103 }
104 if (disabledItems == menuHeaderItemControllers.size()) {
106 return;
107 }
108
112}
113
115{
116 unselect();
117 if (menuHeaderItemControllers.empty() == true) return;
119
120 auto disabledItems = 0;
121 while (disabledItems < menuHeaderItemControllers.size()) {
126 disabledItems++;
127 }
128 if (disabledItems == menuHeaderItemControllers.size()) {
130 return;
131 }
132
136}
137
139 unselect();
143}
144
146 auto selectedMenuHeaderItemController = required_dynamic_cast<GUIMenuHeaderItemController*>(elementNode->getController());
147 auto i = 0;
148 for (auto menuHeaderItemController: menuHeaderItemControllers) {
149 if (menuHeaderItemController == selectedMenuHeaderItemController) {
150 select(i);
151 return;
152 }
153 i++;
154 }
155}
156
158{
159 if (node == this->node && node->isEventBelongingToNode(event) && event->getButton() == MOUSE_BUTTON_LEFT) {
160 event->setProcessed(true);
161 if (event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
162 node->getScreenNode()->getGUI()->setFoccussedNode(required_dynamic_cast<GUIElementNode*>(node));
163 }
164 }
165}
166
168{
169 switch (event->getKeyCode()) {
170 case GUIKeyboardEvent::KEYCODE_ESCAPE: {
172 if (menuHeaderItemControllers.empty() == true) return;
173 if (menuHeaderItemControllerIdx == -1) return;
176 }
177 break;
178 case GUIKeyboardEvent::KEYCODE_LEFT: {
179 event->setProcessed(true);
180 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
182 }
183 }
184 break;
185 case GUIKeyboardEvent::KEYCODE_RIGHT: {
186 event->setProcessed(true);
187 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
188 selectNext();
189 }
190 }
191 break;
192 case GUIKeyboardEvent::KEYCODE_UP: {
193 event->setProcessed(true);
194 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
195 if (menuHeaderItemControllers.empty() == true) return;
200 } else {
202 }
203 }
204 }
205 break;
206 case GUIKeyboardEvent::KEYCODE_DOWN: {
207 event->setProcessed(true);
208 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
209 if (menuHeaderItemControllers.empty() == true) return;
214 } else {
216 }
217 }
218 }
219 break;
220 case GUIKeyboardEvent::KEYCODE_SPACE: {
222 if (menuHeaderItemControllers.empty() == true) return;
224 menuHeaderItemControllers[menuHeaderItemControllerIdx]->handleCurrentMenuItemKeyboardEvent(event);
225 }
226 break;
227 }
228}
229
231{
232}
233
235{
236 focus = true;
237}
238
240{
241 focus = false;
242}
243
245{
246 return false;
247}
248
250{
251 return value;
252}
253
255{
256}
257
259{
262}
263
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:66
void setFoccussedNode(GUIElementNode *newFoccussedNode)
Set focussed node.
Definition: GUI.cpp:359
void determineMenuHeaderItemControllers()
Determine menu header item controllers.
vector< GUIMenuHeaderItemController * > menuHeaderItemControllers
void initialize() override
Initialize controller after element has been created.
void handleKeyboardEvent(GUIKeyboardEvent *event) override
Handle keyboard event.
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.
void setDisabled(bool disabled) override
Set disabled.
void onSubTreeChange() override
On sub tree change.
GUI node controller base class.
GUI node base class.
Definition: GUINode.h:63
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
Console class.
Definition: Console.h:26
Mutable string class.
Definition: MutableString.h:16