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 
00499       virtual bool inside ( double x, double y );
00500 
00508       void set_selectable ( bool selectable = true );
00509 
00514       bool is_selectable();
00515 
00517       virtual bool is_group();
00518 
00525       Viewbox::pointer viewbox();
00526 
00536       void set_viewbox ( Viewbox::pointer viewbox = Viewbox::pointer() );
00537 
00538       void set_viewbox(double x, double y, double w, double h,
00539                        Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00540                        Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00541 
00542       void set_viewbox(const Region& region,
00543                        Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00544                        Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00545 
00552       void set_viewbox ( const Viewbox& viewbox );
00553 
00555       sigc::signal<void, double, double, double, double>& signal_redraw();
00556 
00558       sigc::signal<void>& signal_selectable();
00559 
00561       sigc::signal<void>& signal_destroyed();
00562       
00564       sigc::signal<void,FrozenThawed>& signal_frozen();
00565 
00570       void reset_position();
00571 
00579       void redraw_proxy();
00580 
00581       virtual pointer clone() const = 0;
00582 
00583       operator pointer();
00584 
00585       pointer self();
00586 
00587       virtual Group* parent();
00588 
00589       PAPYRUS_CLASS_NAME ( "Drawable" );
00590 
00591     protected:
00592       weak_pointer m_self;
00593 
00594       Group* m_parent;
00595 
00596       MatrixMap m_matrices;
00597       
00598       MatrixConnMap m_matrix_connections;
00599       
00600       void on_matrix_changed();
00601 
00607       virtual Matrix calculate_composed_matrix() const;
00608       
00612       void apply_external_matrices( Matrix& m ) const;
00613 
00614       int m_composite_operator;
00615 
00616       bool m_visible;
00617       
00619       bool m_frozen;
00620       
00622       bool m_frozen_by_parent;
00623       
00625       bool m_need_redraw;
00626 
00628       bool m_selectable;
00629 
00633       Viewbox::pointer m_viewbox;
00634 
00635       sigc::connection m_viewbox_connection;
00636 
00637       void on_viewbox_changed();
00638 
00640       sigc::signal<void, double, double, double, double> m_signal_redraw;
00641 
00643       sigc::signal<void> m_signal_selectable;
00644 
00646       sigc::signal<void> m_signal_destroyed;
00647       
00649       sigc::signal<void,FrozenThawed> m_signal_frozen;
00650 
00651       friend class Group;
00652 
00660       virtual void redraw( );
00661 
00662       Glib::ustring svg_transform();
00663 
00664       static Cairo::RefPtr<Cairo::ImageSurface> m_sidebuffer_image;
00665 
00666       static Cairo::RefPtr<Cairo::Context> m_sidebuffer_cairo;
00667 
00673       bool m_exclude_from_extents;
00674 
00676       virtual Region calculate_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep = EXTENTS_QUICK) const;
00677 
00678       typedef enum RenderFlags {
00679         RENDER_FLAGS_NONE                  =0,
00680         RENDER_SUPPRESS_MATRIX             =1<<0, 
00681         RENDER_SUPPRESS_CAIRO_FILL         =1<<1, 
00682         RENDER_SUPPRESS_CAIRO_STROKE       =1<<2, 
00683         RENDER_SUPPRESS_CAIRO_SAVE_RESTORE =1<<3, 
00684       } RenderFlags;
00685 
00691       mutable uint16_t m_render_flags;
00692 
00694       bool is_render_flag_set( uint16_t flag ) const { return m_render_flags & flag; }
00695 
00704       void cairo_fill( Cairo::RefPtr<Cairo::Context> cairo ) const;
00705 
00714       void cairo_stroke( Cairo::RefPtr<Cairo::Context> cairo ) const;
00715 
00716       void invalidate_matrix();
00717 
00718       void invalidate_composed_matrix();
00719       
00720       void invalidate_extents();
00721 
00722     private:
00723       
00724       // These are private because any access needs
00725       // to invalidate the matrix
00726 
00728       double m_x;
00729 
00731       double m_y;
00732 
00734       double m_sx;
00735 
00737       double m_sy;
00738 
00740       double m_r;
00741 
00743       double m_skewx;
00744 
00746       double m_skewy;
00747 
00749       double m_centroid_x;
00750 
00752       double m_centroid_y;
00753 
00757        Matrix m_composed_matrix;
00758 
00762       bool m_composed_matrix_invalid;
00763       
00768       Matrix m_matrix;
00769 
00770       bool m_matrix_invalid;
00771 
00773       Region m_extents;
00774 
00775       bool m_extents_invalid;
00776 
00778       Region m_redraw_extents;
00779 
00781       Region m_pre_viewbox_extents;
00782 
00784       bool m_pre_viewbox_extents_invalid;
00785 
00786   };
00787 
00788   typedef std::map<Glib::ustring,Drawable::pointer> DrawableDictionary;
00789 
00790 
00791 
00792 #define EXTENTS_CHECKED_CAIRO_OP(x,y) x->y()
00793 
00794 }
00795 
00796 #endif

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