TDME2  1.9.200
GUIGridItemController.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
10 #include <tdme/gui/nodes/GUINode.h>
14 #include <tdme/gui/GUI.h>
15 
25 using tdme::gui::GUI;
26 
27 string GUIGridItemController::CONDITION_SELECTED = "selected";
28 string GUIGridItemController::CONDITION_UNSELECTED = "unselected";
29 string GUIGridItemController::CONDITION_FOCUSSED = "focussed";
30 string GUIGridItemController::CONDITION_UNFOCUSSED = "unfocussed";
31 string GUIGridItemController::CONDITION_DISABLED = "disabled";
32 string GUIGridItemController::CONDITION_ENABLED = "enabled";
33 
34 GUIGridItemController::GUIGridItemController(GUINode* node)
35  : GUIElementController(node)
36 {
37  this->initialPostLayout = true;
38  this->selected = required_dynamic_cast<GUIElementNode*>(node)->isSelected();
39  this->focussed = false;
40 }
41 
43 {
44  unselect();
45  GUIElementController::setDisabled(disabled);
46 }
47 
49 {
50  auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
51  nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
52  this->selected = true;
53  nodeConditions.add(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
54  auto disabled = required_dynamic_cast<GUIGridController*>(gridNode->getController())->isDisabled();
55  nodeConditions.remove(CONDITION_DISABLED);
56  nodeConditions.remove(CONDITION_ENABLED);
57  nodeConditions.add(disabled == true ? CONDITION_DISABLED : CONDITION_ENABLED);
58 }
59 
61 {
62  auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
63  nodeConditions.remove(this->selected == true?CONDITION_SELECTED:CONDITION_UNSELECTED);
64  this->selected = false;
65  nodeConditions.add(this->selected == true ? CONDITION_SELECTED:CONDITION_UNSELECTED);
66  auto disabled = required_dynamic_cast<GUIGridController*>(gridNode->getController())->isDisabled();
67  nodeConditions.remove(CONDITION_DISABLED);
68  nodeConditions.remove(CONDITION_ENABLED);
69  nodeConditions.add(disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
70 }
71 
73 {
74  if (selected == true) {
75  unselect();
76  } else {
77  select();
78  }
79 }
80 
82 {
83  auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
84  nodeConditions.remove(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
85  this->focussed = true;
86  nodeConditions.add(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
87 }
88 
90 {
91  auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
92  nodeConditions.remove(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
93  this->focussed = false;
94  nodeConditions.add(this->focussed == true?CONDITION_FOCUSSED:CONDITION_UNFOCUSSED);
95 }
96 
98 {
100  while (true == true) {
101  if (dynamic_cast<GUIGridController*>(gridNode->getController()) != nullptr) {
102  break;
103  }
105  }
106  if (selected == true) {
107  select();
108  } else {
109  unselect();
110  }
111 
112  //
113  GUIElementController::initialize();
114 }
115 
117 {
118  GUIElementController::dispose();
119 }
120 
122 {
123  if (initialPostLayout != true) return;
124  if (selected == true) {
127  }
128  initialPostLayout = false;
129 }
130 
132 {
133  GUIElementController::handleMouseEvent(node, event);
134  auto disabled = required_dynamic_cast<GUIGridController*>(gridNode->getController())->isDisabled();
135  auto multipleSelection = required_dynamic_cast<GUIGridController*>(gridNode->getController())->isMultipleSelection();
136  if (disabled == false && node == this->node && node->isEventBelongingToNode(event)) {
137  event->setProcessed(true);
138  if (event->getType() == GUIMouseEvent::MOUSEEVENT_PRESSED) {
139  auto gridController = required_dynamic_cast<GUIGridController*>(gridNode->getController());
140  auto gridItemElementNode = required_dynamic_cast<GUIElementNode*>(node);
141  gridController->unfocus();
142  if (multipleSelection == true && gridController->isKeyControlDown() == true) {
143  gridController->toggle(gridItemElementNode);
144  gridController->focus(gridItemElementNode);
145  } else {
146  gridController->unselect();
147  gridController->select(gridItemElementNode);
148  gridController->focus(gridItemElementNode);
149  }
150  node->getScreenNode()->getGUI()->setFoccussedNode(required_dynamic_cast<GUIElementNode*>(gridNode));
153  node->getScreenNode()->forwardChange(required_dynamic_cast<GUIElementNode*>(gridNode));
154  if (event->getButton() == MOUSE_BUTTON_RIGHT) {
155  node->getScreenNode()->forwardContextMenuRequest(required_dynamic_cast<GUIElementNode*>(gridNode), event->getXUnscaled(), event->getYUnscaled());
156  }
157  }
158  }
159 }
160 
162 {
163  GUIElementController::handleKeyboardEvent(event);
164 }
165 
167 {
168 }
169 
171 {
172 }
173 
175 {
176  return false;
177 }
178 
180 {
181  return value;
182 }
183 
185 {
186 }
#define MOUSE_BUTTON_RIGHT
GUI module class.
Definition: GUI.h:64
void setFoccussedNode(GUIElementNode *newFoccussedNode)
Set focussed node.
Definition: GUI.cpp:267
void dispose() override
Dispose controller.
void postLayout() override
Post layout event.
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.
static STATIC_DLL_IMPEXT string CONDITION_DISABLED
static STATIC_DLL_IMPEXT string CONDITION_ENABLED
static STATIC_DLL_IMPEXT string CONDITION_UNSELECTED
void setDisabled(bool disabled) override
Set disabled.
static STATIC_DLL_IMPEXT string CONDITION_FOCUSSED
static STATIC_DLL_IMPEXT string CONDITION_SELECTED
static STATIC_DLL_IMPEXT string CONDITION_UNFOCUSSED
GUIMouseEventType getType() const
Definition: GUIMouseEvent.h:78
GUI element node conditions.
GUI node controller base class.
GUI node base class.
Definition: GUINode.h:64
void scrollToNodeY(GUIParentNode *toNode=nullptr)
Scroll to node Y.
Definition: GUINode.cpp:1100
void scrollToNodeX(GUIParentNode *toNode=nullptr)
Scroll to node X.
Definition: GUINode.cpp:1096
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &nodeCoordinate)
Is event belonging to node.
Definition: GUINode.h:604
GUINodeController * getController()
Definition: GUINode.h:661
GUIParentNode * getParentControllerNode()
Definition: GUINode.cpp:1011
GUIScreenNode * getScreenNode()
Definition: GUINode.h:325
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
void forwardChange(GUIElementNode *node)
Forward change event.
void forwardContextMenuRequest(GUIElementNode *node, int mouseX, int mouseY)
Forward context menu request event.
Mutable utf8 aware string class.
Definition: MutableString.h:23