Laxkit  0.0.7.1
Public Member Functions | Protected Member Functions | Protected Attributes
Laxkit::DisplayerCairo Class Reference

Displayer based on Cairo. More...

Inheritance diagram for Laxkit::DisplayerCairo:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 DisplayerCairo (anXWindow *nxw=NULL, PanController *pan=NULL)
virtual ~DisplayerCairo ()
 Dec count on cr and surface if they are not null.
virtual Displayerduplicate ()
virtual cairo_t * GetCairo ()
Window and Xlib specific helper functions:
virtual Display * GetDpy ()
Buffer Management
virtual void SwapBuffers ()
virtual void BackBuffer (int on)
virtual void WrapWindow (anXWindow *nw)
virtual int StartDrawing (aDrawable *buffer)
 This sets up internals for drawing onto buffer, and wraps window if the min/max seem to not be set.
virtual int MakeCurrent (aDrawable *buffer)
 Make sure we are drawing on the proper surface.
virtual int ClearDrawable (aDrawable *drawable)
 Free any data associated with drawable.
virtual int CreateSurface (int w, int h, int type=-1)
 Remove old surface, and create a fresh surface to perform drawing operations on.
virtual int ResizeSurface (int width, int height)
 Resize an internal drawing surface.
virtual LaxImageGetSurface ()
virtual int EndDrawing ()
 Free any resources allocated for drawing in this object.
State
virtual unsigned long NewFG (double r, double g, double b, double a=1.0)
 Set new foreground color. Typically usage is NewFG(.5,.8,0,1.0).
virtual unsigned long NewFG (unsigned long ncol)
 Set new foreground. Typically usage is NewFG(app->rgbcolor(23,34,234)).
virtual unsigned long NewFG (ScreenColor *col)
 Set new foreground. Color components are 0..0xffff.
virtual unsigned long NewFG (int r, int g, int b, int a=255)
 Set new foreground. Typically usage is NewFG(app->rgbcolor(23,34,234)).
virtual unsigned long NewBG (double r, double g, double b)
 Set new background color. Typically usage is NewFG(app->rgbcolor(.5,.8,0)).
virtual unsigned long NewBG (int r, int g, int b)
 Set new background. Typically usage is NewBG(app->rgbcolor(23,34,234)).
virtual unsigned long NewBG (unsigned long nc)
 Set new background. Typically usage is NewBG(app->rgbcolor(23,34,234)).
virtual unsigned long FG ()
virtual unsigned long BG ()
virtual void LineAttributes (double width, int dash, int cap, int join)
 Set the width, whether solid, line cap and join.
virtual void FillAttributes (int fillstyle, int fillrule)
virtual LaxCompositeOp BlendMode (LaxCompositeOp mode)
virtual void setCairoBlendMode (cairo_operator_t mode)
 Set how the source is blended onto the destination.
Main drawing functions:
virtual void ClearWindow ()
 Clear the window to bgcolor between Min* and Max*.
virtual flatpoint realtoscreen (flatpoint p)
 Convert real point p to screen coordinates.
virtual flatpoint realtoscreen (double x, double y)
 Convert real point (x,y) to screen coordinates.
virtual flatpoint screentoreal (int x, int y)
 Convert screen point (x,y) to real coordinates.
virtual flatpoint screentoreal (flatpoint p)
 Convert screen point to real coordinates.
virtual int Clip (flatpoint *p, int n, int append)
 Install a clip mask from a polyline (line is automatically closed)
virtual void PushClip (int startfresh)
 Push the current clip mask onto a stack, make a new one maybe.
virtual void PopClip ()
 Restore a previous mask.
virtual void ClearClip ()
 Remove any mask.
virtual int activeMask ()
 Return whether there is an active mask.
virtual void DrawOnMask ()
 Drawing operations following a call here will operate on the mask surface.
virtual void DrawOnSrc ()
 Drawing operations following a call here will operate on the main surface.
