papyrus logo

polyline.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the papyrus library.                             *
00006  *                                                                         *
00007  *   papyrus is free software; you can redistribute it and/or modify       *
00008  *   it under the terms of the GNU Lesser General Public License           *
00009  *   version 3.0 as published by the Free Software Foundation.             *
00010  *                                                                         *
00011  *   papyrus is distributed in the hope that it will be useful,            *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Lesser General Public License version 3.0 for more details.       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with the papyrus library. If not, see                   *
00018  *   <http://www.gnu.org/licenses/>.                                       *
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

Generated on Fri Apr 16 12:40:11 2010 for papyrus by doxygen 1.6.1