-
Notifications
You must be signed in to change notification settings - Fork 0
/
Marker.cpp
112 lines (80 loc) · 2.55 KB
/
Marker.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Marker.h"
// ===============================================================
Marker::Marker()
{
selected = false;
dragging = false;
strcpy(label, "durp"); // default
grid = 1; // default is 1 x/y coordinate = 1 pixel
SetPos(0, 0);
}
// ===============================================================
Marker::Marker(u16 x, u16 y, u16 grid)
{
this->selected = false;
this->dragging = false;
this->grid = grid;
SetPos(x, y);
}
// ===============================================================
void Marker::SetPos(u16 x, u16 y)
{
// snaps the object's coordinates to a grid
this->x = x - (x % this->grid);
this->y = y - (y % this->grid);
SetRect();
}
// ===============================================================
void Marker::SetRect()
{
r.left = this->x;
r.right = this->x + 15;
r.top = this->y;
r.bottom = this->y + 15;
}
// ===============================================================
// returns true only if the inputted coordinates
// would resolve to the same position as the Marker's.
bool Marker::IsPos(u16 x, u16 y)
{
if(this->y == (y - (y % this->grid)))
if(this->x == (x - (x % this->grid)))
return true;
return false;
}
// ===============================================================
bool Marker::IsClick(u16 x, u16 y)
{
POINT pt = { x, y };
return PtInRect( (const RECT*) this->GetRect(), pt) == TRUE ? true : false;
}
// ===============================================================
RECT* Marker::GetRect()
{
return &this->r;
}
// ===============================================================
bool Marker::Select(Marker *m)
{
if(m)
{
m->selected = true;
m->dragging = true;
return true;
}
else
return false;
}
// ===============================================================
bool Marker::Unselect(Marker *m)
{
if(m)
{
m->selected = false;
m->dragging = false;
return true;
}
else
return false;
}
// ===============================================================