TDME2  1.9.200
GUIInputController.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
11 #include <tdme/gui/nodes/GUINode.h>
14 #include <tdme/gui/GUI.h>
16 
17 using std::string;
18 
28 using tdme::gui::GUI;
30 
31 string GUIInputController::CONDITION_DISABLED = "disabled";
32 string GUIInputController::CONDITION_ENABLED = "enabled";
33 
34 GUIInputController::GUIInputController(GUINode* node)
35  : GUIElementController(node)
36 {
37  this->disabled = required_dynamic_cast<GUIElementNode*>(node)->isDisabled();
38 }
39 
41  auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
42  if (inputNode->getText().getString().empty() == true) {
43  if (nodeConditions.has("hint") == false) nodeConditions.add("hint");
44  } else {
45  if (nodeConditions.has("hint") == true) nodeConditions.remove("hint");
46  }
47 }
48 
50 {
51  return disabled;
52 }
53 
55 {
56  auto& nodeConditions = required_dynamic_cast<GUIElementNode*>(node)->getActiveConditions();
57  nodeConditions.remove(this->disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
58  this->disabled = disabled;
59  nodeConditions.add(this->disabled == true?CONDITION_DISABLED:CONDITION_ENABLED);
60 }
61 
63 {
64  inputNode = required_dynamic_cast<GUIInputInternalNode*>(node->getScreenNode()->getNodeById(node->getId() + "_text-input"));
65 
66  //
67  GUIElementController::initialize();
68 
69  //
70  onChange();
71 }
72 
74 {
75  GUIElementController::dispose();
76 }
77 
79 {
80 }
81 
83 {
84  GUIElementController::handleMouseEvent(node, event);
85  if (disabled == false && node == this->node && node->isEventBelongingToNode(event) && event->getButton() == MOUSE_BUTTON_LEFT) {
86  node->getScreenNode()->getGUI()->setFoccussedNode(required_dynamic_cast<GUIElementNode*>(node));
87  event->setProcessed(true);
88  }
89 }
90 
92 {
93 }
94 
96 {
97  GUIElementController::tick();
98 }
99 
101 {
102  inputNode = required_dynamic_cast<GUIInputInternalNode*>(node->getScreenNode()->getNodeById(node->getId() + "_text-input"));
104 }
105 
107 {
108  inputNode = required_dynamic_cast<GUIInputInternalNode*>(node->getScreenNode()->getNodeById(node->getId() + "_text-input"));
110 }
111 
113 {
114  return true;
115 }
116 
118 {
119  return inputNode->getText();
120 }
121 
123 {
125  auto inputInternalController = required_dynamic_cast<GUIInputInternalController*>(inputNode->getController());
126  inputInternalController->formatText();
127  inputInternalController->onTextUpdate();
128  onChange();
129 }
130 
132 {
133 }
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:64
void setFoccussedNode(GUIElementNode *newFoccussedNode)
Set focussed node.
Definition: GUI.cpp:267
void onFocusGained() override
On focus gained.
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 onFocusLost() override
On focus lost.
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.
const MutableString & getValue() override
void onSubTreeChange() override
On sub tree change.
GUI element node conditions.
virtual void onFocusLost()=0
On focus lost.
virtual void onFocusGained()=0
On focus gained.
GUI node base class.
Definition: GUINode.h:64
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &nodeCoordinate)
Is event belonging to node.
Definition: GUINode.h:604
GUINodeController * getController()
Definition: GUINode.h:661
GUIScreenNode * getScreenNode()
Definition: GUINode.h:325
const string & getId()
Definition: GUINode.h:339
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
Mutable utf8 aware string class.
Definition: MutableString.h:23
const string & getString() const
MutableString & set(char c)
Set character.