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 
00142       typedef PapyrusPointer<Drawable> pointer;
00143 
00144       typedef PapyrusPointer<const Drawable> const_pointer;
00145 
00146       typedef PapyrusWeakPointer<Drawable> weak_pointer;
00147 
00148       virtual ~Drawable();
00149 
00150       virtual void set( const AttributeValueMap& avmap );
00151 
00152       bool is_visible();
00153 
00154       void show();
00155 
00156       void hide();
00157       
00159       double x() const;
00160 
00166       void set_x( double x );
00167 
00169       double y() const;
00170 
00176       void set_y( double y );
00177 
00179       void get_xy( double& x, double& y );
00180 
00184       void set_xy( double x, double y );
00185 
00191       void translate ( double tx, double ty );
00192 
00194       void get_scale( double& sx, double& sy );
00195 
00197       double get_scale_x() const;
00198 
00200       double get_scale_y() const;
00201 
00206       void set_scale_x( double sx );
00207 
00212       void set_scale_y( double sy );
00213       
00220       void set_scale( double scale_x, double scale_y );
00221 
00227       void set_scale( double s );
00228 
00234       void scale ( double s );
00235 
00242       void scale ( double scale_x, double scale_y );
00243 
00245       double get_rotation(DegRad unit=RADIANS) const;
00246 
00248       void set_rotation( double r, DegRad unit=RADIANS );
00249 
00255       void rotate ( double r, DegRad unit=RADIANS );
00256 
00258       void get_skew ( double& skewx, double& skewy, DegRad unit=RADIANS );
00259 
00261       double get_skew_x(DegRad unit=RADIANS) const;
00262 
00264       double get_skew_y(DegRad unit=RADIANS) const;
00265 
00267       void set_skew_x ( double skewx, DegRad unit=RADIANS );
00268 
00270       void set_skew_y ( double skewy, DegRad unit=RADIANS );
00271 
00273       void set_skew ( double skewx, double skewy, DegRad unit=RADIANS );
00274 
00276       void set_skew ( double s, DegRad unit=RADIANS );
00277 
00279       void skew ( double x, double y, DegRad unit=RADIANS );
00280 
00282       void skew ( double s, DegRad unit=RADIANS );
00283 
00285       double centroid_x() const;
00286 
00288       void set_centroid_x ( double centroid_x );
00289 
00291       double centroid_y() const;
00292 
00294       void set_centroid_y ( double centroid_y );
00295 
00297       void get_centroid ( double& centroid_x, double& centroid_y );
00298 
00300       void set_centroid ( double centroid_x, double centroid_y );
00301 
00303       const Matrix& matrix() const;
00304       
00314       const Matrix& composed_matrix() const;
00315 
00316       typedef std::list<Matrix::pointer> MatrixList;
00317       typedef std::map<int,MatrixList> MatrixMap;
00318       
00325       struct CountedConnection {
00326         CountedConnection(): count(0) { }
00327         sigc::connection connection;
00328         unsigned int count;
00329       };
00330         
00338       typedef std::map<Matrix::pointer, CountedConnection> MatrixConnMap;
00339       
00349       void add_matrix( const Matrix::pointer m, int level=0 );
00350       
00352       void remove_matrix( const Matrix::pointer m );
00353       
00359       void remove_matrix( const Matrix::pointer m, int level );
00360       
00362       const MatrixMap& matrices();
00363       
00369       const MatrixConnMap& matrix_connection_map();
00370 
00372       virtual Matrix global_matrix() const;
00373 
00375       void global_to_local ( double& x, double& y );
00376 
00378       void local_to_global ( double& x, double& y );
00379 
00381       void distance_global_to_local ( double& x, double& y );
00382 
00384       void distance_local_to_global ( double& x, double& y );
00385 
00399       virtual void render ( Cairo::RefPtr<Cairo::Context> cairo ) const;
00400 
00407       virtual void render( Cairo::RefPtr<Cairo::Context> cairo, double x, double y, double w, double h ) const;
00408       
00415       virtual void draw ( Cairo::RefPtr<Cairo::Context> cairo ) const = 0;
00416       
00426       virtual void freeze();
00427       
00437       virtual void thaw(bool force_redraw=false);
00438 
00440       bool is_frozen();
00441       
00446       int composite_operator();
00447 
00449       void set_composite_operator ( Cairo::Operator op );
00450 
00460       void clear_composite_operator();
00461 
00467       virtual Region extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep=EXTENTS_QUICK) const;
00468 
00470       virtual Region pre_viewbox_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep=EXTENTS_QUICK) const;
00471 
00473       virtual Region raw_extents() const;
00474 
00476       virtual Region global_extents() const;
00477 
00491       bool exclude_from_extents();
00492 
00494       void set_exclude_from_extents ( bool b=true );
00495 
00497       virtual Region calculate_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep = EXTENTS_QUICK) const;
00498 
00502       void apply_external_matrices( Matrix& m ) const;
00503 
00507       virtual bool inside ( double x, double y );
00508 
00516       void set_selectable ( bool selectable = true );
00517 
00522       bool is_selectable();
00523 
00525       virtual bool is_group();
00526 
00533       Viewbox::pointer viewbox();
00534 
00544       void set_viewbox ( Viewbox::pointer viewbox = Viewbox::pointer() );
00545 
00546       void set_viewbox(double x, double y, double w, double h,
00547                        Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00548                        Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00549 
00550       void set_viewbox(const Region& region,
00551                        Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00552                        Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00553 
00560       void set_viewbox ( const Viewbox& viewbox );
00561 
00563       sigc::signal<void, double, double, double, double>& signal_redraw();
00564 
00566       sigc::signal<void>& signal_selectable();
00567 
00569       sigc::signal<void>& signal_destroyed();
00570       
00572       sigc::signal<void,FrozenThawed>& signal_frozen();
00573 
00575       sigc::signal<void>& signal_composed_matrix_invalidated();
00576       
00581       void reset_position();
00582 
00590       void redraw_proxy();
00591 
00592       virtual pointer clone() const = 0;
00593 
00594       operator pointer();
00595 
00596       pointer self();
00597 
00598       virtual Group* parent();
00599 
00600       PAPYRUS_CLASS_NAME ( "Drawable" );
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       
00625       bool m_frozen;
00626       
00628       bool m_frozen_by_parent;
00629       
00631       bool m_need_redraw;
00632 
00634       bool m_selectable;
00635 
00639       Viewbox::pointer m_viewbox;
00640 
00641       sigc::connection m_viewbox_connection;
00642 
00643       void on_viewbox_changed();
00644 
00646       sigc::signal<void, double, double, double, double> m_signal_redraw;
00647 
00649       sigc::signal<void> m_signal_selectable;
00650 
00652       sigc::signal<void> m_signal_destroyed;
00653       
00655       sigc::signal<void,FrozenThawed> m_signal_frozen;
00656       
00658       sigc::signal<void> m_signal_composed_matrix_invalidated;
00659 
00660       friend class Group;
00661 
00669       virtual void redraw( );
00670 
00671       Glib::ustring svg_transform();
00672 
00673       static Cairo::RefPtr<Cairo::ImageSurface> m_sidebuffer_image;
00674 
00675       static Cairo::RefPtr<Cairo::Context> m_sidebuffer_cairo;
00676 
00682       bool m_exclude_from_extents;
00683 
00684       typedef enum RenderFlags {
00685         RENDER_FLAGS_NONE                  =0,
00686         RENDER_SUPPRESS_MATRIX             =1<<0, 
00687         RENDER_SUPPRESS_CAIRO_FILL         =1<<1, 
00688         RENDER_SUPPRESS_CAIRO_STROKE       =1<<2, 
00689         RENDER_SUPPRESS_CAIRO_SAVE_RESTORE =1<<3, 
00690       } RenderFlags;
00691 
00697       mutable uint16_t m_render_flags;
00698 
00700       bool is_render_flag_set( uint16_t flag ) const { return m_render_flags & flag; }
00701 
00710       void cairo_fill( Cairo::RefPtr<Cairo::Context> cairo ) const;
00711 
00720       void cairo_stroke( Cairo::RefPtr<Cairo::Context> cairo ) const;
00721 
00722       void invalidate_matrix();
00723 
00724       void invalidate_composed_matrix();
00725       
00726       void invalidate_extents();
00727 
00728     private:
00729       
00730       // These are private because any access needs
00731       // to invalidate the matrix through invalidate_matrix()
00732       // and invalidate_composed_matrix() to ensure everything
00733       // gets set properly and the signal is emitted
00734 
00736       double m_x;
00737 
00739       double m_y;
00740 
00742       double m_sx;
00743 
00745       double m_sy;
00746 
00748       double m_r;
00749 
00751       double m_skewx;
00752 
00754       double m_skewy;
00755 
00757       double m_centroid_x;
00758 
00760       double m_centroid_y;
00761 
00765        Matrix m_composed_matrix;
00766 
00770       bool m_composed_matrix_invalid;
00771       
00776       Matrix m_matrix;
00777 
00778       bool m_matrix_invalid;
00779 
00781       Region m_extents;
00782 
00783       bool m_extents_invalid;
00784 
00786       Region m_redraw_extents;
00787 
00789       Region m_pre_viewbox_extents;
00790 
00792       bool m_pre_viewbox_extents_invalid;
00793 
00794   };
00795 
00796   typedef std::map<Glib::ustring,Drawable::pointer> DrawableDictionary;
00797 
00798 
00799 
00800 #define EXTENTS_CHECKED_CAIRO_OP(x,y) x->y()
00801 
00802 }
00803 
00804 #endif

Generated on Thu May 14 10:12:35 2009 for papyrus by doxygen 1.5.7.1