TDME2 1.9.121
GUIVerticalScrollbarInternalController.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
11#include <tdme/gui/GUI.h>
12
14
22using tdme::gui::nodes::GUIVerticalScrollbarInternalController_State;
23using tdme::gui::GUI;
24
25GUIVerticalScrollbarInternalController::GUIVerticalScrollbarInternalController(GUINode* node)
26 : GUINodeController(node)
27{
28 this->contentNode = required_dynamic_cast<GUILayoutNode*>(node->getScreenNode()->getNodeById(node->getParentControllerNode()->id + "_inner"));
30 mouseYOffset = -1;
31 contentHeight = 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 elementHeight = contentNode->computedConstraints.height;
64 auto barHeightRelative = (elementHeight / contentHeight);
65 if (barHeightRelative > 1.0f) barHeightRelative = 1.0f;
66 float barHeight = (node->computedConstraints.height - node->border.top - node->border.bottom) * barHeightRelative;
67 if (barHeight < 20.0f) barHeight = 20.0f;
68 return barHeight;
69}
70
72{
73 float elementHeight = contentNode->computedConstraints.height;
74 auto scrollableHeight = contentHeight - elementHeight;
75 auto childrenRenderOffsetY = contentNode->getChildrenRenderOffsetY();
76 if (scrollableHeight > 0.0f) {
77 return node->computedConstraints.top + node->computedConstraints.alignmentTop + node->border.top + (childrenRenderOffsetY * ((node->computedConstraints.height - getBarHeight()) / scrollableHeight));
78 } else {
80 }
81}
82
84{
85 float elementHeight = contentNode->computedConstraints.height;
86 auto scrollableHeight = contentHeight - elementHeight;
87 if (scrollableHeight <= 0.0f) return;
88
89 auto childrenRenderOffsetY = contentNode->getChildrenRenderOffsetY() + (draggedY * (scrollableHeight / (node->computedConstraints.height - getBarHeight())));
90 if (childrenRenderOffsetY < 0) childrenRenderOffsetY = 0;
91 if (childrenRenderOffsetY > scrollableHeight) childrenRenderOffsetY = scrollableHeight;
92
93 contentNode->setChildrenRenderOffsetY(childrenRenderOffsetY);
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 barTop = getBarTop();
111 auto barHeight = getBarHeight();
112 if (event->getY() + barOffsetY < barTop) {
113 float elementHeight = contentNode->computedConstraints.height;
114 auto scrollableHeight = contentHeight - elementHeight;
115 setDraggedY(-elementHeight * ((node->computedConstraints.height - barHeight) / scrollableHeight));
116 } else
117 if (event->getY() + barOffsetY > barTop + barHeight) {
118 float elementHeight = contentNode->computedConstraints.height;
119 auto scrollableHeight = contentHeight - elementHeight;
120 setDraggedY(+elementHeight * ((node->computedConstraints.height - barHeight) / scrollableHeight));
121 } else
122 if (event->getY() + barOffsetY >= barTop && event->getY() + barOffsetY < barTop + barHeight) {
123 mouseYOffset = static_cast<int>((event->getY() - barTop));
125 }
126 event->setProcessed(true);
127 } else
128 if (state == STATE_DRAGGING && event->getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
129 mouseYOffset = -1;
131 event->setProcessed(true);
132 } else
133 if (state == STATE_DRAGGING && event->getType() == GUIMouseEvent::MOUSEEVENT_DRAGGED) {
134 auto barTop = getBarTop();
135 auto draggedY = event->getY() - barTop - mouseYOffset;
136 setDraggedY(draggedY);
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
GUI node controller base class.
GUI node base class.
Definition: GUINode.h:63
GUINode_Border border
Definition: GUINode.h:159
GUINode_ComputedConstraints computedConstraints
Definition: GUINode.h:151
float computeParentChildrenRenderOffsetYTotal()
Definition: GUINode.cpp:962
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 setChildrenRenderOffsetY(float childrenRenderOffSetY)
Set children render offset y.
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 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.
Mutable string class.
Definition: MutableString.h:16
GUI node border entity.