]> Shamusworld >> Repos - architektonas/blob - src/base/paintinterface.h
3815dd0c28767e97470e2794facba4facc57d6e8
[architektonas] / src / base / paintinterface.h
1 #ifndef __PAINTINTERFACE_H__
2 #define __PAINTINTERFACE_H__
3
4 #include <QtGui>
5 #include "rs.h"
6 #include "vector.h"
7 #include "rs_color.h"
8 #include "rs_pen.h"
9
10 // This is an interface class to the rest of the RS_* functions that are supposed
11 // to be toolkit independent, but, because the author of QCad had no idea how to
12 // do that cleanly, we have the present clusterfuck of disaster and failure that
13 // is RS_Painter & friends. This class proposes to fix that.
14 //
15 // The QPainter passed in is only used, never created. Once this class finishes,
16 // it does *nothing* to the QPainter passed in. But this class *MUST^ pass a valid
17 // one in, or else nothing happens.
18 class PaintInterface
19 {
20         public:
21                 PaintInterface(QPainter * p);
22
23                 void setDrawingMode(RS2::DrawingMode m);
24                 RS2::DrawingMode getDrawingMode();
25                 void drawGridPoint(const Vector & p);
26                 void drawPoint(const Vector & p);
27                 void drawLine(const Vector & p1, const Vector & p2);
28                 void drawRect(const Vector & p1, const Vector & p2);
29                 void drawArc(const Vector & cp, double radius, double a1, double a2,
30                         const Vector & p1, const Vector & p2, bool reversed);
31                 void drawArc(const Vector & cp, double radius,
32                         double a1, double a2, bool reversed);
33                 void drawArcMac(const Vector & cp, double radius, double a1, double a2, bool reversed);
34                 void createArc(QPolygon & pa, const Vector & cp, double radius,
35                         double a1, double a2, bool reversed);
36                 void drawCircle(const Vector & cp, double radius);
37                 void drawEllipse(const Vector & cp, double radius1, double radius2,
38                         double angle, double angle1, double angle2, bool reversed);
39                 void drawImg(QImage & img, const Vector & pos,
40                         double angle, const Vector & factor, int sx, int sy, int sw, int sh);
41                 void fillRect(int x1, int y1, int w, int h, const RS_Color & col);
42                 void fillTriangle(const Vector & p1, const Vector & p2, const Vector & p3);
43                 void drawHandle(const Vector & p, const RS_Color & c, int size = -1);
44                 void setPreviewPen();
45                 RS_Pen getPen();
46                 void setPen(const RS_Pen & pen);
47                 void setPen(const RS_Color & color);
48                 void setPen(int r, int g, int b);
49                 void disablePen();
50                 void setBrush(const RS_Color & color);
51                 void drawPolygon(const QPolygon & p);
52                 void erase();
53                 int getWidth();
54                 int getHeight();
55                 void setXORMode();
56                 void setNormalMode();
57                 void setPreviewMode();
58                 bool isPreviewMode();
59                 void setOffset(const Vector & o);
60                 void setClipRect(int x, int y, int w, int h);
61                 void resetClipping();
62                 int toScreenX(double x);
63                 int toScreenY(double y);
64
65         private:
66                 QPainter * painter;
67                 /**
68                  * Current drawing mode.
69                  */
70                 RS2::DrawingMode drawingMode;
71                 /**
72                  * A fixed offset added to all entities drawn (useful for previews).
73                  */
74                 Vector offset;
75                 RS_Pen lpen;
76 };
77
78 #endif  // __PAINTINTERFACE_H__