1 /****************************************************************************
2 ** $Id: rs_painter.cpp 1938 2004-12-09 23:09:53Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_painter.h"
29 RS_Painter::RS_Painter(): drawingMode(RS2::ModeFull), offset(Vector(0.0, 0.0))
31 // drawingMode = RS2::ModeFull;
32 // offset = Vector(0.0, 0.0);
36 * Sets the drawing mode.
38 void RS_Painter::setDrawingMode(RS2::DrawingMode m)
44 * @return Current drawing mode.
46 RS2::DrawingMode RS_Painter::getDrawingMode()
51 void RS_Painter::createArc(Q3PointArray & pa, const Vector& cp, double radius,
52 double a1, double a2, bool reversed)
56 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Painter::createArc: invalid radius: %f", radius);
60 int cix; // Next point on circle
62 double aStep; // Angle Step (rad)
63 double a; // Current Angle (rad)
65 if (fabs(2.0 / radius) <= 1.0)
66 aStep = asin(2.0 / radius);
74 // less than a pixel long lines:
75 //if (radius*aStep<1.0) {
82 pa.setPoint(i++, toScreenX(cp.x + cos(a1) * radius), toScreenY(cp.y - sin(a1) * radius));
83 //moveTo(toScreenX(cp.x+cos(a1)*radius),
84 // toScreenY(cp.y-sin(a1)*radius));
88 // Arc Counterclockwise:
89 if (a1 > a2 - 1.0e-10)
92 for(a=a1+aStep; a<=a2; a+=aStep)
94 cix = toScreenX(cp.x + cos(a) * radius);
95 ciy = toScreenY(cp.y - sin(a) * radius);
97 pa.setPoint(i++, cix, ciy);
103 if (a1 < a2 + 1.0e-10)
106 for(a=a1-aStep; a>=a2; a-=aStep)
108 cix = toScreenX(cp.x + cos(a) * radius);
109 ciy = toScreenY(cp.y - sin(a) * radius);
112 pa.setPoint(i++, cix, ciy);
117 pa.setPoint(i++, toScreenX(cp.x + cos(a2) * radius), toScreenY(cp.y - sin(a2) * radius));
121 void RS_Painter::drawRect(const Vector & p1, const Vector & p2)
123 drawLine(Vector(p1.x, p1.y), Vector(p2.x, p1.y));
124 drawLine(Vector(p2.x, p1.y), Vector(p2.x, p2.y));
125 drawLine(Vector(p2.x, p2.y), Vector(p1.x, p2.y));
126 drawLine(Vector(p1.x, p2.y), Vector(p1.x, p1.y));
129 void RS_Painter::drawHandle(const Vector & p, const RS_Color & c, int size)
134 fillRect((int)(p.x - size), (int)(p.y - size), 2 * size, 2 * size, c);
137 void RS_Painter::setPreviewMode()
139 drawingMode = RS2::ModeXOR;
144 bool RS_Painter::isPreviewMode()
146 return (drawingMode == RS2::ModeXOR);
149 void RS_Painter::setOffset(const Vector & o)
154 int RS_Painter::toScreenX(double x)
156 return RS_Math::round(offset.x + x);
159 int RS_Painter::toScreenY(double y)
161 return RS_Math::round(offset.y + y);