summaryrefslogtreecommitdiff
path: root/kurator/src/Mouse.cpp
blob: a4eff9d570a454cca86ee42dd1476eb0429455ff (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Mouse.h"

#include <raylib.h>

#include <kurator/engine/Point.h>
#include <kurator/engine/Rect.h>


namespace kurator
{


auto from_raylib() -> engine::Point;


Mouse::Mouse() :
	position_ {from_raylib()},
	start {position_},
	dragging {false}
{
}


void
Mouse::update()
{
	position_ = from_raylib();
	if (!dragging)
		start = position_;
	if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
		start = position_;
		dragging = true;
	}
	if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
		dragging = false;
}


engine::Point
Mouse::position() const
{
	return position_;
}


engine::Rect
Mouse::selection() const
{
	return {start, position_};
}


bool
Mouse::is_dragging() const
{
	return dragging && start != position_;
}


bool
Mouse::finished_dragging() const
{
	return !dragging && start != position_;
}


engine::Point
from_raylib()
{
	return {static_cast<double>(GetMouseX()), static_cast<double>(GetMouseY())};
}


}  // namespace kurator