-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewLAT.cpp
97 lines (86 loc) · 3.04 KB
/
ViewLAT.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
#include "ViewLAT.h"
void ViewLAT::removeAllTailboneLine() {
for (int i = 0; i < TAILBONE_POINT_COUNT; ++i)
if (gs.tailboneLine[i] != nullptr) {
scene()->removeItem(gs.tailboneLine[i]);
gs.tailboneLine[i] = nullptr;
}
}
void ViewLAT::drawTailboneLine() {
removeAllTailboneLine();
bool isAllPointSet = true;
for (int i = 0; i < TAILBONE_POINT_COUNT; ++i) {
if (isPointInvalid(gs.tailbonePoint[i])) {
isAllPointSet = false;
}
}
if (isAllPointSet) {
for (int i = 0; i < TAILBONE_POINT_COUNT; ++i) {
for (int j = 0; j < TAILBONE_POINT_COUNT - (i + 1); ++j) {
if (gs.tailbonePoint[j].position.y() >
gs.tailbonePoint[j + 1].position.y()) {
point tmp;
tmp = gs.tailbonePoint[j + 1];
gs.tailbonePoint[j + 1] = gs.tailbonePoint[j];
gs.tailbonePoint[j] = tmp;
}
}
}
// Draw line
gs.pen[scr]->setWidth(7);
for (int i = 0; i < TAILBONE_POINT_COUNT; ++i) {
gs.tailboneLine[i] = scene()->addLine(
gs.tailbonePoint[i].position.x() + CLICK_CORRECTION_WIDTH,
gs.tailbonePoint[i].position.y() + CLICK_CORRECTION_WIDTH,
gs.tailbonePoint[(i + 1) % 3].position.x() + CLICK_CORRECTION_WIDTH,
gs.tailbonePoint[(i + 1) % 3].position.y() + CLICK_CORRECTION_WIDTH,
*gs.pen[scr]);
}
}
}
void ViewLAT::drawTailbonePoint(QPointF pos, const Qt::MouseButton& btn) {
int removePointIndex;
pos.setX(pos.x() - CLICK_CORRECTION_WIDTH);
pos.setY(pos.y() - CLICK_CORRECTION_WIDTH);
if (btn == Qt::LeftButton) {
if (gs.currentTailbonePoint >= TAILBONE_POINT_COUNT) return;
if (clickRangedTailbonePointOrNull(pos, removePointIndex) != nullptr)
return;
gs.pen[scr]->setColor(Qt::blue);
gs.tailbonePoint[gs.currentTailbonePoint] = {
scene()->addEllipse(pos.x(), pos.y(), POINT_RADIUS, POINT_RADIUS,
*gs.pen[scr], *gs.brush[scr]),
pos};
if (gs.removedTailbonePoint.empty() == false) {
int t = gs.removedTailbonePoint.top();
gs.removedTailbonePoint.pop();
gs.currentTailbonePoint = t;
} else {
++gs.currentTailbonePoint;
}
} else {
point* p = clickRangedTailbonePointOrNull(pos, removePointIndex);
if (p == nullptr) return;
gs.removedTailbonePoint.push(gs.currentTailbonePoint);
gs.currentTailbonePoint = removePointIndex;
scene()->removeItem((QGraphicsItem*)p->item);
GlobalState::initPoint(p);
}
drawTailboneLine();
resetPenSetting();
}
point* ViewLAT::clickRangedTailbonePointOrNull(const QPointF& pos,
int& outCurrentPoint) {
for (int i = 0; i < TAILBONE_POINT_COUNT; ++i) {
qreal x = gs.tailbonePoint[i].position.x();
qreal y = gs.tailbonePoint[i].position.y();
if ((x - CLICK_RANGE_WIDTH <= pos.x() &&
pos.x() <= x + CLICK_RANGE_WIDTH) &&
(y - CLICK_RANGE_WIDTH <= pos.y() &&
pos.y() <= y + CLICK_RANGE_WIDTH)) {
outCurrentPoint = i;
return &gs.tailbonePoint[i];
}
}
return nullptr;
}