]> Shamusworld >> Repos - architektonas/blob - src/base/rs_painter.cpp.old
Final round of dialogs/forms needing to be converted from Qt3 to 4
[architektonas] / src / base / rs_painter.cpp.old
1 /****************************************************************************
2 ** $Id: rs_painter.cpp 1938 2004-12-09 23:09:53Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
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.
12 **
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.
16 **
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.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_painter.h"
28
29 RS_Painter::RS_Painter(): drawingMode(RS2::ModeFull), offset(Vector(0.0, 0.0))
30 {
31 //      drawingMode = RS2::ModeFull;
32 //      offset = Vector(0.0, 0.0);
33 }
34
35 /**
36 * Sets the drawing mode.
37 */
38 void RS_Painter::setDrawingMode(RS2::DrawingMode m)
39 {
40         drawingMode = m;
41 }
42
43 /**
44 * @return Current drawing mode.
45 */
46 RS2::DrawingMode RS_Painter::getDrawingMode()
47 {
48         return drawingMode;
49 }
50
51 void RS_Painter::createArc(Q3PointArray & pa, const Vector& cp, double radius,
52         double a1, double a2, bool reversed)
53 {
54         if (radius < 1.0e-6)
55         {
56                 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Painter::createArc: invalid radius: %f", radius);
57                 return;
58         }
59
60         int cix;              // Next point on circle
61         int ciy;              //
62         double aStep;         // Angle Step (rad)
63         double a;             // Current Angle (rad)
64
65         if (fabs(2.0 / radius) <= 1.0)
66                 aStep = asin(2.0 / radius);
67         else
68                 aStep = 1.0;
69
70         //if (aStep<0.05) {
71         //    aStep = 0.05;
72         //}
73
74         // less than a pixel long lines:
75         //if (radius*aStep<1.0) {
76         //      aStep =
77         //}
78
79         //QPointArray pa;
80         int i = 0;
81         pa.resize(i + 1);
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));
85
86         if (!reversed)
87         {
88                 // Arc Counterclockwise:
89                 if (a1 > a2 - 1.0e-10)
90                         a2 += 2 * M_PI;
91
92                 for(a=a1+aStep; a<=a2; a+=aStep)
93                 {
94                         cix = toScreenX(cp.x + cos(a) * radius);
95                         ciy = toScreenY(cp.y - sin(a) * radius);
96                         pa.resize(i + 1);
97                         pa.setPoint(i++, cix, ciy);
98                 }
99         }
100         else
101         {
102                 // Arc Clockwise:
103                 if (a1 < a2 + 1.0e-10)
104                         a2 -= 2 * M_PI;
105
106                 for(a=a1-aStep; a>=a2; a-=aStep)
107                 {
108                         cix = toScreenX(cp.x + cos(a) * radius);
109                         ciy = toScreenY(cp.y - sin(a) * radius);
110                         //lineTo(cix, ciy);
111                         pa.resize(i + 1);
112                         pa.setPoint(i++, cix, ciy);
113                 }
114         }
115
116         pa.resize(i + 1);
117         pa.setPoint(i++, toScreenX(cp.x + cos(a2) * radius), toScreenY(cp.y - sin(a2) * radius));
118         //drawPolyline(pa);
119 }
120
121 void RS_Painter::drawRect(const Vector & p1, const Vector & p2)
122 {
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));
127 }
128
129 void RS_Painter::drawHandle(const Vector & p, const RS_Color & c, int size)
130 {
131         if (size < 0)
132                 size = 2;
133
134         fillRect((int)(p.x - size), (int)(p.y - size), 2 * size, 2 * size, c);
135 }
136
137 void RS_Painter::setPreviewMode()
138 {
139         drawingMode = RS2::ModeXOR;
140         setXORMode();
141         setPreviewPen();
142 }
143
144 bool RS_Painter::isPreviewMode()
145 {
146         return (drawingMode == RS2::ModeXOR);
147 }
148
149 void RS_Painter::setOffset(const Vector & o)
150 {
151         offset = o;
152 }
153
154 int RS_Painter::toScreenX(double x)
155 {
156         return RS_Math::round(offset.x + x);
157 }
158
159 int RS_Painter::toScreenY(double y)
160 {
161         return RS_Math::round(offset.y + y);
162 }