-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshape.cpp
More file actions
68 lines (55 loc) · 1.3 KB
/
shape.cpp
File metadata and controls
68 lines (55 loc) · 1.3 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "shape.h"
namespace {
const int NEAR_LEVEL = 10;
}
Shape::Shape(HDC hdc) {
m_hdc = hdc;
m_painter = new Painter(m_hdc);
m_state = StateType::NOMAL;
m_shapeType = ShapeType::NODEFINE;
m_beginPoint = new Point;
m_endPoint = new Point;
}
Shape::~Shape() {
delete m_painter;
delete m_beginPoint;
delete m_endPoint;
}
void Shape::setHDC(HDC hdc) {
if (!hdc)
return;
m_hdc = hdc;
m_painter->setHDC(hdc);
}
void Shape::setBegin(const Point& beginPoint)
{
m_beginPoint->setX(beginPoint.x());
m_beginPoint->setY(beginPoint.y());
}
void Shape::setEnd(const Point& endPoint)
{
m_endPoint->setX(endPoint.x());
m_endPoint->setY(endPoint.y());
}
void Shape::resize(int width, int height)
{
m_endPoint->setX(m_beginPoint->x() + width);
m_endPoint->setY(m_beginPoint->y() + height);
}
void Shape::moveFunction(const Point& sPoint, const Point& dPoint)
{
Point diffPoint = dPoint.minusPoint(sPoint);
*m_beginPoint = m_beginPoint->addPoint(diffPoint);
*m_endPoint = m_endPoint->addPoint(diffPoint);
}
void Shape::zoomFunction(const Point& sPoint, const Point& dPoint)
{
// 如果靠近起点,将起点设为这个
if (sPoint.pointAroundPoint(*m_beginPoint, NEAR_LEVEL)) {
setBegin(dPoint);
}
// 如果靠近终点,把重点设为这个
else if (sPoint.pointAroundPoint(*m_endPoint, NEAR_LEVEL)) {
setEnd(dPoint);
}
}