TDME2 1.9.121
GUIDropDownOptionController.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
15#include <tdme/gui/GUI.h>
18
19using std::string;
20
22
32using tdme::gui::GUI;
35
36string GUIDropDownOptionController::CONDITION_SELECTED = "selected";
37string GUIDropDownOptionController::CONDITION_UNSELECTED = "unselected";
38string GUIDropDownOptionController::CONDITION_HIDDEN = "hidden";
39
40GUIDropDownOptionController::GUIDropDownOptionController(GUINode* node)
42{
43 this->initialPostLayout = true;
44 this->selected = required_dynamic_cast<GUIElementNode*>(node)->isSelected();
45 this->hidden = false;
46}
47
49{
50 GUIElementController::setDisabled(disabled);
51 unselect();
52}
53
55{
56 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
57 nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
58 this->selected = true;
59 nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
60 auto dropDownOptionTextNode = required_dynamic_cast<GUITextNode*>(node->getScreenNode()->getNodeById(node->getId() + "_unselected"));
61 auto dropDownTextNodeEnabled = required_dynamic_cast<GUITextNode*>(node->getScreenNode()->getNodeById(dropDownNode->getId() + "_text_enabled"));
62 dropDownTextNodeEnabled->setText(dropDownOptionTextNode->getText());
63 auto dropDownTextNodeDisabled = required_dynamic_cast<GUITextNode*>(node->getScreenNode()->getNodeById(dropDownNode->getId() + "_text_disabled"));
64 dropDownTextNodeDisabled->setText(dropDownOptionTextNode->getText());
65}
66
68{
69 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
70 nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
71 this->selected = false;
72 nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
73}
74
75bool GUIDropDownOptionController::search(const string& value) {
76 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
77 if (value.empty() == true) {
78 nodeConditions.remove(CONDITION_HIDDEN);
79 hidden = false;
80 return true;
81 }
82 auto dropDownOptionTextNode = required_dynamic_cast<GUITextNode*>(node->getScreenNode()->getNodeById(node->getId() + "_unselected"));
83 auto nodeTextLowerCase = StringTools::toLowerCase(dropDownOptionTextNode->getText().getString());
84 if (nodeTextLowerCase.find(value) == string::npos) {
85 nodeConditions.add(CONDITION_HIDDEN);
86 hidden = true;
87 return false;
88 } else {
89 nodeConditions.remove(CONDITION_HIDDEN);
90 hidden = false;
91 return true;
92 }
93}
94
96{
97 //
99 while (true == true) {
100 if (dynamic_cast<GUIDropDownController*>(dropDownNode->getController()) != nullptr) {
101 break;
102 }
104 }
105 dropDownContainerNode = required_dynamic_cast<GUIParentNode*>(node->getScreenNode()->getInnerNodeById(dropDownNode->getId()));
106 if (selected == true) {
107 required_dynamic_cast<GUIDropDownController*>(dropDownNode->getController())->select(required_dynamic_cast<GUIElementNode*>(this->node));
108 } else {
109 unselect();
110 }
111
112 //
113 GUIElementController::initialize();
114}
115
117{
118 if (initialPostLayout != true) return;
119 if (selected == true) {
122 }
123 initialPostLayout = false;
124}
125
127{
128 GUIElementController::dispose();
129}
130
132{
133 if (isDisabled() == true) return;
134 GUIElementController::handleMouseEvent(node, event);
135 if (node == this->node && node->isEventBelongingToNode(event) && event->getButton() == MOUSE_BUTTON_LEFT) {
136 event->setProcessed(true);
137 if (event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
138 required_dynamic_cast<GUIDropDownController*>(dropDownNode->getController())->select(required_dynamic_cast<GUIElementNode*>(this->node));
139 required_dynamic_cast<GUIDropDownController*>(dropDownNode->getController())->toggleOpenState();
140 node->getScreenNode()->delegateValueChanged(required_dynamic_cast<GUIElementNode*>(dropDownNode));
141 }
142 }
143}
144
146{
147 GUIElementController::handleKeyboardEvent(event);
148}
149
151{
152 GUIElementController::tick();
153}
154
156{
157}
158
160{
161}
162
164{
165 return false;
166}
167
169{
170 return value;
171}
172
174{
175}
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:66
bool search(const string &value)
Search by string.
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.
GUI element node conditions.
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
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.
void delegateValueChanged(GUIElementNode *node)
Delegate value changed.
GUINode * getInnerNodeById(const string &nodeId)
Get inner GUI node by id.
Mutable string class.
Definition: MutableString.h:16
String tools class.
Definition: StringTools.h:20