-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.cpp
45 lines (36 loc) · 944 Bytes
/
Point.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
#include "Point.h"
#include "App.h"
Point::Point(const POINT& p) { //implicit convert
x = p.x;
y = p.y;
}
bool Point::inRange(const Point& p, int range) const {
auto d = p - *this;
return abs(d.x) <= range && abs(d.y) <= range;
}
void Point::draw(HDC hdc_, int size, bool isHover) const
{
if (isHover) {
draw(hdc_, size, App::Instance()->solidBlackPen, App::Instance()->solidRedBrush);
}
else {
draw(hdc_, size, App::Instance()->solidBlackPen, (HBRUSH) GetStockObject(NULL_BRUSH));
}
}
void Point::draw(HDC hdc_, int size, HPEN hpen, HBRUSH hBrush) const {
int s = size / 2;
auto oldPen = SelectPen(hdc_, hpen);
auto oldBrush = SelectBrush(hdc_, hBrush);
Rectangle(hdc_, x - s, y - s, x + s, y + s);
SelectPen(hdc_, oldPen);
SelectPen(hdc_, oldBrush);
}
void Point::save(std::ofstream& f) {
writeInt(f, x);
writeInt(f, y);
}
void Point::load(std::ifstream& f, Point& p)
{
readInt(f, p.x);
readInt(f, p.y);
}