TDME2 1.9.121
GUIHorizontalScrollbarInternalController.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
11#include <tdme/gui/GUI.h>
12
14
16using tdme::gui::nodes::GUIHorizontalScrollbarInternalController_State;
23using tdme::gui::GUI;
24
25GUIHorizontalScrollbarInternalController::GUIHorizontalScrollbarInternalController(GUINode* node)
26 : GUINodeController(node)
27{
29 mouseXOffset = -1;
30 contentNode = required_dynamic_cast<GUILayoutNode*>(node->getScreenNode()->getNodeById(node->getParentControllerNode()->id + "_inner"));
31 contentWidth = 0;
32}
33
35{
36 return false;
37}
38
40{
41}
42
44{
45}
46
48{
49}
50
52{
54}
55
57{
58 return state;
59}
60
62{
63 float elementWidth = contentNode->computedConstraints.width;
64 auto barWidthRelative = (elementWidth / contentWidth);
65 if (barWidthRelative > 1.0f) barWidthRelative = 1.0f;
66 float barWidth = (node->computedConstraints.width - node->border.left - node->border.right) * barWidthRelative;
67 if (barWidth < 20.0f) barWidth = 20.0f;
68 return barWidth;
69}
70
72{
73 float elementWidth = contentNode->computedConstraints.width;
74 auto scrollableWidth = contentWidth - elementWidth;
75 auto childrenRenderOffsetX = contentNode->getChildrenRenderOffsetX();
76 if (scrollableWidth > 0.0f) {
77 return node->computedConstraints.left + node->computedConstraints.alignmentLeft + node->border.left+ (childrenRenderOffsetX * ((node->computedConstraints.width - getBarWidth()) / scrollableWidth));
78 } else {
80 }
81}
82
84{
85 float elementWidth = contentNode->computedConstraints.width;
86 auto scrollableWidth = contentWidth - elementWidth;
87 if (scrollableWidth <= 0.0f) return;
88
89 auto childrenRenderOffsetX = contentNode->getChildrenRenderOffsetX() + (draggedX * (scrollableWidth / (node->computedConstraints.width - getBarWidth())));
90 if (childrenRenderOffsetX < 0) childrenRenderOffsetX = 0;
91 if (childrenRenderOffsetX > scrollableWidth) childrenRenderOffsetX = scrollableWidth;
92
93 contentNode->setChildrenRenderOffsetX(childrenRenderOffsetX);
94}
95
97{
98 if (event->getType() == GUIMouseEvent::MOUSEEVENT_MOVED) {
99 if (this->node->isEventBelongingToNode(event) == true) {
101 this->node->getScreenNode()->getGUI()->addMouseOutCandidateElementNode(this->node);
102 } else {
104 }
105 event->setProcessed(true);
106 } else
107 if (this->node == node && event->getButton() == MOUSE_BUTTON_LEFT) {
108 if (node->isEventBelongingToNode(event) == true && event->getType() == GUIMouseEvent::MOUSEEVENT_PRESSED) {
110 auto barLeft = getBarLeft();
111 auto barWidth = getBarWidth();
112 if (event->getX() + barOffsetX < barLeft) {
113 float elementWidth = contentNode->computedConstraints.width;
114 auto scrollableWidth = contentWidth - elementWidth;
115 setDraggedX(-elementWidth * ((node->computedConstraints.width - barWidth) / scrollableWidth));
116 } else
117 if (event->getX() + barOffsetX > barLeft + barWidth) {
118 float elementWidth = contentNode->computedConstraints.width;
119 auto scrollableWidth = contentWidth - elementWidth;
120 setDraggedX(+elementWidth * ((node->computedConstraints.width - barWidth) / scrollableWidth));
121 } else
122 if (event->getX() + barOffsetX >= barLeft && event->getX() + barOffsetX < barLeft + barWidth) {
123 mouseXOffset = static_cast<int>((event->getX() - barLeft));
125 }
126 event->setProcessed(true);
127 } else
128 if (state == STATE_DRAGGING && event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
129 mouseXOffset = -1;
131 event->setProcessed(true);
132 } else
133 if (state == STATE_DRAGGING && event->getType() == GUIMouseEvent::MOUSEEVENT_DRAGGED) {
134 auto barLeft = getBarLeft();
135 auto draggedX = event->getX() - barLeft - mouseXOffset;
136 setDraggedX(draggedX);
137 event->setProcessed(true);
138 }
139 }
140}
141
143{
144}
145
147{
148}
149
151{
152}
153
155{
156}
157
159{
160 return false;
161}
162
164{
165 return value;
166}
167
169{
170}
171
173{
174}
#define MOUSE_BUTTON_LEFT
GUI module class.
Definition: GUI.h:66
void addMouseOutCandidateElementNode(GUINode *node)
Add node that is a possible mouse out candidate as it received a mouse over.
Definition: GUI.h:110
void initialize() override
Initialize controller after element has been created.
void handleKeyboardEvent(GUIKeyboardEvent *event) override
Handle keyboard event.
void handleMouseEvent(GUINode *node, GUIMouseEvent *event) override
Handle mouse event.
void tick() override
Tick method will be executed once per frame.
GUI node controller base class.
GUI node base class.
Definition: GUINode.h:63
float computeParentChildrenRenderOffsetXTotal()
Definition: GUINode.cpp:951
GUINode_Border border
Definition: GUINode.h:159
GUINode_ComputedConstraints computedConstraints
Definition: GUINode.h:151
GUIParentNode * getParentControllerNode()
Definition: GUINode.cpp:1053
bool isEventBelongingToNode(GUIMouseEvent *event, Vector2 &position)
Is event belonging to node.
Definition: GUINode.cpp:973
GUIScreenNode * getScreenNode()
Definition: GUINode.h:315
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:43
void setChildrenRenderOffsetX(float childrenRenderOffSetX)
Set children render offset x.
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.
Mutable string class.
Definition: MutableString.h:16
GUI node border entity.