com.flagstone.transform.shape
Class Curve

java.lang.Object
  extended by com.flagstone.transform.shape.Curve
All Implemented Interfaces:
Copyable<ShapeRecord>, SWFEncodeable, ShapeRecord

public final class Curve
extends Object
implements ShapeRecord

Curve is used to define a curve. Curved lines are constructed using a Quadratic Bezier curve. The curve is specified using two points, an off-curve control point, relative to the current point and an on-curve anchor point which defines the end-point of the curve, and which is specified relative to the anchor point.

Flash does not directly support Cubic Bezier curves. Converting a Cubic Bezier curve to a Quadratic curve is a non trivial process, however the Canvas class contains a method to perform the conversion simplifying the create of Shape outlines in Flash from other graphics formats.

See Also:
Canvas

Constructor Summary
Curve(Curve object)
          Creates and initialises a Curve object using the values copied from another Curve object.
Curve(int xControl, int yControl, int xAnchor, int yAnchor)
          Creates a Curve object specifying the anchor and control point coordinates.
Curve(SWFDecoder coder)
          Creates and initialises a Curve object using values encoded in the Flash binary format.
 
Method Summary
 Curve copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 int getAnchorX()
          Get the x-coordinate of the anchor point relative to the control point.
 int getAnchorY()
          Get the y-coordinate of the anchor point relative to the control point.
 int getControlX()
          Get the x-coordinate of the control point relative to the current drawing point.
 int getControlY()
          Get the y-coordinate of the control point relative to the current drawing point.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setPoints(int xControl, int yControl, int xAnchor, int yAnchor)
          Sets the x and y coordinates of the control and anchor points.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Curve

public Curve(SWFDecoder coder)
      throws IOException
Creates and initialises a Curve object using values encoded in the Flash binary format.

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

Curve

public Curve(int xControl,
             int yControl,
             int xAnchor,
             int yAnchor)
Creates a Curve object specifying the anchor and control point coordinates.

Parameters:
xControl - the x-coordinate of the control point, specified relative to the current drawing point. Must be in the range -65535..65535.
yControl - the y-coordinate of the control point, specified relative to the current drawing point.Must be in the range -65535..65535.
xAnchor - the x-coordinate of the anchor point, specified relative to the control point.Must be in the range -65535..65535.
yAnchor - the y-coordinate of the anchor point, specified relative to the control point.Must be in the range -65535..65535.

Curve

public Curve(Curve object)
Creates and initialises a Curve object using the values copied from another Curve object.

Parameters:
object - a Curve object from which the values will be copied.
Method Detail

getControlX

public int getControlX()
Get the x-coordinate of the control point relative to the current drawing point.

Returns:
the x-coordinate of the control point.

getControlY

public int getControlY()
Get the y-coordinate of the control point relative to the current drawing point.

Returns:
the y-coordinate of the control point.

getAnchorX

public int getAnchorX()
Get the x-coordinate of the anchor point relative to the control point.

Returns:
the x-coordinate of the anchor point.

getAnchorY

public int getAnchorY()
Get the y-coordinate of the anchor point relative to the control point.

Returns:
the y-coordinate of the anchor point.

setPoints

public void setPoints(int xControl,
                      int yControl,
                      int xAnchor,
                      int yAnchor)
Sets the x and y coordinates of the control and anchor points. Values must be in the range -65535..65535.

Parameters:
xControl - the x-coordinate of the control point.
yControl - the y-coordinate of the control point.
xAnchor - the x-coordinate of the anchor point.
yAnchor - the y-coordinate of the anchor point.

copy

public Curve copy()
Creates a complete copy of this object.

Specified by:
copy in interface Copyable<ShapeRecord>
Returns:
a deep-copy of this object. New instances of mutable objects are copied and immutable instances are shared.

toString

public String toString()
Overrides:
toString in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.