Papyrus::Drawable Class Reference

#include <papyrus/drawable.h>

Inheritance diagram for Papyrus::Drawable:

Inheritance graph
[legend]
List of all members.

Detailed Description

Papyrus::Drawable is the base class for objects capable of being drawn into a cairo context that also have spatial properties; ie affine transforms can be meaningfully applied to drawables.

It is the presence of meaningful affine transforms that differentiates Papyrus::Drawable from its parent Papyrus::Renderable.

However Papyrus::Drawable lacks a concept of filling and outlining which differentiates it from its child Papyrus::Shape.

This class provides a common interface for managing a transformation matrix that is applied before the object is drawn. These transformations include translation, scaling and shearing (skewing) in the x and y dimensions as well as rotation in the x-y plane.

This class implements the render method required of the parent renderable by pushing the current cairo state onto the cairo stack, applying any necessary transformation matrix, calling the pure virtual draw method, and popping the cairo stack to restore the state.

Since this class handles the matrices directly, children only need to override the draw method and draw themselves with a local coordinate frame reference.

When inheriting from Papyrus::Drawable you should provide a child specific implementation of the draw() method. You should probably also override the extents() method to return a Region object that is meaningful to your child, along with providing a child specific implementation of intersects(x,y) to provide a meaningful (and efficient) method of determining whether your child includes the point (x,y).

Author:
Rick L Vinyard Jr


Public Types

typedef PapyrusSmartPointer<
Drawable
pointer

Public Member Functions

 Drawable (double tx=0.0, double ty=0.0, double sx=1.0, double sy=1.0, double r=0.0)
 Constructor that sets initial transforms.
bool is_visible ()
void show ()
void hide ()
double get_translate_x ()
 X position where this Drawable will be drawn.
double get_translate_y ()
 Y position where this Drawable will be drawn.
void get_translate (double &tx, double &ty)
 (X,Y) position where this Drawable will be drawn
void set_translate_x (double tx)
 Sets the X position.
void set_translate_y (double ty)
 Sets the Y position.
void set_translate (double tx, double ty)
 Sets position to (X,Y).
void translate_x (double tx)
 Translates current position by tx.
void translate_y (double ty)
 Translates current position by ty.
void translate (double tx, double ty)
 Translate current position by (tx, ty).
double get_scale_x ()
 returns the current value of the x scaling
double get_scale_y ()
 returns the current value of the y scaling
void get_scale (double &sx, double &sy)
 convenience method to get scaling in x and y dimensions with a single function call
void set_scale_x (double sx)
 sets scaling in the x dimension and emits changed signal with parameter SCALE_X
void set_scale_y (double sy)
 sets scaling in the y dimension and emits changed signal with parameter SCALE_Y
void set_scale (double scale_x, double scale_y)
 sets scaling in the x and y dimensions and emits changed signal with one of parameters SCALE_X, SCALE_Y or SCALE_X|SCALE_Y
void set_scale (double s)
 sets scaling in the x and y dimensions and emits changed signal with parameter SCALE_X|SCALE_Y
void scale_x (double s)
 Scales the current x dimension by s and emits changed signal with parameter SCALE_X.
void scale_y (double s)
 Scales the current y dimension by s and emits changed signal with parameter SCALE_Y.
void scale (double s)
 Scales the current x and y dimensions by s and emits changed signal with parameter SCALE_X|SCALE_Y.
void scale (double scale_x, double scale_y)
 Scales the current x dimension by sx and the y dimension by sy and emits changed signal with one of parameters SCALE_X, SCALE_Y or SCALE_X|SCALE_Y.
double get_rotate ()
 Get rotation r in radians.
void set_rotate (double r)
 Rotate to r radians.
void rotate (double r)
 Rotate by r radians.
double get_skew_x ()
 Get x skewing angle in radians.
void set_skew_x (double skewx)
 Set x skewing angle in radians.
void skew_x (double skewx)
 Skew the Drawable in the x direction by skewx radians.
double get_skew_y ()
 Get y skewing angle in radians.
void set_skew_y (double skewy)
 Set y skewing angle in radians.
void skew_y (double skewy)
 Skew the Drawable in the y direction by skewy radians.
void get_skew (double &skewx, double &skewy)
 Get the x and y skewing angles.
void set_skew (double skewx, double skewy)
 Set the x and y skewing angles.
void skew (double s)
 Skew the x and y angles uniformly.
void skew (double skewx, double skewy)
 Skew the x and y angles independently.
double get_centroid_x ()
 Get centroid x position about which the Drawable is rotated.
void set_centroid_x (double centroid_x)
 Set the x value of the centroid about which the Drawable will be rotated.
double get_centroid_y ()
 Get centroid y position about which the Drawable is rotated.
