Repository navigation
Expand file tree
/
Copy pathG_point.cpp
More file actions
126 lines (101 loc) · 2.96 KB
/
Copy pathG_point.cpp
File metadata and controls
126 lines (101 loc) · 2.96 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
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
113
114
115
116
117
118
119
120
121
122
123
/*
* KSeg
* Copyright (C) 1999-2006 Ilya Baran
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Send comments and/or bug reports to:
* ibaran@mit.edu
*/
#include "G_point.H"
#include "G_line.H"
#include <qpainter.h>
#include "G_drawstyle.H"
#include "KSegView.H"
#include <qdatastream.h>
void G_point::draw(QPainter &p, const G_drawstyle &drawstyle, bool selected)
{
QPoint t = p.xForm(toQPoint());
if(t.x() > DRAW_MAX || t.x() < -DRAW_MAX || t.y() > DRAW_MAX || t.y() < -DRAW_MAX) return;
int size;
switch(drawstyle.getPointStyle()) {
case SMALL_CIRCLE:
size = 2; break;
case MEDIUM_CIRCLE:
size = 3; break;
case LARGE_CIRCLE:
size = 4; break;
default:
size = 0;
break;
}
p.setPen(QPen(Qt::NoPen)); //ignore drawstyle settings
if(selected && KSegView::getSelectType() == KSegView::BORDER_SELECT) {
p.setPen(QPen(G_drawstyle::getBorderColor(drawstyle.getPen().color()), 2));
size += 2;
}
p.setBrush(QBrush(drawstyle.getPen().color()));
if(selected && KSegView::getSelectType() == KSegView::BLINKING_SELECT)
p.setBrush(QBrush(QColor(QTime::currentTime().msec() * 17, 255, 255, QColor::Hsv)));
if(/*p.device()->isExtDev() ||*/ p.hasViewXForm()) { //draw at higher accuracy to a printer or image
p.scale(0.125, .125);
size *= 8;
p.drawEllipse(qRound(x * 8. - size), qRound(y * 8. - size), size * 2, size * 2);
p.scale(8, 8);
return;
}
p.drawEllipse(qRound(x - size), qRound(y - size), size * 2, size * 2);
return;
}
bool G_point::inRect(const QRect &r) const
{
return r.contains(toQPoint());
}
//transformations:
void G_point::translate(const G_point &p)
{
(*this) += p;
}
void G_point::scale(const G_point &p, double d)
{
*this = p + (*this - p) * d;
}
void G_point::rotate(const G_point &p, double d)
{
*this -= p;
double oldX = x;
x = x * cos(d) - y * sin(d);
y = oldX * sin(d) + y * cos(d);
*this += p;
}
void G_point::reflect(const G_straight &s)
{
*this =
G_line(s.getNearestPoint(*this), s.getDirection()).
getNearestPoint(*this) * 2 - *this;
}
//save and retrieve:
QDataStream &operator<< (QDataStream &d, const G_point &p)
{
d << (float)p.x << (float)p.y;
return d;
}
QDataStream &operator>> (QDataStream &d, G_point &p)
{
float x, y;
d >> x >> y;
p.x = x; p.y = y;
return d;
}