TDME2 1.9.121
GUIKnobController.cpp
Go to the documentation of this file.
2
3#include <array>
4#include <string>
5
6#include <tdme/tdme.h>
14#include <tdme/gui/GUI.h>
15#include <tdme/math/Math.h>
20#include <tdme/utilities/Time.h>
21
22using std::array;
23using std::to_string;
24
32using tdme::gui::GUI;
39
41
42GUIKnobController::GUIKnobController(GUINode* node): GUIElementController(node)
43{
44}
45
47 return false;
48}
49
50void GUIKnobController::setDisabled(bool disabled) {
51
52}
53
55 knobNode = this->node->getScreenNode()->getNodeById(this->node->getId() + "_knob");
56 setValue(MutableString(required_dynamic_cast<GUIElementNode*>(node)->getValue()));
57
58 //
59 GUIElementController::initialize();
60}
61
63 GUIElementController::dispose();
64}
65
67 updateKnob();
68}
69
71 GUIElementController::handleMouseEvent(node, event);
72 if (node == this->node &&
73 event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED == true) {
74 this->node->getScreenNode()->getGUI()->setFoccussedNode(required_dynamic_cast<GUIElementNode*>(this->node));
75 event->setProcessed(true);
76 } else
77 if (node == this->node && node->isEventBelongingToNode(event) == true &&
78 event->getType() == GUIMouseEvent::MOUSEEVENT_PRESSED == true &&
79 event->getButton() == MOUSE_BUTTON_LEFT) {
80 mouseLastX = event->getX();
81 event->setProcessed(true);
82 } else
83 if (event->getType() == GUIMouseEvent::MOUSEEVENT_DRAGGED == true &&
84 event->getButton() == MOUSE_BUTTON_LEFT) {
85 valueFloat = Math::clamp(
86 static_cast<float>(valueFloat + ((event->getX() - mouseLastX) / 75.0f)) ,
87 0.0f,
88 1.0f
89 );
90 updateKnob();
91 node->getScreenNode()->delegateValueChanged(required_dynamic_cast<GUIElementNode*>(this->node));
92 mouseLastX = event->getX();
93 event->setProcessed(true);
94 }
95}
96
98 GUIElementController::handleKeyboardEvent(event);
99 switch (event->getKeyCode()) {
100 case GUIKeyboardEvent::KEYCODE_LEFT: {
101 event->setProcessed(true);
102 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
103 this->valueFloat = Math::clamp(valueFloat - 0.1f, 0.0f, 1.0f);
104 updateKnob();
105 node->getScreenNode()->delegateValueChanged(required_dynamic_cast< GUIElementNode* >(this->node));
106 }
107 }
108 break;
109 case GUIKeyboardEvent::KEYCODE_RIGHT: {
110 event->setProcessed(true);
111 if (event->getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED) {
112 this->valueFloat = Math::clamp(valueFloat + 0.1f, 0.0f, 1.0f);
113 updateKnob();
114 node->getScreenNode()->delegateValueChanged(required_dynamic_cast< GUIElementNode* >(this->node));
115 }
116 }
117 break;
118 }
119}
120
122 GUIElementController::tick();
123}
124
126}
127
129}
130
132 return true;
133}
134
136 return value.set(valueFloat, 4);
137}
138
140 this->value.set(value);
141 this->valueFloat = Math::clamp(Float::parse(this->value.getString()), 0.0f, 1.0f);
142 updateKnob();
143}
144
146 required_dynamic_cast<GUIImageNode*>(knobNode)->setTextureMatrix(Matrix2D3x3::rotateAroundTextureCenter((-valueFloat * (360.0f - 60.0f)) - 210.f));
147}
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:66
void setFoccussedNode(GUIElementNode *newFoccussedNode)
Set focussed node.
Definition: GUI.cpp:359
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.
void setDisabled(bool disabled) override
Set disabled.
const MutableString & getValue() override
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
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
void delegateValueChanged(GUIElementNode *node)
Delegate value changed.
Standard math functions.
Definition: Math.h:21
3x3 2D Matrix class
Definition: Matrix2D3x3.h:22
Console class.
Definition: Console.h:26
Float class.
Definition: Float.h:23
Mutable string class.
Definition: MutableString.h:16
MutableString & set(char c)
Set character.
const string & getString() const
Time utility class.
Definition: Time.h:21