polyline.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PAPYRUSPOLYLINE_H
00021 #define PAPYRUSPOLYLINE_H
00022
00023 #include <vector>
00024
00025 #include <papyrus/primitives.h>
00026 #include <papyrus/shape.h>
00027 #include <papyrus/marker.h>
00028
00057 namespace Papyrus
00058 {
00059
00064 struct Vertex: public Point
00065 {
00066 public:
00067 Vertex ( double vx=0.0, double vy=0.0, bool vrelative=false ) : Point(vx,vy), relative ( vrelative ) {}
00068
00069 Vertex( const Point& p, bool vrelative=false ): Point(p), relative(vrelative) { }
00070
00071 Vertex( const Vertex& v ): Point(v.x, v.y), relative(v.relative) { }
00072
00073 bool relative;
00074 };
00075
00076 typedef std::vector<Vertex> Vertices;
00077
00090 class Polyline : public Shape
00091 {
00092 protected:
00093
00094 Polyline ( const Glib::ustring& id, const Vertices& vertices, Fill::pointer fill, Stroke::pointer stroke );
00095
00096 public:
00097 PAPYRUS_DRAWABLE(Polyline);
00098
00100 static pointer create ( const Vertices& vertices = Vertices(), Stroke::pointer stroke = Stroke::pointer() );
00101
00102 static pointer create ( const Vertices& vertices, Fill::pointer fill, Stroke::pointer stroke = Stroke::pointer() );
00103
00104 static pointer create ( const Glib::ustring& id, Vertices vertices = Vertices(), Stroke::pointer stroke = Stroke::pointer() );
00105
00106 static pointer create ( const Glib::ustring& id, Vertices vertices, Fill::pointer fill, Stroke::pointer stroke = Stroke::pointer() );
00107
00108 virtual ~Polyline();
00109
00110 Polyline& operator= ( const Polyline& other );
00111
00112 Vertex vertex ( unsigned n ) const;
00113
00114 const Vertices& vertices() const;
00115
00116 void add_vertex ( Vertex v );
00117
00118 void add_vertex ( double x, double y );
00119
00120 void set_vertex ( unsigned n, Vertex v );
00121
00122 void set_vertex ( unsigned n, double x, double y );
00123
00124 void set_vertices ( const Vertices& vertices );
00125
00126 virtual Marker::pointer marker(MarkerPosition position);
00127
00133 virtual bool set_marker ( MarkerPosition position, Marker::pointer marker );
00134
00135 virtual void draw ( Context& cairo ) const;
00136
00138 virtual void draw_shape ( Context& cairo ) const;
00139
00140 sigc::signal<void, unsigned> signal_vertex();
00141 sigc::signal<void> signal_vertices();
00142
00143 protected:
00144 Vertices m_vertices;
00145 Marker::pointer m_markers[3];
00146
00147 sigc::signal<void, unsigned> m_signal_vertex;
00148 sigc::signal<void> m_signal_vertices;
00149
00150 virtual void on_vertex_changed ( int n );
00151
00152 virtual void on_vertices_changed();
00153
00154 void update_marker_position( MarkerPosition n );
00155
00160 virtual Region calculate_pre_viewbox_extents(const Matrix& m = Matrix::Identity) const;
00161
00162 mutable sigc::connection m_marker_changed_connections[3];
00163
00164 void on_marker_changed(MarkerPosition which);
00165
00166 };
00167
00168 }
00169
00170 #endif