virtual void show ()
 Flush any waiting composite operation, ie collapse source through mask onto surface.
virtual void fill (int preserve)
 Draw out current path if any.
virtual void stroke (int preserve)
 Draw out current path if any.
virtual void moveto (flatpoint p)
virtual void lineto (flatpoint p)
virtual void curveto (flatpoint c1, flatpoint c2, flatpoint v)
 Add a cubic bezier segment to the current path.
virtual void closed ()
 Call if current path should be closed, and close at the last added point.
virtual void closeopen ()
 Call if current path should be ended, but not closed.
virtual void drawpixel (flatpoint p)
 Draw one pixel at coord p.
virtual void drawpoint (double x, double y, double radius, int tofill)
 Draw optionally filled circle with screen radius r, at (x,y).
virtual void drawlines (flatpoint *points, int npoints, char isclosed, char tofill)
 Draw a polygon, optionally fill.
virtual void drawline (flatpoint p1, flatpoint p2)
virtual void drawline (double ax, double ay, double bx, double by)
virtual void initFont ()
virtual int textheight ()
virtual int font (LaxFont *nfont, double size=-1)
virtual int font (const char *fontconfigpattern)
virtual int font (const char *family, const char *style, double pixelsize)
virtual int fontsize (double size)
virtual double textextent (LaxFont *thisfont, const char *str, int len, double *width, double *height, double *ascent, double *descent, char real)
virtual double textout (double x, double y, const char *str, int len=0, unsigned long align=LAX_CENTER)
 Draw a single line of text at x,y.
virtual double textout (double *matrix, double x, double y, const char *str, int len=0, unsigned long align=LAX_CENTER)
virtual double textout (double angle, double x, double y, const char *str, int len=0, unsigned long align=LAX_CENTER)
virtual void imageout (LaxImage *img, double x, double y)
virtual int imageout (LaxImage *img, double x, double y, double w, double h)
virtual void imageout (LaxImage *img, double *matrix)
virtual void imageout (LaxImage *img, double angle, double x, double y)
virtual void imageout_rotated (LaxImage *img, double x, double y, double ulx, double uly)
virtual void imageout_skewed (LaxImage *img, double x, double y, double ulx, double uly, double urx, double ury)
Viewport maintenance functions:
virtual const double * Getctm ()
 Return a pointer to the current transformation matrix.
virtual const double * Getictm ()
 Return a pointer to the inverse of the current transformation matrix.
virtual void ShiftScreen (int dx, int dy)
 Move the viewable portion by dx,dy screen units.
virtual void NewTransform (const double *d)
 Set the ctm to these 6 numbers.
virtual void NewTransform (double a, double b, double c, double d, double x0, double y0)
 Make the transform correspond to the values.
virtual void PushAxes ()
 Push the current axes on the axessstack. Relying on cr existing is problematic.
virtual void PopAxes ()
 Recover the last pushed axes. Relying on cr existing is problematic.
virtual int DrawReal ()
virtual int DrawScreen ()
- Public Member Functions inherited from Laxkit::Displayer
 Displayer (aDrawable *d)
 Displayer (anXWindow *w=NULL, PanController *pan=NULL)
 Constructor, set everything to nothing or identity.
virtual ~Displayer ()
 Destructor.
virtual aDrawableGetDrawable ()
virtual void Radians ()
 Interpret all angles as radians.
virtual void Degrees ()
 Interpret all angles as radians.
virtual int DrawImmediately (int yes)
 Do not append path operations, draw them with each call.
virtual int onscreen (double x, double y)
 Return whether the given (screen) point is in the viewable area or not.
virtual void moveto (double x, double y)
virtual void lineto (double x, double y)
virtual void drawpoint (flatpoint p, double radius, int fill)
 Draw a little circle at p with screen radius.
virtual void drawrectangle (double x, double y, double w, double h, int tofill)
 Draw a basic rectangle.
