papyrus logo

drawable.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 PAPYRUSDRAWABLE_H
00021 #define PAPYRUSDRAWABLE_H
00022 
00023 #include <map>
00024 
00025 #include <papyrus/pointer.h>
00026 #include <papyrus/enums.h>
00027 #include <papyrus/utility.h>
00028 #include <papyrus/renderable.h>
00029 #include <papyrus/region.h>
00030 #include <papyrus/viewbox.h>
00031 #include <papyrus/matrix.h>
00032 
00033 namespace Papyrus
00034 {
00035 
00036   class Group;
00037 
00126   class Drawable : public Renderable
00127   {
00128     protected:
00129 
00138       Drawable ( const Glib::ustring& id=Glib::ustring(), double tx = 0.0, double ty = 0.0, double sx = 1.0, double sy = 1.0, double r = 0.0 );
00139 
00140     public:
00141       PAPYRUS_RENDERABLE(Drawable);
00142 
00143       virtual ~Drawable();
00144 
00145       virtual void set( const AttributeValueMap& avmap );
00146 
00147       bool is_visible() const;
00148 
00149       void show();
00150 
00151       void hide();
00152 
00153       double alpha() const;
00154 
00155       void set_alpha( double a );
00156       
00158       double x() const;
00159 
00165       void set_x( double x );
00166 
00168       double y() const;
00169 
00175       void set_y( double y );
00176 
00178       void get_xy( double& x, double& y );
00179 
00183       void set_xy( double x, double y );
00184 
00190       void translate ( double tx, double ty );
00191 
00193       void get_scale( double& sx, double& sy );
00194 
00196       double get_scale_x() const;
00197 
00199       double get_scale_y() const;
00200 
00205       void set_scale_x( double sx );
00206 
00211       void set_scale_y( double sy );
00212       
00219       void set_scale( double scale_x, double scale_y );
00220 
00226       void set_scale( double s );
00227 
00233       void scale ( double s );
00234 
00241       void scale ( double scale_x, double scale_y );
00242 
00244       double get_rotation(DegRad unit=RADIANS) const;
00245 
00247       void set_rotation( double r, DegRad unit=RADIANS );
00248 
00254       void rotate ( double r, DegRad unit=RADIANS );
00255 
00257       void get_skew ( double& skewx, double& skewy, DegRad unit=RADIANS );
00258 
00260       double get_skew_x(DegRad unit=RADIANS) const;
00261 
00263       double get_skew_y(DegRad unit=RADIANS) const;
00264 
00266       void set_skew_x ( double skewx, DegRad unit=RADIANS );
00267 
00269       void set_skew_y ( double skewy, DegRad unit=RADIANS );
00270 
00272       void set_skew ( double skewx, double skewy, DegRad unit=RADIANS );
00273 
00275       void set_skew ( double s, DegRad unit=RADIANS );
00276 
00278       void skew ( double x, double y, DegRad unit=RADIANS );
00279 
00281       void skew ( double s, DegRad unit=RADIANS );
00282 
00284       double centroid_x() const;
00285 
00287       void set_centroid_x ( double centroid_x );
00288 
00290       double centroid_y() const;
00291 
00293       void set_centroid_y ( double centroid_y );
00294 
00296       void get_centroid ( double& centroid_x, double& centroid_y );
00297 
00299       void set_centroid ( double centroid_x, double centroid_y );
00300 
00302       const Matrix& matrix() const;
00303       
00313       const Matrix& composed_matrix() const;
00314 
00315       typedef std::list<Matrix::pointer> MatrixList;
00316       typedef std::map<int,MatrixList> MatrixMap;
00317       
00324       struct CountedConnection {
00325         CountedConnection(): count(0) { }
00326         sigc::connection connection;
00327         unsigned int count;
00328       };
00329         
00337       typedef std::map<Matrix::pointer, CountedConnection> MatrixConnMap;
00338       
00348       void add_matrix( const Matrix::pointer m, int level=0 );
00349       
00351       void remove_matrix( const Matrix::pointer m );
00352       
00358       void remove_matrix( const Matrix::pointer m, int level );
00359       
00361       const MatrixMap& matrices();
00362       
00368       const MatrixConnMap& matrix_connection_map();
00369 
00371       virtual Matrix global_matrix() const;
00372 
00374       void global_to_local ( double& x, double& y ) const;
00375 
00377       void local_to_global ( double& x, double& y ) const;
00378 
00380       void distance_global_to_local ( double& x, double& y ) const;
00381 
00383       void distance_local_to_global ( double& x, double& y ) const;
00384 
00398       virtual void render ( Context& cairo ) const;
00399 
00406       virtual void render( Context& cairo, double x, double y, double w, double h ) const;
00407       
00414       virtual void draw( Context& cairo ) const = 0;
00415       
00425       virtual void freeze();
00426       
00436       virtual void thaw(bool force_redraw=false);
00437 
00439       bool is_frozen();
00440       
00445       int composite_operator();
00446 
00448       void set_composite_operator ( Cairo::Operator op );
00449 
00459       void clear_composite_operator();
00460 
00466       virtual Region extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep=EXTENTS_QUICK) const;
00467 
00469       virtual Region pre_viewbox_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep=EXTENTS_QUICK) const;
00470 
00472       virtual Region raw_extents() const;
00473 
00475       virtual Region global_extents() const;
00476 
00490       bool exclude_from_extents();
00491 
00493       void set_exclude_from_extents ( bool b=true );
00494 
00496       virtual Region calculate_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep = EXTENTS_QUICK) const;
00497 
00501       void apply_external_matrices( Matrix& m ) const;
00502 
00506       virtual bool inside ( double x, double y );
00507 
00515       void set_selectable ( bool selectable = true );
00516 
00521       bool is_selectable();
00522 
00524       virtual bool is_group();
00525 
00532       Viewbox::pointer viewbox();
00533 
00543       void set_viewbox ( Viewbox::pointer viewbox = Viewbox::pointer() );
00544 
00545       void set_viewbox(double x, double y, double w, double h,
00546                        Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00547                        Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00548 
00549       void set_viewbox(const Region& region,
00550                        Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00551                        Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00552 
00559       void set_viewbox ( const Viewbox& viewbox );
00560 
00562       sigc::signal<void, double, double, double, double>& signal_redraw();
00563 
00565       sigc::signal<void>& signal_selectable();
00566 
00568       sigc::signal<void>& signal_destroyed();
00569       
00571       sigc::signal<void,FrozenThawed>& signal_frozen();
00572 
00574       sigc::signal<void>& signal_composed_matrix_invalidated();
00575 
00577       sigc::signal<void>& signal_extents_changed();
00578       
00583       void reset_position();
00584 
00592       void redraw_proxy();
00593 
00594       virtual pointer clone() const = 0;
00595 
00596       operator pointer();
00597 
00598       pointer self();
00599 
00600       virtual Group* parent();
00601 
00602     protected:
00603       weak_pointer m_self;
00604 
00605       Group* m_parent;
00606 
00607       MatrixMap m_matrices;
00608       
00609       MatrixConnMap m_matrix_connections;
00610       
00611       void on_matrix_changed();
00612 
00618       virtual Matrix calculate_composed_matrix() const;
00619       
00620       int m_composite_operator;
00621 
00622       bool m_visible;
00623 
00624       double m_alpha;
00625       
00627       bool m_frozen;
00628       
00630       bool m_frozen_by_parent;
00631       
00633       bool m_need_redraw;
00634 
00636       bool m_selectable;
00637 
00641       Viewbox::pointer m_viewbox;
00642 
00643       sigc::connection m_viewbox_connection;
00644 
00645       void on_viewbox_changed();
00646 
00648       sigc::signal<void, double, double, double, double> m_signal_redraw;
00649 
00651       sigc::signal<void> m_signal_selectable;
00652 
00654       sigc::signal<void> m_signal_destroyed;
00655       
00657       sigc::signal<void,FrozenThawed> m_signal_frozen;
00658       
00660       sigc::signal<void> m_signal_composed_matrix_invalidated;
00661 
00663       sigc::signal<void> m_signal_extents_changed;
00664 
00665       friend class Group;
00666 
00674       virtual void redraw( );
00675 
00676       Glib::ustring svg_transform();
00677 
00678       static Cairo::RefPtr<Cairo::ImageSurface> m_sidebuffer_image;
00679 
00680       static Context m_sidebuffer_cairo;
00681 
00687       bool m_exclude_from_extents;
00688 
00689       void invalidate_matrix();
00690 
00691       void invalidate_composed_matrix();
00692       
00693       void invalidate_extents();
00694 
00695     private:
00696       
00697       // These are private because any access needs
00698       // to invalidate the matrix through invalidate_matrix()
00699       // and invalidate_composed_matrix() to ensure everything
00700       // gets set properly and the signal is emitted
00701 
00703       double m_x;
00704 
00706       double m_y;
00707 
00709       double m_sx;
00710 
00712       double m_sy;
00713 
00715       double m_r;
00716 
00718       double m_skewx;
00719 
00721       double m_skewy;
00722 
00724       double m_centroid_x;
00725 
00727       double m_centroid_y;
00728 
00732        Matrix m_composed_matrix;
00733 
00737       bool m_composed_matrix_invalid;
00738       
00743       Matrix m_matrix;
00744 
00745       bool m_matrix_invalid;
00746 
00748       Region m_extents;
00749 
00750       bool m_extents_invalid;
00751 
00753       Region m_redraw_extents;
00754 
00756       Region m_pre_viewbox_extents;
00757 
00759       bool m_pre_viewbox_extents_invalid;
00760 
00761   };
00762 
00763   typedef std::map<Glib::ustring,Drawable::pointer> DrawableDictionary;
00764 
00765 
00766 
00767 #define EXTENTS_CHECKED_CAIRO_OP(x,y) x->y()
00768 
00769 }
00770 
00771 #endif

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