User Guide
Ruby Component
addArc rect, startAngle, sweepAngle
addCurve points
addBeziers points
addLines points
Note that when you add line elements, consecutive lines will automatically get joined at their end and start points. You can then call the
closeFigure method to make the end of the last line join with the start of the first to form a closed shape.
The addCurve and addClosedCurve methods can also take the same optional input parameters that the drawCurve and
drawClosedCurve methods take. See the previous two sections for more information.
There is one additional add method of the GraphicsPath class called addPath. This allows you to append another path to the path. The
method has two inputs: the path to be added and a true/false value to indicate whether the path is to connect into the existing figure (true) or
be a new figure in the path (false).
addPath path, connect
Once you have created a GraphicsPath object you can draw it using the View class drawPath method. This takes a path and a drawing
instrument (pen or brush) as inputs:
drawPath instrument, path
The example below shows how you might use a graphics path in practice:
Other GraphicsPath Methods
You can get the bounding rectangle of a GraphicsPath object by calling the getBounds method. This will return a Ruby array of the form
[x,y,w,h] giving you the smallest rectangle that contains the complete path.
To widen the path call the widen method:
widen pen, {optional View object}
The view object input is optional and serves only to provide scaling information. The pen input provides a pen to widen the path by. Widening
is done by adding an additional outline to the path as if the path had been drawn in the pen.
You can check if a point is inside the GraphicsPath using the isVisible method:
isVisible point, {optional View object}
The view object input is the same as for the widen method. The point input is a two dimensional Ruby array [x,y] for the point you want to
test. The return value is either true or false.
You can also check if a point is on the outline of a GraphicsPath using the isOutlineVisible method
isOutlineVisible point, pen, {optional View object}
121 of 212