papyrus logo

group.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 PAPYRUSGROUP_H
00021 #define PAPYRUSGROUP_H
00022 
00023 #include <list>
00024 #include <map>
00025 #include <vector>
00026 
00027 #include <papyrus/drawable.h>
00028 #include <papyrus/fill.h>
00029 #include <papyrus/rgba.h>
00030 #include <papyrus/stroke.h>
00031 
00061 namespace Papyrus
00062 {
00063 
00064   typedef std::vector<Drawable::pointer> Selection;
00065 
00086   class Group : public Drawable
00087   {
00088     protected:
00089 
00090       Group(const Glib::ustring& id);
00091 
00092       Group(const AttributeValueMap& avmap);
00093 
00094     public:
00095       typedef PapyrusPointer<Group> pointer;
00096 
00097       static pointer create(const Glib::ustring& id=Glib::ustring());
00098 
00099       static pointer create(const AttributeValueMap& avmap);
00100 
00107       typedef std::list<Drawable::pointer> Layer;
00108 
00113       typedef std::map<int,Layer> Layers;
00114 
00115       friend class Canvas;
00116 
00117       virtual ~Group();
00118 
00119       const Glib::ustring& title() const;
00120 
00121       void set_title( const Glib::ustring& t );
00122 
00123       sigc::signal<void>& signal_title_changed();
00124 
00125       const Glib::ustring& description() const;
00126 
00127       void set_description( const Glib::ustring& d );
00128 
00129       sigc::signal<void>& signal_description_changed();
00130       
00135       virtual void freeze();
00136       
00143       virtual void thaw(bool force_redraw=false);
00144 
00145 
00146       virtual void set( const AttributeValueMap& avmap );
00147 
00154       virtual bool add( Drawable::pointer item, int layer=0 );
00155 
00159       virtual bool remove( Drawable::pointer object );
00160 
00165       virtual bool remove( Drawable* object );
00166 
00170       virtual bool clear();
00171 
00177       Drawable::pointer child( const Glib::ustring& id ) const;
00178 
00193       template <class T>
00194       PapyrusPointer<T> child( const Glib::ustring& id ) const
00195       {
00196         Layers::const_iterator ilayer;
00197         Layer::const_reverse_iterator ichild;
00198   
00199         for ( ilayer = m_layers.begin(); ilayer != m_layers.end(); ilayer++ )
00200         {
00201           for ( ichild = ilayer->second.rbegin(); ichild != ilayer->second.rend(); ichild++ )
00202           {
00203             if ( (*ichild)->id() == id )
00204             {
00205               PapyrusPointer<T> ptr;
00206               try {
00207                 ptr = papyrus_dynamic_pointer_cast<T>(*ichild);
00208                 return ptr;
00209               }
00210               catch ( std::bad_cast )
00211               {
00212               }
00213             }
00214           }
00215         }
00216 
00217         return PapyrusPointer<T>();
00218       }
00219 
00224       virtual bool raise( Drawable::pointer item, int steps=1 );
00225 
00227       virtual bool raise_to_top( Drawable::pointer item );
00228 
00233       virtual bool lower( Drawable::pointer item, int steps=1 );
00234       
00240       virtual bool lower_to_bottom( Drawable::pointer item );
00241 
00246       virtual bool move_to_layer( int layer, Drawable::pointer item );
00247 
00249       size_t size() const;
00250 
00252       const Layers& layers() const;
00253 
00260       const Layer& layer(int l) const throw (std::out_of_range);
00261 
00263       bool has_layer( int l );
00264 
00266       bool has( Drawable::pointer d ) const;
00267 
00274       virtual bool inside( double x, double y );
00275 
00276       virtual Selection select( double x, double y, unsigned depth = 1 );
00277 
00278       sigc::signal<void, Drawable::pointer>& signal_child_added();
00279 
00280       sigc::signal<void, Drawable::pointer>& signal_child_removed();
00281 
00282       virtual bool is_group();
00283 
00287       Fill::pointer fill();
00288 
00295       void set_fill( Fill::pointer fill );
00296 
00297       void set_fill ( Paint paint );
00298 
00299       void set_fill( const RGBA& color );
00300 
00301       void set_fill( const Glib::ustring& fill );
00302 
00306       Stroke::pointer stroke();
00307 
00314       void set_stroke( Stroke::pointer stroke );
00315 
00316       void set_stroke ( Paint paint );
00317 
00318       void set_stroke ( const RGBA& color );
00319 
00320       void set_stroke ( const Glib::ustring& stroke );
00321 
00323       const PaintDictionary& paint_dictionary() const;
00324 
00330       Paint::pointer lookup_paint( const Glib::ustring& name ) const;
00331 
00333       void add_paint_to_dictionary( const Glib::ustring& name, Paint::pointer p );
00334 
00336       void remove_paint_from_dictionary( const Glib::ustring& name );
00337 
00339       void clear_paint_dictionary();
00340 
00342       sigc::signal<void, const Glib::ustring& >& signal_paint_added_to_dictionary();
00343 
00345       sigc::signal<void, const Glib::ustring& >& signal_paint_removed_from_dictionary();
00346 
00348       const DrawableDictionary& drawable_dictionary() const;
00349 
00357       Drawable::pointer lookup_drawable( const Glib::ustring& name ) const;
00358 
00360       void add_drawable_to_dictionary( const Glib::ustring& name, Drawable::pointer p );
00361 
00363       void remove_drawable_from_dictionary( const Glib::ustring& name );
00364 
00370       void clear_drawable_dictionary();
00371 
00373       sigc::signal<void, const Glib::ustring& >& signal_drawable_added_to_dictionary();
00374 
00376       sigc::signal<void, const Glib::ustring& >& signal_drawable_removed_from_dictionary();
00377 
00378       virtual Glib::ustring svg(unsigned depth=0);
00379 
00380       PAPYRUS_CLASS_NAME("Group");
00381 
00382       PAPYRUS_CLONE_METHOD( Group );
00383 
00384     protected:
00385 
00386       // maintaining both items as list for drawing order and connections for quick access
00387       Layers m_layers;
00388       size_t m_size;
00389 
00390       typedef std::map<Drawable::pointer, sigc::connection> Connections;
00391       Connections m_redraw_connections;
00392       Connections m_changed_connections;
00393 
00394       sigc::signal<void, Drawable::pointer> m_signal_child_added;
00395       sigc::signal<void, Drawable::pointer> m_signal_child_removed;
00396 
00397       Fill::pointer m_fill;
00398       Stroke::pointer m_stroke;
00399 
00400       PaintDictionary m_paint_dictionary;
00401       sigc::signal<void, const Glib::ustring& > m_signal_paint_added_to_dictionary;
00402       sigc::signal<void, const Glib::ustring& > m_signal_paint_removed_from_dictionary;
00403 
00404       DrawableDictionary m_drawable_dictionary;
00405       sigc::signal<void, const Glib::ustring& > m_signal_drawable_added_to_dictionary;
00406       sigc::signal<void, const Glib::ustring& > m_signal_drawable_removed_from_dictionary;
00407 
00408       Glib::ustring m_title;
00409       sigc::signal<void> m_signal_title_changed;
00410 
00411       Glib::ustring m_description;
00412       sigc::signal<void> m_signal_description_changed;
00413 
00414 
00415 
00424       virtual void on_child_changed( Drawable::pointer child );
00425 
00426       virtual Region calculate_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep = EXTENTS_QUICK) const;
00427 
00428       void on_child_redraw( double x, double y, double w, double h, Drawable::pointer child );
00429       
00430       virtual void draw( Cairo::RefPtr<Cairo::Context> cairo ) const;
00431       
00432       void freeze_children();
00433       
00434       void thaw_children(bool force_redraw=false);
00435 
00436     private:
00437 
00442       void on_child_changed_proxy( Drawable::pointer child );
00443       
00444   };
00445 
00446 }
00447 
00448 #endif

Generated on Wed Mar 18 12:34:04 2009 for papyrus by doxygen 1.5.7.1