TDME2 1.9.121
GUIRadioButtonController.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
11#include <tdme/gui/GUI.h>
13
22using tdme::gui::GUI;
24
25string GUIRadioButtonController::CONDITION_SELECTED = "selected";
26string GUIRadioButtonController::CONDITION_UNSELECTED = "unselected";
27string GUIRadioButtonController::CONDITION_DISABLED = "disabled";
28string GUIRadioButtonController::CONDITION_ENABLED = "enabled";
29
30map<string, vector<GUIElementNode*>>* GUIRadioButtonController::radioButtonGroupNodesByName = new map<string, vector<GUIElementNode*>>();
31
32GUIRadioButtonController::GUIRadioButtonController(GUINode* node)
34{
35 this->selected = required_dynamic_cast<GUIElementNode*>(node)->isSelected();
36 this->disabled = required_dynamic_cast<GUIElementNode*>(node)->isDisabled();
37 (*radioButtonGroupNodesByName)[
39 "_radiobuttongroup_" +
40 required_dynamic_cast<GUIElementNode*>(node)->getName()
41 ].push_back(required_dynamic_cast<GUIElementNode*>(node));
42}
43
45{
46 return selected;
47}
48
50{
51 auto radioButtonGroupNodesIt = radioButtonGroupNodesByName->find(
52 this->node->getScreenNode()->getId() +
53 "_radiobuttongroup_" +
54 required_dynamic_cast<GUIElementNode*>(this->node)->getName()
55 );
56 if (radioButtonGroupNodesIt != radioButtonGroupNodesByName->end()) {
57 for (auto i = 0; i < radioButtonGroupNodesIt->second.size(); i++) {
58 auto radioButtonNode = required_dynamic_cast<GUIElementNode*>(radioButtonGroupNodesIt->second[i]);
59 auto& nodeConditions = radioButtonNode->getActiveConditions();
60 auto nodeController = required_dynamic_cast<GUIRadioButtonController*>(radioButtonNode->getController());
61 nodeConditions.remove(nodeController->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
62 nodeController->selected = false;
63 nodeConditions.add(nodeController->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
64 }
65 }
66 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
67 nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
68 this->selected = true;
69 nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
70}
71
73{
74 return disabled;
75}
76
78{
79 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
80 nodeConditions.remove(this->disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
81 this->disabled = disabled;
82 nodeConditions.add(this->disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
83}
84
86{
87 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
88 nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
89
90 //
91 GUIElementController::initialize();
92}
93
95{
96 GUIElementController::dispose();
98 this->node->getScreenNode()->getId() +
99 "_radiobuttongroup_" +
100 required_dynamic_cast<GUIElementNode*>(this->node)->getName()
101 );
102}
103
105{
106}
107
109{
110 GUIElementController::handleMouseEvent(node, event);
111 if (disabled == false && node == this->node && node->isEventBelongingToNode(event) && event->getButton() == MOUSE_BUTTON_LEFT) {
112 event->setProcessed(true);
113 if (event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
114 select();
115 node->getScreenNode()->getGUI()->setFoccussedNode(required_dynamic_cast<GUIElementNode*>(node));
116 node->getScreenNode()->delegateValueChanged(required_dynamic_cast<GUIElementNode*>(node));
117 }
118 }
119}
120
122{
123 GUIElementController::handleKeyboardEvent(event);
124 if (disabled == false) {
125 switch (event->getKeyCode()) {
126 case GUIKeyboardEvent::KEYCODE_SPACE: {
127 event->setProcessed(true);
128 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
129 select();
130 node->getScreenNode()->delegateValueChanged(required_dynamic_cast<GUIElementNode*>(node));
131 }
132 }
133 break;
134 default: {
135 break;
136 }
137 }
138
139 }
140}
141
143{
144 GUIElementController::tick();
145}
146
148{
149}
150
152{
153}
154
156{
157 return true;
158}
159
161{
162 value.reset();
163 if (selected == true) {
164 value.append(required_dynamic_cast<GUIElementNode*>(node)->getValue());
165 }
166 return value;
167}
168
170{
171 if (value.equals(required_dynamic_cast<GUIElementNode*>(node)->getValue()) == true) {
172 select();
173 }
174}
175
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:66
void setFoccussedNode(GUIElementNode *newFoccussedNode)
Set focussed node.
Definition: GUI.cpp:359
static STATIC_DLL_IMPEXT map< string, vector< GUIElementNode * > > * radioButtonGroupNodesByName
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.
static STATIC_DLL_IMPEXT string CONDITION_UNSELECTED
void setDisabled(bool disabled) override
Set disabled.
GUI element node conditions.
GUI node base class.
Definition: GUINode.h:63
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
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:57
void delegateValueChanged(GUIElementNode *node)
Delegate value changed.
Mutable string class.
Definition: MutableString.h:16
MutableString & append(char c)
Append character.
MutableString & reset()
Reset.
bool equals(const string &s2) const
Equals.