]> Shamusworld >> Repos - architektonas/blob - src/base/rs_pen.h
21b3729c299d5d467034728a9789c28447e7c96b
[architektonas] / src / base / rs_pen.h
1 #ifndef RS_PEN_H
2 #define RS_PEN_H
3
4 #include "rs.h"
5 #include "rs_color.h"
6 #include "rs_flags.h"
7
8 /**
9  * A pen stores attributes for painting such as line width,
10  * linetype, color, ...
11  *
12  * @author Andrew Mustun
13  */
14 class RS_Pen: public RS_Flags
15 {
16 public:
17     /**
18      * Creates a default pen (black, solid, width 0).
19      */
20     RS_Pen() : RS_Flags() {
21         setColor(RS_Color(0,0,0));
22         setWidth(RS2::Width00);
23         setLineType(RS2::SolidLine);
24                 setScreenWidth(0);
25     }
26     /**
27      * Creates a pen with the given attributes.
28      */
29     RS_Pen(const RS_Color& c,
30            RS2::LineWidth w,
31            RS2::LineType t) : RS_Flags() {
32         setColor(c);
33         setWidth(w);
34         setLineType(t);
35                 setScreenWidth(0);
36     }
37     /**
38      * Creates a default pen with the given flags. This is
39      * usually used to create invalid pens.
40      *
41      * e.g.:
42      * <pre>
43      *   RS_Pen p(RS2::FlagInvalid);
44      * </pre>
45      */
46     RS_Pen(unsigned int f) : RS_Flags(f) {
47         setColor(RS_Color(0,0,0));
48         setWidth(RS2::Width00);
49         setLineType(RS2::SolidLine);
50                 setScreenWidth(0);
51     }
52     //RS_Pen(const RS_Pen& pen) : RS_Flags(pen.getFlags()) {
53     //    lineType = pen.lineType;
54     //    width = pen.width;
55     //    color = pen.color;
56     //}
57     virtual ~RS_Pen() {}
58
59     RS2::LineType getLineType() const {
60         return lineType;
61     }
62     void setLineType(RS2::LineType t) {
63         lineType = t;
64     }
65     RS2::LineWidth getWidth() const {
66         return width;
67     }
68     void setWidth(RS2::LineWidth w) {
69         width = w;
70     }
71     double getScreenWidth() const {
72         return screenWidth;
73     }
74     void setScreenWidth(double w) {
75         screenWidth = w;
76     }
77     const RS_Color& getColor() const {
78         return color;
79     }
80     void setColor(const RS_Color& c) {
81         color = c;
82     }
83     bool isValid() {
84         return !getFlag(RS2::FlagInvalid);
85     }
86
87     //RS_Pen& operator = (const RS_Pen& p) {
88     //    lineType = p.lineType;
89     //    width = p.width;
90     //    color = p.color;
91     //    setFlags(p.getFlags());
92
93     //    return *this;
94     //}
95
96     bool operator == (const RS_Pen& p) const {
97         return (lineType==p.lineType && width==p.width && color==p.color);
98     }
99
100     bool operator != (const RS_Pen& p) const {
101         return !(*this==p);
102     }
103
104     friend std::ostream& operator << (std::ostream& os, const RS_Pen& p) {
105         //os << "style: " << p.style << std::endl;
106         os << " pen color: " << p.getColor()
107         << " pen width: " << p.getWidth()
108         << " pen screen width: " << p.getScreenWidth()
109         << " pen line type: " << p.getLineType()
110         << " flags: " << (p.getFlag(RS2::FlagInvalid) ? "INVALID" : "")
111         << std::endl;
112         return os;
113     }
114
115 protected:
116     RS2::LineType lineType;
117     RS2::LineWidth width;
118         double screenWidth;
119     RS_Color color;
120 };
121
122 #endif