Wt: Wt::WPainterPath Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
Wt::WPainterPath Class Reference
Painting system

A path defining a shape. More...

`#include <Wt/WPainterPath.h>`

Inheritance diagram for Wt::WPainterPath:
[legend]

## Classes
class | Segment
| A segment. More...

## Public Member Functions
| WPainterPath ()
| Default constructor.
| WPainterPath (const WPointF &startPoint)
| Construct a new path, and set the initial position.
| WPainterPath (const WPainterPath &path)
| Copy constructor.
WPainterPath & | operator= (const WPainterPath &path)
| Assignment operator.
WPointF | currentPosition () const
| Returns the current position.
bool | isEmpty () const
| Returns whether the path is empty.
bool | operator== (const WPainterPath &path) const
| Comparison operator.
bool | operator!= (const WPainterPath &path) const
| Comparison operator.
void | closeSubPath ()
| Closes the last sub path.
void | moveTo (const WPointF &point)
| Moves the current position to a new location.
void | moveTo (double x, double y)
| Moves the current position to a new location.
void | lineTo (const WPointF &point)
| Draws a straight line.
void | lineTo (double x, double y)
| Draws a straight line.
void | cubicTo (const WPointF &c1, const WPointF &c2, const WPointF &endPoint)
| Draws a cubic bezier curve.
void | cubicTo (double c1x, double c1y, double c2x, double c2y, double endPointx, double endPointy)
| Draws a cubic bezier curve.
void | arcTo (double cx, double cy, double radius, double startAngle, double spanAngle)
| Draws an arc.
void | arcMoveTo (double cx, double cy, double radius, double angle)
| Moves to a point on an arc.
void | arcMoveTo (double x, double y, double width, double height, double angle)
| Move to a point on an arc.
void | quadTo (const WPointF &c, const WPointF &endPoint)
| Draws a quadratic bezier curve.
void | quadTo (double cx, double cy, double endPointx, double endPointy)
| Draws a quadratic bezier curve.
void | addEllipse (const WRectF &boundingRectangle)
| Draws an ellipse.
void | addEllipse (double x, double y, double width, double height)
| Draws an ellipse.
void | addRect (const WRectF &rectangle)
| Draws a rectangle.
void | addRect (double x, double y, double width, double height)
| Draws a rectangle.
void | addPolygon (const std::vector< WPointF > &points)
| Adds a polygon.
void | addPath (const WPainterPath &path)
| Adds a path.
void | connectPath (const WPainterPath &path)
| Adds a path, connecting.
WRectF | controlPointRect (const WTransform &transform=WTransform::Identity) const
| Returns the bounding box of the control points.
WPainterPath | crisp () const
| Returns a copy of the path where straight lines are moved to be rendered crisply.
void | setOpenSubPathsEnabled (bool enabled=true)
| Disables automatically closing subpaths on moveTo.
bool | openSubPathsEnabled () const
| Returns whether open subpaths are enabled.
virtual std::string | jsValue () const override
| Returns a JavaScript representation of the value of this object.
Public Member Functions inherited from Wt::WJavaScriptExposableObject
bool | isJavaScriptBound () const
| Returns whether this object is JavaScript bound.
std::string | jsRef () const
| Returns a JavaScript reference to this object.

## Detailed Description

A path defining a shape.

A painter path represents a (complex) path that may be composed of lines, arcs and bezier curve segments, and painted onto a paint device using WPainter::drawPath().

The path that is composed in a painter path may consist of multiple closed sub-paths. Only the last sub-path can be left open.

To compose a path, this class maintains a current position, which is the starting point for the next drawing operation. An operation may draw a line (see lineTo()), arc (see arcTo()), or bezier curve (see quadTo() and cubicTo()) from the current position to a new position. A new sub path may be started by moving the current position to a new location (see moveTo()), which automatically closes the previous sub path.

When sub paths overlap, the result is undefined (it is dependent on the underlying painting device).

Usage example:

Wt::WPainter painter(...);
Wt::WPainterPath path(Wt::WPointF(10, 10));
path.lineTo(10, 20);
path.lineTo(30, 20);
path.closeSubPath();
painter.setPen(Wt::StandardColor::Red);
painter.setBrush(Wt::StandardColor::Blue);
painter.drawPath(path);
Wt::WPainterPath
A path defining a shape.
Definition WPainterPath.h:149
Wt::WPainter
Vector graphics painting class.
Definition WPainter.h:147
Wt::WPointF
A value class that defines a 2D point.
Definition WPointF.h:39
Wt::StandardColor::Blue
@ Blue
Color blue.
Wt::StandardColor::Red
@ Red
Color red.

### JavaScript exposability

A WPainterPath is JavaScript exposable. If a WPainterPath is JavaScript bound, it can be accessed in your custom JavaScript code through its handle's jsRef().

A WPainterPath is represented in JavaScript as an array of segments, where each segment is defined by a three element array: [x,y,type], where type is the integer representation of the type of a segment.

For example, a 10 by 10 square with the top left at (10,10) is represented as:

[
[10,10,0], // move to (10,10)
[20,10,1], // line to (20,10)
[20,20,1], // line to (20,20)
[10,20,1], // line to (10,20)
[10,10,1] // line to (10,10)
]

Warning
  A WPainterPath that is JavaScript exposed should be modified only through its handle. Any attempt at modifying it will cause an exception to be thrown.

See also
  WPainter::drawPath(), WPaintedWidget::createJSPainterPath()

## Constructor & Destructor Documentation

## ◆ WPainterPath() [1/2]

Wt::WPainterPath::WPainterPath | ( |  | ) |

Default constructor.

Creates an empty path, and sets the current position to (0, 0).

## ◆ WPainterPath() [2/2]

Wt::WPainterPath::WPainterPath | ( | const WPointF & | startPoint | ) |

Construct a new path, and set the initial position.

Creates an empty path, and sets the current position to `startPoint`.

## Member Function Documentation

## ◆ addEllipse() [1/2]

void Wt::WPainterPath::addEllipse | ( | const WRectF & | boundingRectangle | ) |

Draws an ellipse.

This method closes the current sub path, and adds an ellipse that is bounded by the rectangle `boundingRectangle`.

`Note:` some renderers only support circles (width == height)

Exceptions

  WException | if the path is JavaScript bound

See also
  addEllipse(double, double, double, double), arcTo()

## ◆ addEllipse() [2/2]

void Wt::WPainterPath::addEllipse | ( | double | x,
|  | double | y,
|  | double | width,
|  | double | height )

Draws an ellipse.

This method closes the current sub path, and adds an ellipse that is bounded by the rectangle defined by top left position (`x`, y), and size width x `height`.

Note
  Some renderers only support circles (width == height)

Exceptions

  WException | if the path is JavaScript bound

See also
  addEllipse(const WRectF&), arcTo()

## ◆ addPath()

void Wt::WPainterPath::addPath | ( | const WPainterPath & | path | ) |

Adds a path.

Adds an entire `path` to the current path. If the path's begin position is different from the current position, the last sub path is first closed, unless open subpaths are enabled, otherwise the last sub path is extended with the path's first sub path.

Exceptions

  WException | if the path is JavaScript bound

See also
  connectPath(const WPainterPath&)

## ◆ addPolygon()

void Wt::WPainterPath::addPolygon | ( | const std::vector< WPointF > & | points | ) |

Adds a polygon.

If the first point is different from the current position, the last sub path is first closed, unless open subpaths are enabled, otherwise the last sub path is extended with the polygon.

Exceptions

  WException | if the path is JavaScript bound

See also
  moveTo(), lineTo()

## ◆ addRect() [1/2]

void Wt::WPainterPath::addRect | ( | const WRectF & | rectangle | ) |

Draws a rectangle.

This method closes the current sub path, unless open subpaths are enabled, and adds a rectangle that is defined by `rectangle`.

Exceptions

  WException | if the path is JavaScript bound

See also
  addRect(double, double, double, double)

## ◆ addRect() [2/2]

void Wt::WPainterPath::addRect | ( | double | x,
|  | double | y,
|  | double | width,
|  | double | height )

Draws a rectangle.