void set_centroid_y (double centroid_y)
 Set the y value of the centroid about which the Drawable will be rotated.
void get_centroid (double &centroid_x, double &centroid_y)
 Get the (x,y) centroid about which the Drawable will be rotated.
void set_centroid (double centroid_x, double centroid_y)
 Set the (x,y) centroid about which the Drawable will be rotated.
void reset_position ()
 Reset position to default values of xy = (0,0), scale = (1,1), rotation = 0, and shear xy = (0,0).
const Cairo::Matrix & matrix ()
 Return the cairo matrix of this object with all transforms applied.
Cairo::Matrix global_matrix ()
 Returns the global matrix that will be applied to this drawable.
void global_to_local (double &x, double &y)
 Transform a global point to the drawable's local coordinates.
void local_to_global (double &x, double &y)
 Transform a local point to global coordinates.
void distance_global_to_local (double &x, double &y)
 Transform a global distance to the drawable's local coordinates.
void distance_local_to_global (double &x, double &y)
 Transform a local distance to global coordinates.
virtual void render (Cairo::RefPtr< Cairo::Context > cairo)
 Reimplemented render method from renderable.
virtual void draw (Cairo::RefPtr< Cairo::Context > cairo)=0
 Pure virtual draw method to be reimplemented by children.
virtual Regionextents ()
 Returns the extents of this drawable without applying the matrix formed from the affine transform methods translate*, scale* and rotate*.
virtual Region local_extents ()
virtual Region global_extents ()
 Returns the extents of this drawable that has been transformed by the matrix formed by the affine transform methods translate*, scale* and rotate*.
virtual Region extents_transformed (Cairo::Matrix &globalmatrix)
 Returns the extents of this drawable that has been transformed by a combined local and global matrix.
virtual bool inside (double x, double y)
 True if the point (x,y) is inside this Drawable's drawing area.
bool exclude_from_extents ()
void set_exclude_from_extents (bool b)
void set_selectable (bool selectable=true)
 Set to true if this Drawable will respond to the select method.
bool is_selectable ()
 True if this Drawable will respond to the select method, or false if it will not include itself in the select method.
virtual bool is_group ()
 True if this Drawable contains other drawables.
Viewbox::pointer viewbox ()
 Returns the viewbox associated with this Drawable.
void set_viewbox (Viewbox::pointer viewbox=Viewbox::pointer())
 Sets this Drawable's viewbox to the provided viewbox.
void set_viewbox (const Viewbox &viewbox)
 Sets this Drawable's viewbox to the provided viewbox.
sigc::signal< void, double,
double, double, double > 
signal_redraw ()
 Signal emitted with x,y,w,h values when this Drawable needs to be redrawn.
sigc::signal< void > signal_xy ()
 Signal emitted when the xy position is changed.
sigc::signal< void > signal_scale ()
 Signal emitted when the scale is changed.
sigc::signal< void > signal_rotation ()
 Signal emitted when the rotation value is changed.
sigc::signal< void > signal_skew ()
 Signal emitted when the skew is changed.
sigc::signal< void > signal_selectable ()
 Signal emitted when the selectable value is changed.
sigc::signal< void > signal_centroid ()
 Signal emitted when the centroid is changed.
void need_redraw_proxy ()
 This is a proxy for the virtual need_redraw() method.
virtual Drawable::pointer clone () const=0
virtual Groupparent ()
 PAPYRUS_CLASS_NAME ("Drawable")

Protected Member Functions

void recalculate_matrix ()
 Recalculates m_matrix if m_regenerate_matrix is true and sets m_regenerate_matrix to false; does nothing if m_regenerate_matrix is false.
virtual void need_redraw ()
 Convenience method that children can call and will take care of emitting the need redraw signal with the proper parameters.
virtual void set_extents (const Region &extents)
 To be used by children that need to set the extents.

Protected Attributes

Groupm_parent
Groupm_drawing_parent
bool m_visible
double m_tx
 x translation value
double m_ty
 y translation value
double m_sx
 x scaling value
double m_sy
 y scaling value
double m_r
 rotation value in radians
double m_skewx
 skew x angle in radians
double m_skewy
 skew y angle in radians
bool m_selectable
 whether the drawable is selectable
double m_centroid_x
 x centroid value
double m_centroid_y
 y centroid value
bool m_exclude_from_extents
Viewbox::pointer m_viewbox
 Pointer to a viewbox, which may be null if this Drawable doesn't have a viewbox.
sigc::connection m_viewbox_connection
bool m_regenerate_matrix
 True if the cairo matrix needs to be regenerated before rendering or returning from the matrix method.
Cairo::Matrix m_matrix
 The cairo matrix returned from matrix and used in rendering.
