group.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef PAPYRUSGROUP_H
00020 #define PAPYRUSGROUP_H
00021 
00022 #include <list>
00023 #include <map>
00024 #include <vector>
00025 
00026 #include <papyrus/drawable.h>
00027 
00057 namespace Papyrus
00058 {
00059 
00081   class Group : public Drawable
00082   {
00083     protected:
00084 
00085       Group();
00086 
00087     public:
00088       typedef PapyrusSmartPointer<Group> pointer;
00089 
00090       static pointer create();
00091 
00098       typedef std::list<Drawable::pointer> Layer;
00099 
00104       typedef std::map<int,Layer> Layers;
00105 
00106       friend class Canvas;
00107 
00108       virtual ~Group();
00109 
00116       virtual bool add( Drawable::pointer item, int layer=0, bool drawing_only=false );
00117 
00121       virtual bool remove( Drawable::pointer object );
00122 
00127       virtual bool remove( Drawable* object );
00128 
00132       virtual bool clear();
00133 
00138       virtual bool raise( Drawable::pointer item, int steps=1 );
00139 
00141       virtual bool raise_to_top( Drawable::pointer item );
00142 
00147       virtual bool lower( Drawable::pointer item, int steps=1 );
00148       
00154       virtual bool lower_to_bottom( Drawable::pointer item );
00155 
00160       virtual bool move_to_layer( int layer, Drawable::pointer item );
00161 
00163       size_t size() const;
00164       
00166       const Layers& layers() const;
00167 
00174       const Layer& layer(int l) const throw (std::out_of_range);
00175 
00177       bool has_layer( int l );
00178 
00185       virtual bool inside( double x, double y );
00186 
00187       virtual std::vector<Drawable::pointer> select( double x, double y, unsigned depth = 1 );
00188 
00189       sigc::signal<void, Drawable::pointer>& signal_child_added();
00190 
00191       sigc::signal<void, Drawable::pointer>& signal_child_removed();
00192 
00193       virtual bool is_group();
00194 
00195       PAPYRUS_CLASS_NAME("Group");
00196 
00197       PAPYRUS_CLONE_METHOD( Group );
00198 
00199     protected:
00200 
00201       // maintaining both items as list for drawing order and connections for quick access
00202       Layers m_layers;
00203       size_t m_size;
00204 
00205       typedef std::map<Drawable::pointer, sigc::connection> Connections;
00206       Connections m_redraw_connections;
00207       Connections m_changed_connections;
00208 
00209       sigc::signal<void, Drawable::pointer> m_signal_child_added;
00210       sigc::signal<void, Drawable::pointer> m_signal_child_removed;
00211 
00222       virtual void on_child_changed( Drawable::pointer child );
00223 
00232       virtual void update_extents();
00233 
00234       void on_child_need_redraw( double x, double y, double w, double h, Drawable::pointer child );
00235       virtual void draw( Cairo::RefPtr<Cairo::Context> cairo );
00236 
00237       virtual void rebuild_extents();
00238 
00239   };
00240 
00241 }
00242 
00243 #endif

Generated on Sun Mar 11 10:01:28 2007 by  doxygen 1.5.1