This method closes the current sub path, unless open subpaths are enabled, and adds a rectangle that is defined by top left position (x, `y`), and size width x `height`.

Exceptions

  WException | if the path is JavaScript bound

See also
  addRect(const WRectF&)

## ◆ arcMoveTo() [1/2]

void Wt::WPainterPath::arcMoveTo | ( | double | cx,
|  | double | cy,
|  | double | radius,
|  | double | angle )

Moves to a point on an arc.

Moves to a point on a circle. The circle is defined with center (cx, cy) and `radius`, and the point is at `angle` degrees measured counter-clockwise starting from the 3 o'clock position.

Exceptions

  WException | if the path is JavaScript bound

See also
  arcTo()

## ◆ arcMoveTo() [2/2]

void Wt::WPainterPath::arcMoveTo | ( | double | x,
|  | double | y,
|  | double | width,
|  | double | height,
|  | double | angle )

Move to a point on an arc.

Moves to a point on an ellipse. The ellipse fits in the rectangle defined by top left position (`x`, y), and size width x `height`, and the point is at `angle` degrees measured counter-clockwise starting from the 3 o'clock position.

Exceptions

  WException | if the path is JavaScript bound

See also
  arcTo()

## ◆ arcTo()

void Wt::WPainterPath::arcTo | ( | double | cx,
|  | double | cy,
|  | double | radius,
|  | double | startAngle,
|  | double | spanAngle )

Draws an arc.

Draws an arc which is a segment of a circle. The circle is defined with center (cx, cy) and `radius`. The segment starts at `startAngle`, and spans an angle given by `spanAngle`. These angles are expressed in degrees, and are measured counter-clockwise starting from the 3 o'clock position.

Implicitly draws a line from the current position to the start of the arc, if the current position is different from the start.

Exceptions

  WException | if the path is JavaScript bound

See also
  arcMoveTo()

## ◆ closeSubPath()

void Wt::WPainterPath::closeSubPath | ( |  | ) |

Closes the last sub path.

Draws a line from the current position to the start position of the last sub path (which is the end point of the last move operation), and sets the current position to (0, 0).

Exceptions

  WException | if the path is JavaScript bound

## ◆ connectPath()

void Wt::WPainterPath::connectPath | ( | const WPainterPath & | path | ) |

Adds a path, connecting.

Adds an entire `path` to the current path. If the path's begin position is different from the current position, the last sub path is first closed, unless open subpaths are enabled, otherwise the last sub path is extended with the path's first sub path.

Exceptions

  WException | if the path is JavaScript bound

See also
  connectPath(const WPainterPath&)

## ◆ controlPointRect()

WRectF Wt::WPainterPath::controlPointRect | ( | const WTransform & | transform = WTransform::Identity | ) | const

Returns the bounding box of the control points.

Returns the bounding box of all control points. This is guaranteed to be a superset of the actual bounding box.

The `transform` is applied to the path first.

## ◆ crisp()

WPainterPath Wt::WPainterPath::crisp | ( |  | ) | const

Returns a copy of the path where straight lines are moved to be rendered crisply.

This is intended to be used on rectangles, or other paths consisting of only straight line, and will nudge every edge a little bit, so that 1px straight lines are rendered as a crisp line.

This will also work if the path is JavaScript bound.

## ◆ cubicTo() [1/2]

void Wt::WPainterPath::cubicTo | ( | const WPointF & | c1,
|  | const WPointF & | c2,
|  | const WPointF & | endPoint )

Draws a cubic bezier curve.

Draws a cubic bezier curve from the current position to `endPoint`, which becomes the new current position. The bezier curve uses the two control points c1 and `c2`.

Exceptions

  WException | if the path is JavaScript bound

See also
  cubicTo(double, double, double, double, double, double)

## ◆ cubicTo() [2/2]

void Wt::WPainterPath::cubicTo | ( | double | c1x,
|  | double | c1y,
|  | double | c2x,
|  | double | c2y,
|  | double | endPointx,
|  | double | endPointy )

Draws a cubic bezier curve.

This is an overloaded method provided for convenience.

Exceptions

  WException | if the path is JavaScript bound