virtual void drawbez (flatpoint *bpoints, int n, int isclosed=0, int tofill=0)
 Draw a cubic bezier line.
virtual int drawrealline (flatline &ln, int num)
 Draw a line across the whole view, and if num!=-10000000, print the number num where the line hits the sides of the window.
virtual void drawellipse (double x, double y, double xradius, double yradius, double start_angle=0, double end_angle=0, int fill=0)
 Draw an ellipse with center at real point p..
virtual void drawellipse (flatpoint p, double xradius, double yradius, double start_angle=0, double end_angle=0, int fill=0)
 Draw an ellipse in the rectangle spanned by p +/- (xradius,yradius).
virtual void drawarc (flatpoint p, double xr, double yr, double start_angle=0, double end_angle=0)
 Draw part of an ellipse.
virtual void drawfocusellipse (flatpoint focus1, flatpoint focus2, double c, double start_angle=0, double end_angle=0, int fill=0)
 Draw an ellipse based on the foci.
virtual void drawthing (double x, double y, double rx, double ry, int fill, DrawThingTypes thing)
 Draw a little graphic in range X:x-rx..x+rx, Y:y-ry..y+ry.
virtual void drawthing (double x, double y, double rx, double ry, DrawThingTypes thing, unsigned long fg, unsigned long bg, int lwidth=1)
virtual void drawarrow (flatpoint p, flatpoint v, int rfromp=0, double len=10, char reallength=1, int portion=3)
 Draw a little arrow near point p in v direction.
virtual void drawaxes (double len=1)
 Draw the axes, x=red, y=green, real length len.
virtual void drawnum (double x, double y, int num)
 Draw the number num centered at screen coord (x,y).
virtual double textextent (const char *str, int len, double *width, double *height)
 Return the width of the text.
virtual int righthanded ()
 Return whether the ctm is (mathematically) right handed or not.
virtual char Updates (char toupdatepanner)
 Call Updates(0) to disable updating the panner, Updates(1) to reenable it.
virtual void syncPanner (int all=0)
 Using displayer viewable portion settings, set the panner settings.
virtual void syncFromPanner (int all=0)
 Using the settings in the panner, try to set the Displayer bounds.
virtual void UseThisPanner (PanController *npanner)
 Use the supplied PanController for bounds control.
virtual void PushAndNewTransform (const double *m)
 Push axes, and multiply ctm by a new transform.
virtual void PushAndNewAxes (flatpoint p, flatpoint x, flatpoint y)
 Push axes, and multiply ctm by a new basis, p,x,y are all in real units.
virtual void NewAxis (flatpoint o, flatpoint xtip)
 Replace current transform wth a new orthogonal basis with origin o, xaxis unit corresponds to (xtip-o).
virtual void NewAxis (flatpoint o, flatvector x, flatvector y)
 Replace current transform with origin o, with x and y as the new axes.
virtual void ShiftReal (double dx, double dy)
 Move the screen by real dx,dy along the real axes.
virtual void Center (double minx, double maxx, double miny, double maxy)
 Zoom and center the view on the given real bounds.
virtual void Center (const double *m, DoubleBBox *bbox)
 Center the bbox bounds, after transforming by m.
virtual void Center (DoubleBBox *bbox)
 Center the bbox bounds, which are in real coordinates.
virtual void CenterPoint (flatpoint p)
 Centers the view at real point p.
virtual void CenterReal ()
 Make the center of Minx,Maxx... correspond to the real origin.
virtual void Newangle (double angle, int dir=0, int dec=-1)
 Rotate around real origin so that the x axis has angle between it and the screen horizontal.
virtual void Rotate (double angle, int x, int y, int dec=-1)
 Rotate by angle, about screen coordinate (x,y).
virtual void Zoomr (double m, flatpoint p)
 Zoom around real point p.
virtual void Zoom (double m, int x, int y)
 Zoom around screen point x,y.
virtual void Zoom (double m)
 Zoom around the real origin.
