00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef STROKE_HPP
00025 #define STROKE_HPP
00026
00027 #include <vector>
00028
00029 #include <mapnik/color.hpp>
00030
00031 namespace mapnik
00032 {
00033 using std::pair;
00034 using std::vector;
00035 typedef vector<pair<float,float> > dash_array;
00036
00037 enum line_cap_e
00038 {
00039 BUTT_CAP,
00040 SQUARE_CAP,
00041 ROUND_CAP
00042 };
00043
00044 enum line_join_e
00045 {
00046 MITER_JOIN,
00047 MITER_REVERT_JOIN,
00048 ROUND_JOIN,
00049 BEVEL_JOIN
00050 };
00051
00052 class stroke
00053 {
00054 Color c_;
00055 float width_;
00056 float opacity_;
00057 line_cap_e line_cap_;
00058 line_join_e line_join_;
00059 dash_array dash_;
00060 public:
00061 explicit stroke()
00062 : c_(0,0,0),
00063 width_(1.0),
00064 opacity_(1.0),
00065 line_cap_(BUTT_CAP),
00066 line_join_(MITER_JOIN),
00067 dash_() {}
00068
00069 stroke(Color const& c, float width=1.0)
00070 : c_(c),
00071 width_(width),
00072 opacity_(1.0),
00073 line_cap_(BUTT_CAP),
00074 line_join_(MITER_JOIN),
00075 dash_() {}
00076
00077 stroke(stroke const& other)
00078 : c_(other.c_),
00079 width_(other.width_),
00080 opacity_(other.opacity_),
00081 line_cap_(other.line_cap_),
00082 line_join_(other.line_join_),
00083 dash_(other.dash_) {}
00084
00085 stroke& operator=(const stroke& rhs)
00086 {
00087 stroke tmp(rhs);
00088 swap(tmp);
00089 return *this;
00090 }
00091
00092 void set_color(const Color& c)
00093 {
00094 c_=c;
00095 }
00096
00097 Color const& get_color() const
00098 {
00099 return c_;
00100 }
00101
00102 float get_width() const
00103 {
00104 return width_;
00105 }
00106 void set_width(float w)
00107 {
00108 width_=w;
00109 }
00110
00111 void set_opacity(float opacity)
00112 {
00113 if (opacity > 1.0) opacity_=1.0;
00114 else if (opacity < 0.0) opacity_=0.0;
00115 else opacity_=opacity;
00116 }
00117
00118 float get_opacity() const
00119 {
00120 return opacity_;
00121 }
00122
00123 void set_line_cap(line_cap_e line_cap)
00124 {
00125 line_cap_=line_cap;
00126 }
00127
00128 line_cap_e get_line_cap() const
00129 {
00130 return line_cap_;
00131 }
00132
00133 void set_line_join(line_join_e line_join)
00134 {
00135 line_join_=line_join;
00136 }
00137
00138 line_join_e get_line_join() const
00139 {
00140 return line_join_;
00141 }
00142
00143 void add_dash(float dash,float gap)
00144 {
00145 dash_.push_back(std::make_pair(dash,gap));
00146 }
00147 bool has_dash() const
00148 {
00149 return dash_.size()>0 ? true : false ;
00150 }
00151
00152 dash_array const& get_dash_array() const
00153 {
00154 return dash_;
00155 }
00156
00157 private:
00158 void swap(const stroke& other) throw()
00159 {
00160 c_=other.c_;
00161 width_=other.width_;
00162 opacity_=other.opacity_;
00163 line_cap_=other.line_cap_;
00164 line_join_=other.line_join_;
00165 dash_ = other.dash_;
00166 }
00167 };
00168 }
00169
00170 #endif //STROKE_HPP