tbx  0.7.6
Public Member Functions | List of all members
tbx::DrawPath Class Reference

Class to represent, display and manipulate a graphical path used by the Draw RISC OS module. More...

#include <drawpath.h>

Public Member Functions

 DrawPath (int capacity=64)
 Create a new draw path object. More...
 
void add (const DrawElement &element)
 Add an element to the path. More...
 
void capacity (int capacity)
 Set the capacity of the path. More...
 
int capacity () const
 Get capacity in words (1 word = 4 bytes)
 
void end_path ()
 End the path.
 
void move (int x, int y)
 Move to (x, y) starting new subpath. More...
 
void close_gap ()
 Close path with a gap.
 
void close_line ()
 Close path with a line.
 
void bezier (int cx1, int cy1, int cx2, int cy2, int x, int y)
 Bezier curve to.
 
void gap (int x, int y)
 Add a gap to a path.
 
void line (int x, int y)
 Add a line to a path.
 
void circle (int x, int y, int radius)
 Adds a circle subpath to the drawing. More...
 
void fill (DrawFillStyle fill_style=WINDING_NON_ZERO, DrawTransform *transform=0, int flatness=0) const
 Fill the interior of a path. More...
 
void stroke (DrawFillStyle fill_style=WINDING_NON_ZERO, DrawTransform *transform=0, int flatness=0, int thickness=0, DrawCapAndJoin *cap_and_join=0, DrawDashPattern *dashes=0) const
 Sends a path to the VDU. More...
 

Detailed Description

Class to represent, display and manipulate a graphical path used by the Draw RISC OS module.

A path is created by adding DrawElements to the path.

Convenience methods are included to add the common draw elements without need to construct a draw element first.

The units used for coordinates in a path are user defined, they are converted to screen coordinates by a transform when the path it filled or stroked.

Constructor & Destructor Documentation

◆ DrawPath()

tbx::DrawPath::DrawPath ( int  capacity = 64)

Create a new draw path object.

A move, line or gap takes 3 words. A curve takes 7 words Closing a path takes 1 word. The end element and draw continuation take 2 words

Parameters
initialcapacity in words. 1 word is 4 bytes. Default is 64.

Member Function Documentation

◆ add()

void tbx::DrawPath::add ( const DrawElement element)

Add an element to the path.

Parameters
elementDrawElement to add

◆ capacity()

void tbx::DrawPath::capacity ( int  new_cap)

Set the capacity of the path.

Parameters
new_capnew capacity in words (1 word = 4 bytes)

◆ circle()

void tbx::DrawPath::circle ( int  x,
int  y,
int  radius 
)

Adds a circle subpath to the drawing.

The circle is an approximation using bezier curves.

The circle is made of 4 bezier curves, a move and a close so requires 32 words.

Parameters
xuser x coordinate of centre
yuser y coordinate of centre
radiusradius of the circle (maximum 32767).

◆ fill()

void tbx::DrawPath::fill ( DrawFillStyle  fill_style = WINDING_NON_ZERO,
DrawTransform transform = 0,
int  flatness = 0 
) const

Fill the interior of a path.

This method emulates the PostScript 'fill' operator. It performs the following actions:

  • closes open subpaths
  • flattens the path
  • transforms it to standard coordinates
  • fills the resulting path and draws to the VDU.

The transform needs to map the user units into internal draw units which are 1/256th of an OS unit.

Parameters
styleDrawFillStyle flags for filling. Default is WINDING_NON_ZERO.
transformtransformation matrix of 0 for none
flatnessmaximum distance allowed from beizer curve when flattening it in user units (0 use default)

◆ move()

void tbx::DrawPath::move ( int  x,
int  y 
)

Move to (x, y) starting new subpath.

The new subpath does affect winding numbers and so is filled normally.

◆ stroke()

void tbx::DrawPath::stroke ( DrawFillStyle  fill_style = WINDING_NON_ZERO,
DrawTransform transform = 0,
int  flatness = 0,
int  thickness = 0,
DrawCapAndJoin cap_and_join = 0,
DrawDashPattern dashes = 0 
) const

Sends a path to the VDU.

This command emulates the PostScript 'stroke' operator. It performs the following actions: flattens the path

  • applies a dash pattern to the path, if dashes != 0
  • thickens the path, using the specified joins and caps
  • re-flattens the path, to flatten round caps and joins, so that they can be filled.
  • transforms the path to standard coordinates
  • fills the resulting path and draws to the VDU.

The transform needs to map the user units into internal draw units which are 1/256th of an OS unit.

Parameters
fill_styleDrawFillStyle. Default is WINDING_NON_ZERO.
transformpointer to transformation matrix, or 0 for identity matrix
flatnessflatness, or 0 for default
thicknessline thickness, or 0 for default. If the thickness is zero then the line is drawn with the minimum width that can be used, given the limitations of the pixel size (so lines are a single pixel wide). If the thickness is n, then the line will be drawn with a thickness of n/2 user coordinates translated to pixels on either side of the theoretical line position. If the line thickness is non-zero, then the cap and join parameter must also be passed.
cap_and_joinpointer to line cap and join specification (if required)
pointerto dash pattern, or 0 for no dashes

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