See also
  cubicTo(const WPointF&, const WPointF&, const WPointF&)

## ◆ currentPosition()

WPointF Wt::WPainterPath::currentPosition | ( |  | ) | const

Returns the current position.

Returns the current position, which is the end point of the last move or draw operation, and which well be the start point of the next draw operation.

## ◆ isEmpty()

bool Wt::WPainterPath::isEmpty | ( |  | ) | const

Returns whether the path is empty.

Returns `true` if the path contains no drawing operations. Note that move operations are not considered drawing operations.

## ◆ jsValue()

virtual std::string Wt::WPainterPath::jsValue | ( |  | ) | const
| overridevirtual

Returns a JavaScript representation of the value of this object.

Note
  The value returned will reflect the current server side value of the object. If this object is JavaScript bound, this value may not reflect the actual client side value. If you need access to the client side value, use jsRef() intead.

Implements Wt::WJavaScriptExposableObject.

## ◆ lineTo() [1/2]

void Wt::WPainterPath::lineTo | ( | const WPointF & | point | ) |

Draws a straight line.

Draws a straight line from the current position to `point`, which becomes the new current position.

Exceptions

  WException | if the path is JavaScript bound

See also
  lineTo(double, double)

## ◆ lineTo() [2/2]

void Wt::WPainterPath::lineTo | ( | double | x,
|  | double | y )

Draws a straight line.

Draws a straight line from the current position to (`x`, `y`), which becomes the new current position.

Exceptions

  WException | if the path is JavaScript bound

See also
  lineTo(const WPointF&)

## ◆ moveTo() [1/2]

void Wt::WPainterPath::moveTo | ( | const WPointF & | point | ) |

Moves the current position to a new location.

Moves the current position to a new point, implicitly closing the last sub path, unless open subpaths are enabled.

Exceptions

  WException | if the path is JavaScript bound

See also
  closeSubPath(), moveTo(double, double), setOpenSubPathsEnabled(bool)

## ◆ moveTo() [2/2]

void Wt::WPainterPath::moveTo | ( | double | x,
|  | double | y )

Moves the current position to a new location.

Moves the current position to a new point, implicitly closing the last sub path, unless open subpaths are enabled.

Exceptions

  WException | if the path is JavaScript bound

See also
  closeSubPath(), moveTo(const WPointF&), setOpenSubPathsEnabled(bool)

## ◆ openSubPathsEnabled()

bool Wt::WPainterPath::openSubPathsEnabled | ( |  | ) | const

Returns whether open subpaths are enabled.

See also
  setOpenSubPathsEnabled(bool)

## ◆ operator!=()

bool Wt::WPainterPath::operator!= | ( | const WPainterPath & | path | ) | const

Comparison operator.

Returns `true` if the paths are different.

## ◆ operator==()

bool Wt::WPainterPath::operator== | ( | const WPainterPath & | path | ) | const

Comparison operator.

Returns `true` if the paths are exactly the same.

## ◆ quadTo() [1/2]

void Wt::WPainterPath::quadTo | ( | const WPointF & | c,
|  | const WPointF & | endPoint )

Draws a quadratic bezier curve.

Draws a quadratic bezier curve from the current position to `endPoint`, which becomes the new current position. The bezier curve uses the single control point `c`.

Exceptions

  WException | if the path is JavaScript bound

See also
  quadTo(double, double, double, double)

## ◆ quadTo() [2/2]

void Wt::WPainterPath::quadTo | ( | double | cx,
|  | double | cy,
|  | double | endPointx,
|  | double | endPointy )

Draws a quadratic bezier curve.

This is an overloaded method provided for convenience.

Exceptions

  WException | if the path is JavaScript bound

See also
  quadTo(const WPointF&, const WPointF&)

## ◆ setOpenSubPathsEnabled()

void Wt::WPainterPath::setOpenSubPathsEnabled | ( | bool | enabled = true | ) |

Disables automatically closing subpaths on moveTo.

By default, open sub paths are disabled, and moveTo and any operation that relies on moveTo will automatically close the last subpath. Enabling this option disables that feature.

See also
  moveTo(), addPath(), connectPath(), addRect()