Newer
Older
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
#include "multiline.h"
#include "scene.h"
MultiLine::MultiLine(Point startIn, Scene *s) : Shape(startIn, s->getDefaultColour()) {
points.push_back(Point(0, 0));
}
void MultiLine::addPoint(Point toAdd) {
toAdd = Point(toAdd.x - start.x, toAdd.y - start.y);
points.push_back(toAdd);
points.push_back(toAdd);
}
void MultiLine::display(QPainter *qp) {
qp->setPen(QPen(colour, 2, Qt::SolidLine));
QVector<QPoint> qv;
for (Point &p: points) {
qv.push_back(QPoint(start.x + p.x, start.y + p.y));
}
qp->drawLines(qv);
}
void MultiLine::displayHighlight(QPainter *qp, QColor colourIn) {
qp->setPen(QPen(colourIn, 2, Qt::DashLine));
QVector<QPoint> qv;
for (Point &p: points) {
qv.push_back(QPoint(start.x + p.x, start.y + p.y));
}
qp->drawLines(qv);
}
void MultiLine::update(Point in, Scene *parent) {
addPoint(in);
}
float MultiLine::innerDistance() {
return distanceBetweenPoints(start, points.back());
}
bool MultiLine::pointInShape(Point in) {
Point delta(in.x - start.x, in.y - start.y);
for (int i = 1; i < (int) points.size(); i += 2) {
Point &p = points[i];
if (distanceBetweenPoints(delta, p) <= 1.5) {
return true;
}
}
return false;
}