-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.cpp
More file actions
49 lines (46 loc) · 1.09 KB
/
Node.cpp
File metadata and controls
49 lines (46 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Node.h"
namespace UI
{
void Node::onMouseMove(float x, float y)
{
// scroll offset
y -= scrollForce.x;
if (x >= bounds.x &&
x <= bounds.x + bounds.w &&
y >= bounds.y &&
y <= bounds.y + bounds.h)
{
isMouseOver = true;
}
else
{
isMouseOver = false;
}
// relative positioning
y -= bounds.y;
x -= bounds.x;
for (auto &child : children)
{
child->onMouseMove(x, y);
}
}
void Node::handleScroll(SDL_MouseWheelEvent event)
{
float x{event.mouse_x}, y{event.mouse_y};
if (scrollable)
{
scrollForce.y = event.y;
return;
}
for (auto &child : children)
{
if (x >= child->bounds.x &&
x <= child->bounds.x + child->bounds.w &&
y >= child->bounds.y &&
y <= child->bounds.y + child->bounds.h)
{
child->handleScroll(event);
}
}
}
}