virtual double Getmag (int y=0)
 Return the current magnification, screen=Getmag*real.
virtual double GetVMag (int x, int y)
 Return the magnification along the screen vector (x,y). (screen=mag*real)
virtual void Newmag (double xs, double ys=-1)
 Set the xscale and the yscale, but preserve orientation, then syncPanner().
virtual void SetView (double minx, double maxx, double miny, double maxy)
 Set the view area to this section of the screen.
virtual int SetSpace (double minx, double maxx, double miny, double maxy)
 Set the workspace bounds, return nonzero if successful.
virtual void GetSpace (double *minx, double *maxx, double *miny, double *maxy)
 Get the real, not screen, workspace bounds.
virtual void GetTransformedSpace (long *minx, long *maxx, long *miny, long *maxy)
 Find the mins and maxes of the transformed workspace.
- Public Member Functions inherited from Laxkit::PanUser
 PanUser (PanController *npan=NULL)
 Create with a new panner.
virtual ~PanUser ()
 Removes this from panner tellstack. Delete panner if necessary.
virtual PanControllercreateNewPanner (PanController *pan=NULL)
 Create a new panner that is a copy of pan if given.
- Public Member Functions inherited from Laxkit::anObject
 anObject ()
 Set object_id=getUniqueNumber().
virtual ~anObject ()
 Empty virtual destructor.
virtual const charwhattype ()
 Returns the type of anObject.
virtual anObjectduplicate (anObject *ref=NULL)
virtual int inc_count ()
 Increment the data's count by 1. Returns count.
virtual int dec_count ()
 Decrement the count of the data, deleting if count is less than or equal to 0.
virtual int the_count ()

Protected Member Functions

virtual int reallocBuffer (int len)
void base_init ()

Protected Attributes

charbuffer
int bufferlen
Display * dpy
Visual * vis
Window w
LaxCompositeOp blendmode
int isinternal
cairo_t * cr
 Cairo context that the displayer uses.
cairo_surface_t * target
cairo_surface_t * surface
 Cairo destination surface.
cairo_surface_t * mask
 Cairo mask surface, if any.
cairo_surface_t * source
 Cairo source surface, if any.
double ctm [6]
double ictm [6]
PtrStack< double > axesstack
double fgRed
double fgGreen
double fgBlue
double fgAlpha
double bgRed
double bgGreen
double bgBlue
double bgAlpha
cairo_font_face_t * curfont
cairo_scaled_font_t * curscaledfont
double _textheight
- Protected Attributes inherited from Laxkit::Displayer
anXWindowxw
aDrawabledr
int on
char updatepanner
double spaceminx
 Minimum real workspace x coordinate.
double spacemaxx
 Maximum real workspace x coordinate.
double spaceminy
 Minimum real workspace y coordinate.
double spacemaxy
 Maximum real workspace y coordinate.
char draw_immediately
char real_coordinates
char decimal
int num_bez_div
- Protected Attributes inherited from Laxkit::anObject
int _count
 The reference count of the object.

Additional Inherited Members

- Public Attributes inherited from Laxkit::Displayer
unsigned long displayer_style
double upperbound
 The maximum screen length of an axis and other items.
double lowerbound
 The minimum screen length of an axis and other items.
int Minx
 Minimum screen x coordinate.
int Maxx
 Maximum screen x coordinate.
int Miny
 Minimum screen y coordinate (near top of screen).
int Maxy
 Maximum screen y coordinate (near bottom of screen).
- Public Attributes inherited from Laxkit::PanUser
PanControllerpanner
- Public Attributes inherited from Laxkit::anObject
int suppress_debug
DeleteRefCountedFunc deleteMe
 Called when the count is decremented to 0.
unsigned long object_id
charobject_idstr

Detailed Description

