TDME2 1.9.121
GUISelectorHController.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
17#include <tdme/gui/GUI.h>
20
21using std::string;
22using std::to_string;
23
37using tdme::gui::GUI;
40
41string GUISelectorHController::CONDITION_DISABLED = "disabled";
42string GUISelectorHController::CONDITION_ENABLED = "enabled";
43
44GUISelectorHController::GUISelectorHController(GUINode* node)
46{
47 this->disabled = required_dynamic_cast<GUIElementNode*>(node)->isDisabled();
48}
49
51{
52 return disabled;
53}
54
56{
57 auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
58 nodeConditions.remove(this->disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
59 this->disabled = disabled;
60 nodeConditions.add(this->disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
61}
62
64{
65 //
66 GUIElementController::initialize();
67
68 //
70
71 //
72 innerNode = required_dynamic_cast<GUIParentNode*>(node->getScreenNode()->getInnerNodeById(node->getId()));
73
74 //
75 class GUISelectorHControllerActionListener: public virtual GUIActionListener
76 {
77 public:
78 void onActionPerformed(GUIActionListenerType type, GUIElementNode* node) override {
79 if (type != GUIActionListenerType::PERFORMED) return;
80 if (node == leftArrowNode) {
81 selectorHController->selectPrevious();
82 } else
83 if (node == rightArrowNode) {
84 selectorHController->selectNext();
85 }
86 }
87
88 /**
89 * Public constructor
90 * @param selectorHController selector horizontal Controller
91 * @param leftArrowNode left arrow node
92 * @param rightArrowNode right arrow node
93 */
94 GUISelectorHControllerActionListener(GUISelectorHController* selectorHController, GUIElementNode* leftArrowNode, GUIElementNode* rightArrowNode)
95 : selectorHController(selectorHController)
96 , leftArrowNode(leftArrowNode)
97 , rightArrowNode(rightArrowNode) {
98 }
99
100 private:
101 GUISelectorHController* selectorHController;
102 GUIElementNode* leftArrowNode;
103 GUIElementNode* rightArrowNode;
104 };
105
106 //
107 auto const leftArrowNode = dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(node->getId() + "_left"));
108 auto const rightArrowNode = dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(node->getId() + "_right"));
109 node->getScreenNode()->addActionListener(actionListener = new GUISelectorHControllerActionListener(this, leftArrowNode, rightArrowNode));
110}
111
113{
114 //
115 GUIElementController::dispose();
116
117 //
118 if (actionListener != nullptr) {
120 delete actionListener;
121 actionListener = nullptr;
122 }
123}
124
126{
127}
128
130{
131 if (selectedHOptionControllerIdx == -1) return;
133}
134
136 unselect();
138 if (selectedHOptionControllerIdx == -1) return;
140}
141
142void GUISelectorHController::select(GUIElementNode* selectedSelectorHOptionElementNode) {
143 unselect();
144 auto selectedSelectorHOptionElementController = selectedSelectorHOptionElementNode->getController();
145 auto i = 0;
146 for (auto selectorHOptionController: selectorHOptionControllers) {
147 if (selectorHOptionController == selectedSelectorHOptionElementController) {
148 select(i);
149 break;
150 }
151 i++;
152 }
153}
154
156{
157 vector<GUINode*> childControllerNodes;
159 required_dynamic_cast<GUIParentNode*>(node)->getChildControllerNodes(childControllerNodes);
160 for (auto i = 0; i < childControllerNodes.size(); i++) {
161 auto childControllerNode = childControllerNodes[i];
162 auto childController = dynamic_cast<GUISelectorHOptionController*>(childControllerNode->getController());
163 if (childController != nullptr) selectorHOptionControllers.push_back(childController);
164 }
165}
166
168{
169 unselect();
170 if (selectorHOptionControllers.size() == 0)
171 return;
172
173 auto disabledCount = 0;
174 while (disabledCount < selectorHOptionControllers.size()) {
177 selectorHOptionControllers[selectedHOptionControllerIdx]->isHidden() == false) break;
178 disabledCount++;
179 }
180 if (disabledCount == selectorHOptionControllers.size()) {
182 return;
183 }
184
186}
187
189{
190 unselect();
191 if (selectorHOptionControllers.size() == 0)
192 return;
193
195
196 auto disabledCount = 0;
197 while (disabledCount < selectorHOptionControllers.size()) {
202 selectorHOptionControllers[selectedHOptionControllerIdx]->isHidden() == false) break;
203 disabledCount++;
204 }
205 if (disabledCount == selectorHOptionControllers.size()) {
207 return;
208 }
209
211}
212
214{
215 GUIElementController::handleMouseEvent(node, event);
216 if (disabled == true) return;
217 if (event->getButton() == MOUSE_BUTTON_LEFT) {
218 if (node == innerNode && innerNode->isEventBelongingToNode(event) == true) {
219 if (event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
220 auto elementNode = required_dynamic_cast<GUIElementNode*>(this->node);
221 node->getScreenNode()->getGUI()->setFoccussedNode(elementNode);
222 selectNext();
223 }
224 }
225 }
226}
227
229{
230 GUIElementController::handleKeyboardEvent(event);
231 if (disabled == true) return;
232 switch (event->getKeyCode()) {
233 case GUIKeyboardEvent::KEYCODE_LEFT: {
234 event->setProcessed(true);
235 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
237 }
238 }
239 break;
240 case GUIKeyboardEvent::KEYCODE_RIGHT: {
241 event->setProcessed(true);
242 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
243 selectNext();
244 }
245 }
246 break;
247 }
248}
249
251{
252 GUIElementController::tick();
253}
254
256{
257}
258
260{
261}
262
264{
265 return true;
266}
267
269{
270 value.reset();
272 return value;
273}
274
276{
277 unselect();
278 auto i = 0;
279 for (auto selectorHOptionController: selectorHOptionControllers) {
280 auto selectorHOptionNode = required_dynamic_cast<GUIElementNode*>(selectorHOptionController->getNode());
281 if (value.equals(selectorHOptionNode->getValue())) {
282 select(i);
283 break;
284 }
285 i++;
286 }
287}
288
292 auto i = 0;
293 for (auto selectorHOptionController: selectorHOptionControllers) {
294 auto selectorHOptionNode = required_dynamic_cast<GUIElementNode*>(selectorHOptionController->getNode());
295 selectorHOptionController->unselect();
296 if (selectorHOptionNode->isSelected() == true) {
298 break;
299 }
300 i++;
301 }
304}
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:66
void setFoccussedNode(GUIElementNode *newFoccussedNode)
Set focussed node.
Definition: GUI.cpp:359
GUI selector horizontal controller.
vector< GUISelectorHOptionController * > selectorHOptionControllers
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_DISABLED
static STATIC_DLL_IMPEXT string CONDITION_ENABLED
void setDisabled(bool disabled) override
Set disabled.
void onSubTreeChange() override
On sub tree change.
void determineSelectorHOptionControllers()
Determine drop down option controllers.
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
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 removeActionListener(GUIActionListener *listener)
Remove action listener.
void addActionListener(GUIActionListener *listener)
Add action listener.
GUINode * getInnerNodeById(const string &nodeId)
Get inner GUI node by id.
Mutable string class.
Definition: MutableString.h:16
MutableString & append(char c)
Append character.
MutableString & reset()
Reset.
bool equals(const string &s2) const
Equals.
String tools class.
Definition: StringTools.h:20
GUI action listener interface.