sigc::signal< void, double,
double, double, double > 
m_signal_redraw
 Signal emitted when this object has changed and needs to be redrawn.
sigc::signal< void > m_signal_xy
 Signal emitted when the xy position is changed.
sigc::signal< void > m_signal_scale
 Signal emitted when the scale is changed.
sigc::signal< void > m_signal_rotation
 Signal emitted when the rotation value is changed.
sigc::signal< void > m_signal_skew
 Signal emitted when the skew is changed.
sigc::signal< void > m_signal_selectable
 Signal emitted when the selectable value is changed.
sigc::signal< void > m_signal_centroid
 Signal emitted when the centroid is changed.

Friends

class Group


Constructor & Destructor Documentation

Papyrus::Drawable::Drawable ( double  tx = 0.0,
double  ty = 0.0,
double  sx = 1.0,
double  sy = 1.0,
double  r = 0.0 
)

Constructor that sets initial transforms.

If no parameters are specified, initial values set translation to (0,0) with a (1,1) scale ratio and no rotation or shearing.

If either scale parameter < 0.0, the parameter will be reset to 1.0.


Member Function Documentation

void Papyrus::Drawable::set_translate_x ( double  tx  ) 

Sets the X position.

If previous position was (px,py) new position is (tx,py).

void Papyrus::Drawable::set_translate_y ( double  ty  ) 

Sets the Y position.

If previous position was (px,py) new position is (px,ty).

void Papyrus::Drawable::set_translate ( double  tx,
double  ty 
)

Sets position to (X,Y).

Absolute move to (tx,ty).

void Papyrus::Drawable::translate_x ( double  tx  ) 

Translates current position by tx.

If previous position was (px,py) new position is (px+tx,py).

void Papyrus::Drawable::translate_y ( double  ty  ) 

Translates current position by ty.

If previous position was (px,py) new position is (px,py+ty).

void Papyrus::Drawable::translate ( double  tx,
double  ty 
)

Translate current position by (tx, ty).

If previous position was (px,py) new position is (px+tx, py+ty).

void Papyrus::Drawable::set_scale_x ( double  sx  ) 

sets scaling in the x dimension and emits changed signal with parameter SCALE_X

Parameters:
scale_x The new x dimension scaling; must be >= 0.0 or no change will occur

void Papyrus::Drawable::set_scale_y ( double  sy  ) 

sets scaling in the y dimension and emits changed signal with parameter SCALE_Y

Parameters:
scale_y The new y dimension scaling; must be >= 0.0 or no change will occur

void Papyrus::Drawable::set_scale ( double  scale_x,
double  scale_y 
)

sets scaling in the x and y dimensions and emits changed signal with one of parameters SCALE_X, SCALE_Y or SCALE_X|SCALE_Y

Parameters:
scale_x The new x dimension scaling; must be >= 0.0 or no change to x scaling will occur
scale_y The new y dimension scaling; must be >= 0.0 or no change to y scaling will occur

void Papyrus::Drawable::set_scale ( double  s  ) 

sets scaling in the x and y dimensions and emits changed signal with parameter SCALE_X|SCALE_Y

Parameters:
s The amount to scale the x and y dimensions by; must be >= 0.0 or no change will occur

void Papyrus::Drawable::scale_x ( double  s  ) 

Scales the current x dimension by s and emits changed signal with parameter SCALE_X.

Parameters:
s The amount to scale the x dimension by; must be >= 0.0 or no change will occur

void Papyrus::Drawable::scale_y ( double  s  ) 

Scales the current y dimension by s and emits changed signal with parameter SCALE_Y.

Parameters:
s The amount to scale the y dimension by; must be >= 0.0 or no change will occur

void Papyrus::Drawable::scale ( double  s  ) 

Scales the current x and y dimensions by s and emits changed signal with parameter SCALE_X|SCALE_Y.

Parameters:
s The amount to scale the x and y dimensions by; must be >= 0.0 or no change will occur

void Papyrus::Drawable::scale ( double  scale_x,
double  scale_y 
)

Scales the current x dimension by sx and the y dimension by sy and emits changed signal with one of parameters SCALE_X, SCALE_Y or SCALE_X|SCALE_Y.

Parameters:
scale_x The amount to scale the x dimension by; must be >= 0.0 or no change will occur
scale_y The amount to scale the y dimension by; must be >= 0.0 or no change will occur

void Papyrus::Drawable::rotate ( double  r  ) 

Rotate by r radians.

If previous rotation was pr then new rotation is pr+r

double Papyrus::Drawable::get_skew_x (  ) 

Get x skewing angle in radians.

The skew angle is used to implement a shearing transform with the shear value = tan(skewx).

void Papyrus::Drawable::set_skew_x ( double  skewx  ) 

