]> Shamusworld >> Repos - architektonas/blob - src/base/rs_pen.h
4dcf7d9be223f7842ee9925595993fa2b3d723cc
[architektonas] / src / base / rs_pen.h
1 /****************************************************************************
2 ** $Id: rs_pen.h 1760 2003-10-13 19:52:37Z 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 #ifndef RS_PEN_H
28 #define RS_PEN_H
29
30 #include "rs.h"
31 #include "rs_color.h"
32 #include "rs_flags.h"
33
34 /**
35  * A pen stores attributes for painting such as line width,
36  * linetype, color, ...
37  *
38  * @author Andrew Mustun
39  */
40 class RS_Pen: public RS_Flags
41 {
42 public:
43     /**
44      * Creates a default pen (black, solid, width 0).
45      */
46     RS_Pen() : RS_Flags() {
47         setColor(RS_Color(0,0,0));
48         setWidth(RS2::Width00);
49         setLineType(RS2::SolidLine);
50                 setScreenWidth(0);
51     }
52     /**
53      * Creates a pen with the given attributes.
54      */
55     RS_Pen(const RS_Color& c,
56            RS2::LineWidth w,
57            RS2::LineType t) : RS_Flags() {
58         setColor(c);
59         setWidth(w);
60         setLineType(t);
61                 setScreenWidth(0);
62     }
63     /**
64      * Creates a default pen with the given flags. This is
65      * usually used to create invalid pens.
66      *
67      * e.g.:
68      * <pre>
69      *   RS_Pen p(RS2::FlagInvalid);
70      * </pre>
71      */
72     RS_Pen(unsigned int f) : RS_Flags(f) {
73         setColor(RS_Color(0,0,0));
74         setWidth(RS2::Width00);
75         setLineType(RS2::SolidLine);
76                 setScreenWidth(0);
77     }
78     //RS_Pen(const RS_Pen& pen) : RS_Flags(pen.getFlags()) {
79     //    lineType = pen.lineType;
80     //    width = pen.width;
81     //    color = pen.color;
82     //}
83     virtual ~RS_Pen() {}
84
85     RS2::LineType getLineType() const {
86         return lineType;
87     }
88     void setLineType(RS2::LineType t) {
89         lineType = t;
90     }
91     RS2::LineWidth getWidth() const {
92         return width;
93     }
94     void setWidth(RS2::LineWidth w) {
95         width = w;
96     }
97     double getScreenWidth() const {
98         return screenWidth;
99     }
100     void setScreenWidth(double w) {
101         screenWidth = w;
102     }
103     const RS_Color& getColor() const {
104         return color;
105     }
106     void setColor(const RS_Color& c) {
107         color = c;
108     }
109     bool isValid() {
110         return !getFlag(RS2::FlagInvalid);
111     }
112
113     //RS_Pen& operator = (const RS_Pen& p) {
114     //    lineType = p.lineType;
115     //    width = p.width;
116     //    color = p.color;
117     //    setFlags(p.getFlags());
118
119     //    return *this;
120     //}
121
122     bool operator == (const RS_Pen& p) const {
123         return (lineType==p.lineType && width==p.width && color==p.color);
124     }
125
126     bool operator != (const RS_Pen& p) const {
127         return !(*this==p);
128     }
129
130     friend std::ostream& operator << (std::ostream& os, const RS_Pen& p) {
131         //os << "style: " << p.style << std::endl;
132         os << " pen color: " << p.getColor()
133         << " pen width: " << p.getWidth()
134         << " pen screen width: " << p.getScreenWidth()
135         << " pen line type: " << p.getLineType()
136         << " flags: " << (p.getFlag(RS2::FlagInvalid) ? "INVALID" : "")
137         << std::endl;
138         return os;
139     }
140
141 protected:
142     RS2::LineType lineType;
143     RS2::LineWidth width;
144         double screenWidth;
145     RS_Color color;
146 };
147
148 #endif