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     public:
00084       typedef PapyrusSmartPointer<Group> pointer;
00085 
00086       Group();
00087 
00088       static pointer create();
00089 
00090       typedef std::list<Drawable::pointer> Children;
00091 
00092       friend class Canvas;
00093 
00094       virtual ~Group();
00095 
00096       virtual bool add( Drawable::pointer item, bool drawing_only=false );
00097 
00098       virtual bool remove( Drawable::pointer object );
00099       
00104       virtual bool remove( Drawable* object );
00105       
00106       virtual bool clear();
00107 
00108       virtual bool raise( Drawable::pointer item );
00109       virtual bool raise_to_top( Drawable::pointer item );
00110       virtual bool lower( Drawable::pointer item );
00111       virtual bool lower_to_bottom( Drawable::pointer item );
00112 
00113       Children& get_children();
00114 
00121       virtual bool inside( double x, double y );
00122 
00123       virtual std::vector<Drawable::pointer> select( double x, double y, unsigned depth = 1 );
00124 
00125       sigc::signal<void, Drawable::pointer>& signal_child_added();
00126 
00127       sigc::signal<void, Drawable::pointer>& signal_child_removed();
00128 
00129       virtual bool is_group();
00130 
00131       PAPYRUS_CLASS_NAME("Group");
00132 
00133       PAPYRUS_CLONE_METHOD( Group );
00134 
00135     protected:
00136 
00137       // maintaining both items as list for drawing order and connections for quick access
00138       Children m_children;
00139       typedef std::map<Drawable::pointer, sigc::connection> Connections;
00140       Connections m_redraw_connections;
00141       Connections m_changed_connections;
00142 
00143       sigc::signal<void, Drawable::pointer> m_signal_child_added;
00144       sigc::signal<void, Drawable::pointer> m_signal_child_removed;
00145 
00156       virtual void on_child_changed( Drawable::pointer child );
00157 
00166       virtual void update_extents();
00167 
00168       void on_child_need_redraw( double x, double y, double w, double h, Drawable::pointer child );
00169       virtual void draw( Cairo::RefPtr<Cairo::Context> cairo );
00170 
00171       void rebuild_extents();
00172 
00173   };
00174 
00175 }
00176 
00177 #endif

Generated on Sun Jan 7 22:53:57 2007 by  doxygen 1.5.1