Displayer based on Cairo.

 About the Current Transformation matrix (ctm) and its inverse (ictm):
  Postscript:
      [ a  b  0 ]
  CTM=[ c  d  0 ]  –> [a b c d tx ty]
      [ tx ty 1 ]
  screen x= ax + cy + tx  –> screen = [x',y',1] = [x,y,1] * CTM  = real * CTM
  screen y= bx + dy + ty
  Say you want to rotate real, then translate real, then screenp = realp*R*T*CTM.
  In the Cairo library, cairo_matrix_t={ double xx,xy, yx,yy, x0,y0 } corresponds
  to a Laxkit transform [xx yx xy yy x0 y0].
 

Constructor & Destructor Documentation

Laxkit::DisplayerCairo::DisplayerCairo ( anXWindow nxw = NULL,
PanController pan = NULL 
)

set cr=NULL, and surface=NULL.


Member Function Documentation

int Laxkit::DisplayerCairo::ClearDrawable ( aDrawable drawable)
virtual

Free any data associated with drawable.

! Find out what type of surface is currently set to be drawn on. ! 1 for internal surface, 2 for aDrawable, 3 for a back buffer of aDrawable.

Return 1 for drawable not currently used, or 0 for cleared.

Implements Laxkit::Displayer.

int Laxkit::DisplayerCairo::Clip ( flatpoint p,
int  n,
int  append 
)
virtual

Install a clip mask from a polyline (line is automatically closed)

If append!=0, then add this path to the clipping path. Otherwise, remove any existing clip information, and install this one path.

Implements Laxkit::Displayer.

References cr, Laxkit::Displayer::DrawImmediately(), and drawlines().

void Laxkit::DisplayerCairo::drawlines ( flatpoint points,
int  npoints,
char  ifclosed,
char  tofill 
)
virtual

Draw a polygon, optionally fill.

If fill==1 then fill with FG and have no border. If fill==2, then fill with BG and border wich FG.

Implements Laxkit::Displayer.

References cr, and realtoscreen().

Referenced by Clip().

void Laxkit::DisplayerCairo::drawpoint ( double  x,
double  y,
double  radius,
int  tofill 
)
virtual

Draw optionally filled circle with screen radius r, at (x,y).

(x,y) is real or screen according to DrawScreen() or DrawReal(), but radius is still screen units.

Implements Laxkit::Displayer.

References Laxkit::Displayer::drawarc(), and realtoscreen().

int Laxkit::DisplayerCairo::EndDrawing ( )
virtual

Free any resources allocated for drawing in this object.

This resets all the drawing bits to 0. Be warned that most of the functions in DisplayerCairo do not check for a NULL context or NULL surface!!

If xw==NULL, then also call Updates(1);

Implements Laxkit::Displayer.

References cr, mask, source, surface, and Laxkit::Displayer::Updates().

void Laxkit::DisplayerCairo::fill ( int  preserve)
virtual

Draw out current path if any.

If preserve!=0, then the path is not cleared.

Implements Laxkit::Displayer.

References cr.

int Laxkit::DisplayerCairo::font ( const char fontconfigpattern)
virtual

Return 0 for success, 1 for fail.

Implements Laxkit::Displayer.

References cr.

void Laxkit::DisplayerCairo::LineAttributes ( double  width,
int  dash,
int  cap,
int  join 
)
virtual

Set the width, whether solid, line cap and join.

This currently uses Xlib's names which are as follows.

width is only in screen pixels for now. dash can be LineSolid, LineOnOffDash, or LineDoubleDash. width is only in screen pixels for now. See LaxJoinStyle and LaxCapStyle for values for cap and join.

Todo:
should be able to set dash pattern somehow, and set line width based on current transform...

Implements Laxkit::Displayer.

References cr.

unsigned long Laxkit::DisplayerCairo::NewBG ( double  r,
double  g,
double  b 
)
virtual

Set new background color. Typically usage is NewFG(app->rgbcolor(.5,.8,0)).

Component range is [0..1.0].

Implements Laxkit::Displayer.

Referenced by NewBG().

