00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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() const;
00153
00154 void show();
00155
00156 void hide();
00157
00158 double alpha() const;
00159
00160 void set_alpha( double a );
00161
00163 double x() const;
00164
00170 void set_x( double x );
00171
00173 double y() const;
00174
00180 void set_y( double y );
00181
00183 void get_xy( double& x, double& y );
00184
00188 void set_xy( double x, double y );
00189
00195 void translate ( double tx, double ty );
00196
00198 void get_scale( double& sx, double& sy );
00199
00201 double get_scale_x() const;
00202
00204 double get_scale_y() const;
00205
00210 void set_scale_x( double sx );
00211
00216 void set_scale_y( double sy );
00217
00224 void set_scale( double scale_x, double scale_y );
00225
00231 void set_scale( double s );
00232
00238 void scale ( double s );
00239
00246 void scale ( double scale_x, double scale_y );
00247
00249 double get_rotation(DegRad unit=RADIANS) const;
00250
00252 void set_rotation( double r, DegRad unit=RADIANS );
00253
00259 void rotate ( double r, DegRad unit=RADIANS );
00260
00262 void get_skew ( double& skewx, double& skewy, DegRad unit=RADIANS );
00263
00265 double get_skew_x(DegRad unit=RADIANS) const;
00266
00268 double get_skew_y(DegRad unit=RADIANS) const;
00269
00271 void set_skew_x ( double skewx, DegRad unit=RADIANS );
00272
00274 void set_skew_y ( double skewy, DegRad unit=RADIANS );
00275
00277 void set_skew ( double skewx, double skewy, DegRad unit=RADIANS );
00278
00280 void set_skew ( double s, DegRad unit=RADIANS );
00281
00283 void skew ( double x, double y, DegRad unit=RADIANS );
00284
00286 void skew ( double s, DegRad unit=RADIANS );
00287
00289 double centroid_x() const;
00290
00292 void set_centroid_x ( double centroid_x );
00293
00295 double centroid_y() const;
00296
00298 void set_centroid_y ( double centroid_y );
00299
00301 void get_centroid ( double& centroid_x, double& centroid_y );
00302
00304 void set_centroid ( double centroid_x, double centroid_y );
00305
00307 const Matrix& matrix() const;
00308
00318 const Matrix& composed_matrix() const;
00319
00320 typedef std::list<Matrix::pointer> MatrixList;
00321 typedef std::map<int,MatrixList> MatrixMap;
00322
00329 struct CountedConnection {
00330 CountedConnection(): count(0) { }
00331 sigc::connection connection;
00332 unsigned int count;
00333 };
00334
00342 typedef std::map<Matrix::pointer, CountedConnection> MatrixConnMap;
00343
00353 void add_matrix( const Matrix::pointer m, int level=0 );
00354
00356 void remove_matrix( const Matrix::pointer m );
00357
00363 void remove_matrix( const Matrix::pointer m, int level );
00364
00366 const MatrixMap& matrices();
00367
00373 const MatrixConnMap& matrix_connection_map();
00374
00376 virtual Matrix global_matrix() const;
00377
00379 void global_to_local ( double& x, double& y ) const;
00380
00382 void local_to_global ( double& x, double& y ) const;
00383
00385 void distance_global_to_local ( double& x, double& y ) const;
00386
00388 void distance_local_to_global ( double& x, double& y ) const;
00389
00403 virtual void render ( Cairo::RefPtr<Cairo::Context> cairo ) const;
00404
00411 virtual void render( Cairo::RefPtr<Cairo::Context> cairo, double x, double y, double w, double h ) const;
00412
00419 virtual void draw ( Cairo::RefPtr<Cairo::Context> cairo ) const = 0;
00420
00430 virtual void freeze();
00431
00441 virtual void thaw(bool force_redraw=false);
00442
00444 bool is_frozen();
00445
00450 int composite_operator();
00451
00453 void set_composite_operator ( Cairo::Operator op );
00454
00464 void clear_composite_operator();
00465
00471 virtual Region extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep=EXTENTS_QUICK) const;
00472
00474 virtual Region pre_viewbox_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep=EXTENTS_QUICK) const;
00475
00477 virtual Region raw_extents() const;
00478
00480 virtual Region global_extents() const;
00481
00495 bool exclude_from_extents();
00496
00498 void set_exclude_from_extents ( bool b=true );
00499
00501 virtual Region calculate_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep = EXTENTS_QUICK) const;
00502
00506 void apply_external_matrices( Matrix& m ) const;
00507
00511 virtual bool inside ( double x, double y );
00512
00520 void set_selectable ( bool selectable = true );
00521
00526 bool is_selectable();
00527
00529 virtual bool is_group();
00530
00537 Viewbox::pointer viewbox();
00538
00548 void set_viewbox ( Viewbox::pointer viewbox = Viewbox::pointer() );
00549
00550 void set_viewbox(double x, double y, double w, double h,
00551 Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00552 Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00553
00554 void set_viewbox(const Region& region,
00555 Viewbox::ALIGN align=Viewbox::ALIGN_XMAX_YMAX,
00556 Viewbox::MEET_OR_SLICE meet_or_slice = Viewbox::MEET);
00557
00564 void set_viewbox ( const Viewbox& viewbox );
00565
00567 sigc::signal<void, double, double, double, double>& signal_redraw();
00568
00570 sigc::signal<void>& signal_selectable();
00571
00573 sigc::signal<void>& signal_destroyed();
00574
00576 sigc::signal<void,FrozenThawed>& signal_frozen();
00577
00579 sigc::signal<void>& signal_composed_matrix_invalidated();
00580
00582 sigc::signal<void>& signal_extents_changed();
00583
00588 void reset_position();
00589
00597 void redraw_proxy();
00598
00599 virtual pointer clone() const = 0;
00600
00601 operator pointer();
00602
00603 pointer self();
00604
00605 virtual Group* parent();
00606
00607 PAPYRUS_CLASS_NAME ( "Drawable" );
00608
00609 protected:
00610 weak_pointer m_self;
00611
00612 Group* m_parent;
00613
00614 MatrixMap m_matrices;
00615
00616 MatrixConnMap m_matrix_connections;
00617
00618 void on_matrix_changed();
00619
00625 virtual Matrix calculate_composed_matrix() const;
00626
00627 int m_composite_operator;
00628
00629 bool m_visible;
00630
00631 double m_alpha;
00632
00634 bool m_frozen;
00635
00637 bool m_frozen_by_parent;
00638
00640 bool m_need_redraw;
00641
00643 bool m_selectable;
00644
00648 Viewbox::pointer m_viewbox;
00649
00650 sigc::connection m_viewbox_connection;
00651
00652 void on_viewbox_changed();
00653
00655 sigc::signal<void, double, double, double, double> m_signal_redraw;
00656
00658 sigc::signal<void> m_signal_selectable;
00659
00661 sigc::signal<void> m_signal_destroyed;
00662
00664 sigc::signal<void,FrozenThawed> m_signal_frozen;
00665
00667 sigc::signal<void> m_signal_composed_matrix_invalidated;
00668
00670 sigc::signal<void> m_signal_extents_changed;
00671
00672 friend class Group;
00673
00681 virtual void redraw( );
00682
00683 Glib::ustring svg_transform();
00684
00685 static Cairo::RefPtr<Cairo::ImageSurface> m_sidebuffer_image;
00686
00687 static Cairo::RefPtr<Cairo::Context> m_sidebuffer_cairo;
00688
00694 bool m_exclude_from_extents;
00695
00696 typedef enum RenderFlags {
00697 RENDER_FLAGS_NONE =0,
00698 RENDER_SUPPRESS_MATRIX =1<<0,
00699 RENDER_SUPPRESS_CAIRO_FILL =1<<1,
00700 RENDER_SUPPRESS_CAIRO_STROKE =1<<2,
00701 RENDER_SUPPRESS_CAIRO_SAVE_RESTORE =1<<3,
00702 } RenderFlags;
00703
00709 mutable uint16_t m_render_flags;
00710
00712 bool is_render_flag_set( uint16_t flag ) const { return m_render_flags & flag; }
00713
00722 void cairo_fill( Cairo::RefPtr<Cairo::Context> cairo ) const;
00723
00732 void cairo_paint( Cairo::RefPtr<Cairo::Context> cairo ) const;
00733
00742 void cairo_paint_with_alpha( Cairo::RefPtr<Cairo::Context> cairo, double alpha ) const;
00743
00752 void cairo_stroke( Cairo::RefPtr<Cairo::Context> cairo ) const;
00753
00754 void invalidate_matrix();
00755
00756 void invalidate_composed_matrix();
00757
00758 void invalidate_extents();
00759
00760 private:
00761
00762
00763
00764
00765
00766
00768 double m_x;
00769
00771 double m_y;
00772
00774 double m_sx;
00775
00777 double m_sy;
00778
00780 double m_r;
00781
00783 double m_skewx;
00784
00786 double m_skewy;
00787
00789 double m_centroid_x;
00790
00792 double m_centroid_y;
00793
00797 Matrix m_composed_matrix;
00798
00802 bool m_composed_matrix_invalid;
00803
00808 Matrix m_matrix;
00809
00810 bool m_matrix_invalid;
00811
00813 Region m_extents;
00814
00815 bool m_extents_invalid;
00816
00818 Region m_redraw_extents;
00819
00821 Region m_pre_viewbox_extents;
00822
00824 bool m_pre_viewbox_extents_invalid;
00825
00826 };
00827
00828 typedef std::map<Glib::ustring,Drawable::pointer> DrawableDictionary;
00829
00830
00831
00832 #define EXTENTS_CHECKED_CAIRO_OP(x,y) x->y()
00833
00834 }
00835
00836 #endif