1
// --------------------------------------------------------------------
3
// --------------------------------------------------------------------
6
This file is part of the extensible drawing editor Ipe.
7
Copyright (C) 1993-2004 Otfried Cheong
9
Ipe is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
As a special exception, you have permission to link Ipe with the
15
CGAL library and distribute executables, as long as you follow the
16
requirements of the Gnu General Public License in regard to all of
17
the software in the executable aside from CGAL.
19
Ipe is distributed in the hope that it will be useful, but WITHOUT
20
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
22
License for more details.
24
You should have received a copy of the GNU General Public License
25
along with Ipe; if not, you can find it at
26
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
27
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32
#include "ipevisitor.h"
33
#include "ipepainter.h"
37
\brief The mark object.
39
A mark is a little marker for a "point". Several shapes are
40
available: disks, circles, squares, crosses, etc.
44
//! Create from XML stream.
45
IpeMark::IpeMark(IpeRepository *rep, const IpeXmlAttributes &attr,
47
: IpeObject(rep, attr)
49
iSize = rep->MakeScalar(IpeAttribute::EMarkSize, attr["size"]);
50
IpeLex shapeLex(attr["shape"]);
55
IpeLex lex(attr["pos"]);
56
lex >> iPos.iX >> iPos.iY;
59
//! Create at position.
60
IpeMark::IpeMark(const IpeAllAttributes &attr, const IpeVector &pos)
63
iSize = attr.iMarkSize;
64
iShape = attr.iMarkShape;
69
IpeObject *IpeMark::Clone() const
71
return new IpeMark(*this);
75
IpeMark::IpeMark(const IpeMark &rhs)
83
//! Return pointer to this object.
84
IpeMark *IpeMark::AsMark()
89
//! Call VisitMark of visitor.
90
void IpeMark::Accept(IpeVisitor &visitor) const
92
visitor.VisitMark(this);
95
void IpeMark::SaveAsXml(IpePainter &painter, IpeStream &stream,
96
IpeString layer) const
99
SaveAttributesAsXml(painter, stream, layer);
100
stream << " pos=\"" << iPos.iX << " " << iPos.iY << "\"";
101
if (painter.MarkShape() == 0)
102
stream << " shape=\"" << int(iShape) << "\"";
103
if (painter.MarkSize().IsNull())
104
stream << " size=\"" << painter.Repository()->String(iSize) << "\"/>\n";
108
void IpeMark::Draw(IpePainter &painter) const
111
painter.Transform(Matrix());
112
painter.Translate(iPos);
113
painter.Untransform(false);
115
painter.SetMarkSize(iSize);
116
painter.SetMarkShape(iShape);
117
painter.SetStroke(Stroke());
118
painter.SetDashStyle(IpeAttribute::Solid());
120
const IpeRepository *rep = painter.Repository();
121
int shape = painter.MarkShape();
122
double absSize = rep->ToScalar(painter.MarkSize());
124
painter.SetLineWidth(IpeAttribute(IpeAttribute::ELineWidth, 0.2 * absSize));
126
if (shape == EDisc || shape == ESquare) {
127
painter.SetFill(painter.Stroke());
129
painter.SetFill(IpeAttribute::Void());
132
IpeVector size(absSize, absSize);
133
IpeVector ll = IpeVector::Zero - 0.5 * size;
134
if (shape == EBox || shape == ESquare) {
136
re.AddPoint(ll + size);
138
} else if (shape == ECross) {
139
painter.BeginPath(ll);
140
painter.LineTo(ll + size);
142
painter.BeginPath(ll + IpeVector(absSize, 0));
143
painter.LineTo(ll + IpeVector(0, absSize));
147
m.iA[0] = m.iA[3] = 0.5 * absSize;
148
painter.Transform(m);
149
painter.DrawEllipse();
155
double IpeMark::Distance(const IpeVector &v, const IpeMatrix &m,
156
double /* bound */) const
158
return (v - m * (Matrix() * Position())).Len();
161
void IpeMark::AddToBBox(IpeRect &box, const IpeMatrix &m) const
163
IpeVector p = m * (Matrix() * Position());
167
void IpeMark::SnapVtx(const IpeVector &mouse, const IpeMatrix &m,
168
IpeVector &pos, double &bound) const
170
SnapVertex(mouse, m * Matrix() * Position(), pos, bound);
173
//! Set shape of mark.
174
void IpeMark::SetShape(int shape)
179
//! Set size of mark.
180
void IpeMark::SetSize(IpeAttribute size)
185
void IpeMark::CheckStyle(const IpeStyleSheet *sheet,
186
IpeAttributeSeq &seq) const
188
IpeObject::CheckStyle(sheet, seq);
189
CheckSymbol(iSize, sheet, seq);
192
// --------------------------------------------------------------------