TDME2 1.9.121
GUISelectBoxOptionController.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
15#include <tdme/gui/GUI.h>
16
27using tdme::gui::GUI;
28
29string GUISelectBoxOptionController::CONDITION_SELECTED = "selected";
30string GUISelectBoxOptionController::CONDITION_UNSELECTED = "unselected";
31string GUISelectBoxOptionController::CONDITION_FOCUSSED = "focussed";
32string GUISelectBoxOptionController::CONDITION_UNFOCUSSED = "unfocussed";
33string GUISelectBoxOptionController::CONDITION_DISABLED = "disabled";
34string GUISelectBoxOptionController::CONDITION_ENABLED = "enabled";
35string GUISelectBoxOptionController::CONDITION_CHILD = "child";
36
37GUISelectBoxOptionController::GUISelectBoxOptionController(GUINode* node)
39{
40 this->initialPostLayout = true;
41 this->selected = required_dynamic_cast<GUIElementNode*>(node)->isSelected();
42 this->focussed = false;
43}
44
46{
47 unselect();
48 GUIElementController::setDisabled(disabled);
49}
50
52{
53 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
54 nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
55 this->selected = true;
56 nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
57 auto disabled = required_dynamic_cast<GUISelectBoxController*>(selectBoxNode->getController())->isDisabled();
58 nodeConditions.remove(CONDITION_DISABLED);
59 nodeConditions.remove(CONDITION_ENABLED);
60 nodeConditions.add(disabled == true ? CONDITION_DISABLED : CONDITION_ENABLED);
61}
62
64{
65 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
66 nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
67 this->selected = false;
68 nodeConditions.add(this->selected == true ? CONDITION_SELECTED:CONDITION_UNSELECTED);
69 auto disabled = required_dynamic_cast<GUISelectBoxController*>(selectBoxNode->getController())->isDisabled();
70 nodeConditions.remove(CONDITION_DISABLED);
71 nodeConditions.remove(CONDITION_ENABLED);
72 nodeConditions.add(disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
73}
74
76{
77 if (selected == true) {
78 unselect();
79 } else {
80 select();
81 }
82}
83
85{
86 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
87 nodeConditions.remove(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
88 this->focussed = true;
89 nodeConditions.add(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
90}
91
93{
94 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
95 nodeConditions.remove(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
96 this->focussed = false;
97 nodeConditions.add(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
98}
99
101 if (dynamic_cast<GUIElementNode*>(node)->getParentElementNodeId().empty() == false) {
102 GUIElementNode* _parentElementNode = dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(dynamic_cast<GUIElementNode*>(node)->getParentElementNodeId()));
103 while (_parentElementNode != nullptr) {
104 auto selectBoxParentOptionController = dynamic_cast<GUISelectBoxParentOptionController*>(_parentElementNode->getController());
105 if (selectBoxParentOptionController != nullptr) {
106 if (selectBoxParentOptionController->isExpanded() == false) return false;
107 } else {
108 break;
109 }
110 _parentElementNode =
111 _parentElementNode->getParentElementNodeId().empty() == false?
112 dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(_parentElementNode->getParentElementNodeId())):
113 nullptr;
114 }
115 }
116 return true;
117}
118
120 if (dynamic_cast<GUIElementNode*>(node)->getParentElementNodeId().empty() == false) {
121 GUIElementNode* _parentElementNode = dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(dynamic_cast<GUIElementNode*>(node)->getParentElementNodeId()));
122 while (_parentElementNode != nullptr) {
123 auto selectBoxParentOptionController = dynamic_cast<GUISelectBoxParentOptionController*>(_parentElementNode->getController());
124 if (selectBoxParentOptionController != nullptr) {
125 if (selectBoxParentOptionController->isExpanded() == false) selectBoxParentOptionController->toggleExpandState();
126 } else {
127 break;
128 }
129 _parentElementNode =
130 _parentElementNode->getParentElementNodeId().empty() == false?
131 dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(_parentElementNode->getParentElementNodeId())):
132 nullptr;
133 }
134 }
135}
136
138{
140 while (true == true) {
141 if (dynamic_cast<GUISelectBoxController*>(selectBoxNode->getController()) != nullptr) {
142 break;
143 }
145 }
146 if (selected == true) {
147 select();
148 } else {
149 unselect();
150 }
151
152 {
153 auto childIdx = 0;
154 if (dynamic_cast<GUIElementNode*>(node)->getParentElementNodeId().empty() == false) {
155 GUIElementNode* _parentElementNode = dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(dynamic_cast<GUIElementNode*>(node)->getParentElementNodeId()));
156 while (_parentElementNode != nullptr) {
157 if (dynamic_cast<GUISelectBoxParentOptionController*>(_parentElementNode->getController()) != nullptr) {
158 childIdx++;
159 } else {
160 break;
161 }
162 _parentElementNode =
163 _parentElementNode->getParentElementNodeId().empty() == false?
164 dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(_parentElementNode->getParentElementNodeId())):
165 nullptr;
166 }
167 if (childIdx > 0) {
168 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
169 nodeConditions.add(CONDITION_CHILD);
170 }
171 }
172 }
173
174 //
175 GUIElementController::initialize();
176}
177
179{
180 GUIElementController::dispose();
181}
182
184{
185 if (initialPostLayout != true) return;
186 if (selected == true) {
189 }
190 initialPostLayout = false;
191}
192
194{
195 GUIElementController::handleMouseEvent(node, event);
196 auto disabled = required_dynamic_cast<GUISelectBoxController*>(selectBoxNode->getController())->isDisabled();
197 auto multipleSelection = required_dynamic_cast<GUISelectBoxController*>(selectBoxNode->getController())->isMultipleSelection();
198 if (disabled == false && node == this->node && node->isEventBelongingToNode(event)) {
199 event->setProcessed(true);
200 if (event->getType() == GUIMouseEvent::MOUSEEVENT_PRESSED) {
201 auto selectBoxController = required_dynamic_cast<GUISelectBoxController*>(selectBoxNode->getController());
202 auto optionElementNode = required_dynamic_cast<GUIElementNode*>(node);
203 selectBoxController->unfocus();
204 if (multipleSelection == true && selectBoxController->isKeyControlDown() == true) {
205 selectBoxController->toggle(optionElementNode);
206 selectBoxController->focus(optionElementNode);
207 } else {
208 selectBoxController->unselect();
209 selectBoxController->select(optionElementNode);
210 selectBoxController->focus(optionElementNode);
211 }
212 node->getScreenNode()->getGUI()->setFoccussedNode(required_dynamic_cast<GUIElementNode*>(selectBoxNode));
215 node->getScreenNode()->delegateValueChanged(required_dynamic_cast<GUIElementNode*>(selectBoxNode));
216 if (event->getButton() == MOUSE_BUTTON_RIGHT) {
217 node->getScreenNode()->delegateContextMenuRequest(required_dynamic_cast<GUIElementNode*>(selectBoxNode), event->getXUnscaled(), event->getYUnscaled());
218 }
219 }
220 }
221}
222
224{
225 GUIElementController::handleKeyboardEvent(event);
226}
227
229{
230}
231
233{
234}
235
237{
238 return false;
239}
240
242{
243 return value;
244}
245
247{
248}
#define MOUSE_BUTTON_RIGHT
GUI module class.
Definition: GUI.h:66
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 setValue(const MutableString &value) override
Set value.
void handleMouseEvent(GUINode *node, GUIMouseEvent *event) override
Handle mouse event.
void setDisabled(bool disabled) override
Set disabled.
GUINodeConditions & getActiveConditions()
GUI element node conditions.
bool add(const string &condition)
Add a condition.
GUI node controller base class.
GUI node base class.
Definition: GUINode.h:63
void scrollToNodeY(GUIParentNode *toNode=nullptr)
Scroll to node Y.
Definition: GUINode.cpp:1129
void scrollToNodeX(GUIParentNode *toNode=nullptr)
Scroll to node X.
Definition: GUINode.cpp:1125
GUIParentNode * getParentControllerNode()
Definition: GUINode.cpp:1053
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.
void delegateValueChanged(GUIElementNode *node)
Delegate value changed.
void delegateContextMenuRequest(GUIElementNode *node, int mouseX, int mouseY)
Delegate mouse over event.
Mutable string class.
Definition: MutableString.h:16