eu.webtoolkit.jwt
Class WPainterPath

java.lang.Object
  extended by eu.webtoolkit.jwt.WPainterPath

public class WPainterPath
extends java.lang.Object

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:

 {
        @code
        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);
 }
 

See Also:
WPainter.drawPath(WPainterPath path)

Nested Class Summary
static class WPainterPath.Segment
          A segment.
 
Constructor Summary
WPainterPath()
          Default constructor.
WPainterPath(WPainterPath path)
          Copy constructor.
WPainterPath(WPointF startPoint)
          Construct a new path, and set the initial position.
 
Method Summary
 void addEllipse(double x, double y, double width, double height)
          Draws an ellipse.
 void addEllipse(WRectF rect)
          Draws an ellipse.
 void addPath(WPainterPath path)
          Adds a path.
 void addRect(double x, double y, double width, double height)
          Draws a rectangle.
 void addRect(WRectF rectangle)
          Draws a rectangle.
 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 arcTo(double cx, double cy, double radius, double startAngle, double sweepLength)
          Draws an arc.
 WPainterPath assign(WPainterPath path)
          Assignment method.
 void closeSubPath()
          Closes the last sub path.
 void connectPath(WPainterPath path)
          Adds a path, connecting.
 void cubicTo(double c1x, double c1y, double c2x, double c2y, double endPointx, double endPointy)
          Draws a cubic bezier curve.
 void cubicTo(WPointF c1, WPointF c2, WPointF endPoint)
          Draws a cubic bezier curve.
 boolean equals(WPainterPath path)
          Indicates whether some other object is "equal to" this one.
 WRectF getControlPointRect()
          Returns the bounding box of the control points.
 WRectF getControlPointRect(WTransform transform)
          Returns the bounding box of the control points.
 WPointF getCurrentPosition()
          Returns the current position.
 java.util.List<WPainterPath.Segment> getSegments()
           
 boolean isEmpty()
          Returns whether the path is empty.
 void lineTo(double x, double y)
          Draws a straight line.
 void lineTo(WPointF point)
          Draws a straight line.
 void moveTo(double x, double y)
          Moves the current position to a new location.
 void moveTo(WPointF point)
          Moves the current position to a new location.
 void quadTo(double cx, double cy, double endPointX, double endPointY)
          Draws a quadratic bezier curve.
 void quadTo(WPointF c, WPointF endPoint)
          Draws a quadratic bezier curve.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WPainterPath

public WPainterPath()
Default constructor.

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


WPainterPath

public WPainterPath(WPointF startPoint)
Construct a new path, and set the initial position.

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


WPainterPath

public WPainterPath(WPainterPath path)
Copy constructor.

Method Detail

assign

public WPainterPath assign(WPainterPath path)
Assignment method.


getCurrentPosition

public WPointF getCurrentPosition()
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

public boolean isEmpty()
Returns whether the path is empty.

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


equals

public boolean equals(WPainterPath path)
Indicates whether some other object is "equal to" this one.

Returns true if the paths are exactly the same.


closeSubPath

public void 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).


moveTo

public void moveTo(WPointF point)
Moves the current position to a new location.

Moves the current position to a new point, implicitly closing the last sub path.

See Also:
closeSubPath(), moveTo(double x, double y)

moveTo

public void 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.

See Also:
closeSubPath(), moveTo(WPointF point)

lineTo

public void lineTo(WPointF point)
Draws a straight line.

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

See Also:
lineTo(double x, double y)

lineTo

public void 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.

See Also:
lineTo(WPointF point)

cubicTo

public void cubicTo(WPointF c1,
                    WPointF c2,
                    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.

See Also:
cubicTo(double c1x, double c1y, double c2x, double c2y, double endPointx, double endPointy)

cubicTo

public void 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.

See Also:
cubicTo(WPointF c1, WPointF c2, WPointF endPoint)

arcTo

public void arcTo(double cx,
                  double cy,
                  double radius,
                  double startAngle,
                  double sweepLength)
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.

See Also:
arcMoveTo(double cx, double cy, double radius, double angle)

arcMoveTo

public void 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.

See Also:
arcTo(double cx, double cy, double radius, double startAngle, double sweepLength)

arcMoveTo

public void 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.

See Also:
arcTo(double cx, double cy, double radius, double startAngle, double sweepLength)

quadTo

public void quadTo(WPointF c,
                   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.

See Also:
quadTo(double cx, double cy, double endPointX, double endPointY)

quadTo

public void quadTo(double cx,
                   double cy,
                   double endPointX,
                   double endPointY)
Draws a quadratic bezier curve.

This is an overloaded method provided for convenience.

See Also:
quadTo(WPointF c, WPointF endPoint)

addEllipse

public void addEllipse(WRectF rect)
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)

See Also:
addEllipse(double x, double y, double width, double height), arcTo(double cx, double cy, double radius, double startAngle, double sweepLength)

addEllipse

public void 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)

See Also:
addEllipse(WRectF rect), arcTo(double cx, double cy, double radius, double startAngle, double sweepLength)

addRect

public void addRect(WRectF rectangle)
Draws a rectangle.

This method closes the current sub path, and adds a rectangle that is defined by rectangle.

See Also:
addRect(double x, double y, double width, double height)

addRect

public void addRect(double x,
                    double y,
                    double width,
                    double height)
Draws a rectangle.

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

See Also:
addRect(WRectF rectangle)

addPath

public void addPath(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, otherwise the last sub path is extended with the path's first sub path.

See Also:
connectPath(WPainterPath path)

connectPath

public void connectPath(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, otherwise the last sub path is extended with the path's first sub path.

See Also:
connectPath(WPainterPath path)

getSegments

public java.util.List<WPainterPath.Segment> getSegments()

getControlPointRect

public WRectF getControlPointRect(WTransform transform)
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.


getControlPointRect

public final WRectF getControlPointRect()
Returns the bounding box of the control points.

Returns getControlPointRect(WTransform.Identity)