Class WPainterPath

java.lang.Object
eu.webtoolkit.jwt.WJavaScriptExposableObject
eu.webtoolkit.jwt.WPainterPath

public class WPainterPath
extends WJavaScriptExposableObject
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:


 WPainter painter = new WPainter();

 WPainterPath path = new WPainterPath(new WPointF(10, 10));
 path.lineTo(10, 20);
 path.lineTo(30, 20);
 path.closeSubPath();

 painter.setPen(new WPen(WColor.red));
 painter.setBrush(new WBrush(WColor.blue));
 painter.drawPath(path);

 

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(WPainterPath path), WPaintedWidget.createJSPainterPath()