TDME2  1.9.200
GUIProgressBarController.cpp
Go to the documentation of this file.
2 
3 #include <array>
4 #include <string>
5 
6 #include <tdme/tdme.h>
12 #include <tdme/gui/nodes/GUINode.h>
15 #include <tdme/gui/GUI.h>
16 #include <tdme/math/Math.h>
17 #include <tdme/utilities/Console.h>
18 #include <tdme/utilities/Float.h>
20 #include <tdme/utilities/Time.h>
21 
22 using std::array;
23 using std::to_string;
24 
32 using tdme::gui::GUI;
33 using tdme::math::Math;
38 
40 
41 GUIProgressBarController::GUIProgressBarController(GUINode* node): GUIElementController(node)
42 {
43 }
44 
46  return false;
47 }
48 
50 
51 }
52 
54  barNode = required_dynamic_cast<GUIImageNode*>(this->node->getScreenNode()->getNodeById(this->node->getId() + "_bar"));
55  textNode = required_dynamic_cast<GUITextNode*>(this->node->getScreenNode()->getNodeById(this->node->getId() + "_text"));
56  setValue(MutableString(required_dynamic_cast<GUIElementNode*>(node)->getValue()));
57  GUIElementController::initialize();
58 }
59 
61  GUIElementController::dispose();
62 }
63 
65  updateBar();
66 }
67 
69  GUIElementController::handleMouseEvent(node, event);
70 }
71 
73  GUIElementController::handleKeyboardEvent(event);
74 }
75 
77  GUIElementController::tick();
78 }
79 
81 }
82 
84 }
85 
87  return true;
88 }
89 
91  return value.set(valueFloat, 4);
92 }
93 
95  this->value.set(value);
96  valueFloat = Math::clamp(Float::parse(this->value.getString()), 0.0f, 1.0f);
97  textNode->setText((MutableString((int)(valueFloat * 100.0f))).append(" %"));
98  updateBar();
99 }
100 
102  auto barParentNode = barNode->getParentNode();
103  auto barWidth = barParentNode->getComputedConstraints().width - barParentNode->getPadding().left - barParentNode->getPadding().right;
104  barNode->getClipping().right = barWidth - (int)((float)barWidth * valueFloat);
105 }
GUI module class.
Definition: GUI.h:64
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 node base class.
Definition: GUINode.h:64
GUIParentNode * getParentNode()
Definition: GUINode.h:332
GUIScreenNode * getScreenNode()
Definition: GUINode.h:325
GUINode_ComputedConstraints & getComputedConstraints()
Definition: GUINode.h:412
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.
void setText(const MutableString &text)
Set text.
Definition: GUITextNode.cpp:81
Standard math functions.
Definition: Math.h:19
Console class.
Definition: Console.h:29
Float class.
Definition: Float.h:27
Mutable utf8 aware string class.
Definition: MutableString.h:23
const string & getString() const
MutableString & set(char c)
Set character.
Time utility class.
Definition: Time.h:20