unsigned long Laxkit::DisplayerCairo::NewFG ( double  r,
double  g,
double  b,
double  a = 1.0 
)
virtual

Set new foreground color. Typically usage is NewFG(.5,.8,0,1.0).

Component range is clamped to [0..1.0].

Implements Laxkit::Displayer.

References cr.

Referenced by NewFG().

unsigned long Laxkit::DisplayerCairo::NewFG ( int  r,
int  g,
int  b,
int  a = 255 
)
virtual

Set new foreground. Typically usage is NewFG(app->rgbcolor(23,34,234)).

Component range is currently 0..255.... subject to change.

Implements Laxkit::Displayer.

References NewFG().

int Laxkit::DisplayerCairo::reallocBuffer ( int  len)
protectedvirtual

Reallocate only when necessary.

Referenced by textextent(), and textout().

flatpoint Laxkit::DisplayerCairo::realtoscreen ( flatpoint  p)
virtual

Convert real point p to screen coordinates.

  screen x= ax + cy + tx  –> screen = [x',y',1] = [x,y,1] * CTM  = real * CTM
  screen y= bx + dy + ty
  

Implements Laxkit::Displayer.

References Laxkit::transform_point().

Referenced by drawlines(), drawpixel(), and drawpoint().

flatpoint Laxkit::DisplayerCairo::realtoscreen ( double  x,
double  y 
)
virtual

Convert real point (x,y) to screen coordinates.

  screen x= ax + cy + tx  –> screen = [x',y',1] = [x,y,1] * CTM  = real * CTM
  screen y= bx + dy + ty
  

Implements Laxkit::Displayer.

References Laxkit::transform_point().

int Laxkit::DisplayerCairo::ResizeSurface ( int  width,
int  height 
)
virtual

Resize an internal drawing surface.

If you had previously called CreateSurface(), this will resize that surface. If the target surface is an external surface, then nothing is done.

Return 0 for success, or 1 if not using an internal surface, and nothing done.

Implements Laxkit::Displayer.

References CreateSurface(), Laxkit::Displayer::Maxx, and Laxkit::Displayer::Maxy.

void Laxkit::DisplayerCairo::setCairoBlendMode ( cairo_operator_t  mode)
virtual

Set how the source is blended onto the destination.

The cairo modes are cairo_operator_t:

  CAIRO_OPERATOR_CLEAR, 
  CAIRO_OPERATOR_SOURCE,
  CAIRO_OPERATOR_OVER,
  CAIRO_OPERATOR_IN,
  CAIRO_OPERATOR_OUT,
  CAIRO_OPERATOR_ATOP, 
  CAIRO_OPERATOR_DEST,
  CAIRO_OPERATOR_DEST_OVER,
  CAIRO_OPERATOR_DEST_IN,
  CAIRO_OPERATOR_DEST_OUT,
  CAIRO_OPERATOR_DEST_ATOP, 
  CAIRO_OPERATOR_XOR,
  CAIRO_OPERATOR_ADD,
  CAIRO_OPERATOR_SATURATE
 

References cr.

void Laxkit::DisplayerCairo::stroke ( int  preserve)
virtual

Draw out current path if any.

If preserve!=0, then the path is not cleared.

Implements Laxkit::Displayer.

References cr.

double Laxkit::DisplayerCairo::textextent ( LaxFont thisfont,
const char str,
int  len,
double *  width,
double *  height,
double *  ascent,
double *  descent,
char  real 
)
virtual

str should be utf8, and len should be number of bytes into str.

Implements Laxkit::Displayer.

References cr, and reallocBuffer().

double Laxkit::DisplayerCairo::textout ( double  x,
double  y,
const char str,
int  len = 0,
unsigned long  align = LAX_CENTER 
)
virtual

Draw a single line of text at x,y.

str is utf8.

Implements Laxkit::Displayer.

References cr, and reallocBuffer().


The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:52:59, Laxkit