Set x skewing angle in radians.

The skew angle is used to implement a shearing transform with the shear value = tan(skewx).

void Papyrus::Drawable::skew_x ( double  skewx  ) 

Skew the Drawable in the x direction by skewx radians.

If previous x skew angle was px, new skew angle is px+skewx.

double Papyrus::Drawable::get_skew_y (  ) 

Get y skewing angle in radians.

The skew angle is used to implement a shearing transform with the shear value = tan(skewy).

void Papyrus::Drawable::set_skew_y ( double  skewy  ) 

Set y skewing angle in radians.

The skew angle is used to implement a shearing transform with the shear value = tan(skewy).

void Papyrus::Drawable::skew_y ( double  skewy  ) 

Skew the Drawable in the y direction by skewy radians.

If previous y skew angle was py, new skew angle is py+skewy.

void Papyrus::Drawable::render ( Cairo::RefPtr< Cairo::Context >  cairo  )  [virtual]

Reimplemented render method from renderable.

Generally, children should reimplement the draw method rather than this method.

Performs the following actions: 1. Pushes cairo state onto the stack 2. Recalculates local matrix if necessary 3. Applies the local matrix to the current matrix 4. Calls the virtual draw method 5. Restores the cairo state

Implements Papyrus::Renderable.

Reimplemented in Papyrus::Text.

virtual void Papyrus::Drawable::draw ( Cairo::RefPtr< Cairo::Context >  cairo  )  [pure virtual]

Pure virtual draw method to be reimplemented by children.

This method is called by the supplied render method after the local transformation matrix has been applied to the cairo stack.

Implemented in Papyrus::Grid, and Papyrus::Shape.

Region & Papyrus::Drawable::extents (  )  [virtual]

Returns the extents of this drawable without applying the matrix formed from the affine transform methods translate*, scale* and rotate*.

Children should modify the member attribute m_extents as appropriate and generally shouldn't need to provide a polymorphic version of this method.

Region Papyrus::Drawable::global_extents (  )  [virtual]

Returns the extents of this drawable that has been transformed by the matrix formed by the affine transform methods translate*, scale* and rotate*.

Applies the local transformation matrix to the extents returned from the extents() method. The m_extents member is not used so that the extents() method may be overridden by a child and this method will still work as intended without also overriding this method.

virtual Region Papyrus::Drawable::extents_transformed ( Cairo::Matrix &  globalmatrix  )  [virtual]

Returns the extents of this drawable that has been transformed by a combined local and global matrix.

The local matrix is applied to the supplied parameter matrix, and this transform is in turn applied to the extents returned from extents().

The m_extents member is not used so that the extents() method may be overridden by a child and this method will still work as intended without also overriding this method.

void Papyrus::Drawable::set_selectable ( bool  selectable = true  ) 

Set to true if this Drawable will respond to the select method.

For example, it may not be desirable to have a group respond to the select method itself, and may instead pass the select(x,y) request to its children.

Viewbox::pointer Papyrus::Drawable::viewbox (  ) 

Returns the viewbox associated with this Drawable.

If no viewbox is associated, the pointer returned will be a null smart pointer.

void Papyrus::Drawable::set_viewbox ( Viewbox::pointer  viewbox = Viewbox::pointer()  ) 

Sets this Drawable's viewbox to the provided viewbox.

This method does not copy the viewbox, but will hold shared ownership of the shared smart pointer.

Calling set_viewbox() with no parameters sets the viewbox to a null pointer, thus removing it.

void Papyrus::Drawable::set_viewbox ( const Viewbox viewbox  ) 

Sets this Drawable's viewbox to the provided viewbox.

This method will not maintain a connection to the provided Viewbox, and will create its own copy.

void Papyrus::Drawable::need_redraw_proxy (  ) 

This is a proxy for the virtual need_redraw() method.

The changed signal of the viewbox is connected to this proxy that in turn calls the appropriate version of need_redraw(). HACK For some reason child Shape can't access this parent method when protected

void Papyrus::Drawable::need_redraw (  )  [protected, virtual]

Convenience method that children can call and will take care of emitting the need redraw signal with the proper parameters.

For efficiency, if a child needs less than a complete redraw the child could reimplement this method.

Reimplemented in Papyrus::Arc.

void Papyrus::Drawable::set_extents ( const Region extents  )  [protected, virtual]

To be used by children that need to set the extents.

Direct access is not allowed to ensure that children go through this method, which may be polymorphically implemented by children such as Shape.

Reimplemented in Papyrus::Bezierline, Papyrus::Polyline, and Papyrus::Shape.


The documentation for this class was generated from the following files:
Generated on Sun Mar 11 10:01:37 2007 by  doxygen 1.5.1