com.flagstone.transform.datatype
Class Bounds

java.lang.Object
  extended by com.flagstone.transform.datatype.Bounds
All Implemented Interfaces:
SWFEncodeable

public final class Bounds
extends Object
implements SWFEncodeable

The Bounds class defines the area inside which shapes, text fields and characters are drawn.

In Flash the axes are specified relative to the top left corner of the screen and the bounding area is defined by two pairs of coordinates that identify the top left and bottom right corners of a rectangle.

The coordinates for each corner also specify the coordinate range so specifying a bounding rectangle with the points (-100,-100) and (100,100) defines a rectangle 200 twips by 200 twips with the point (0,0) located in the centre. Specifying the points (0,0) and (200,200) defines a rectangle with the same size however the centre is now located at (100,100).

The bounding rectangle does not clip the object when it is drawn. Lines and curves drawn outside of the rectangle will still be displayed. However if the position of the object is changed or another object is displayed in front of it then only the pixels inside of the bounding box will be repainted.


Constructor Summary
Bounds(int xmin, int ymin, int xmax, int ymax)
          Creates a Bounds object representing a rectangle with the corners at (xmin,ymin) and (xmax,ymax).
Bounds(SWFDecoder coder)
          Creates and initialises a Bounds using values encoded in the Flash binary format.
 
Method Summary
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 boolean equals(Object object)
          
 int getHeight()
          Returns the height of the rectangle, measured in twips.
 int getMaxX()
          Returns the x-coordinate of the bottom right corner of the bounding rectangle as seen on a screen.
 int getMaxY()
          Returns the y-coordinate of the bottom right corner of the bounding rectangle as seen on a screen.
 int getMinX()
          Returns the x-coordinate of the top left corner of the bounding rectangle as seen on a screen.
 int getMinY()
          Returns the y-coordinate of the top left corner of the bounding rectangle as seen on a screen.
 int getWidth()
          Returns the width of the rectangle, measured in twips.
 int hashCode()
          
static Bounds pad(Bounds rect, int padding)
          Create a Bounds by applying a padding factor to all sides of the bounding box.
static Bounds pad(Bounds rect, int top, int right, int bottom, int left)
          Create a Bounds by applying a padding factor to all sides of the bounding box.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Bounds

public Bounds(SWFDecoder coder)
       throws IOException
Creates and initialises a Bounds 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.

Bounds

public Bounds(int xmin,
              int ymin,
              int xmax,
              int ymax)
Creates a Bounds object representing a rectangle with the corners at (xmin,ymin) and (xmax,ymax).

Parameters:
xmin - x-coordinate of the top left corner.
ymin - y-coordinate of the top left corner.
xmax - x-coordinate of bottom right corner.
ymax - y-coordinate of bottom right corner.
Method Detail

pad

public static Bounds pad(Bounds rect,
                         int padding)
Create a Bounds by applying a padding factor to all sides of the bounding box.

Parameters:
rect - the Bounds to adjust.
padding - the margin to add to the coordinates of the bounds.
Returns:
the adjusted Bounds.

pad

public static Bounds pad(Bounds rect,
                         int top,
                         int right,
                         int bottom,
                         int left)
Create a Bounds by applying a padding factor to all sides of the bounding box.

Parameters:
rect - the Bounds to adjust.
top - the to apply to the top of the bounding box.
right - the to apply to the right of the bounding box.
bottom - the to apply to the bottom of the bounding box.
left - the to apply to the left of the bounding box.
Returns:
the adjusted Bounds.

getMinX

public int getMinX()
Returns the x-coordinate of the top left corner of the bounding rectangle as seen on a screen.

Returns:
the x-coordinate of the upper left corner.

getMaxX

public int getMaxX()
Returns the x-coordinate of the bottom right corner of the bounding rectangle as seen on a screen.

Returns:
the x-coordinate of the lower right corner.

getMinY

public int getMinY()
Returns the y-coordinate of the top left corner of the bounding rectangle as seen on a screen.

Returns:
the y-coordinate of the upper left corner.

getMaxY

public int getMaxY()
Returns the y-coordinate of the bottom right corner of the bounding rectangle as seen on a screen.

Returns:
the y-coordinate of the lower right corner.

getWidth

public int getWidth()
Returns the width of the rectangle, measured in twips.

Returns:
the width of the bounding box in twips.

getHeight

public int getHeight()
Returns the height of the rectangle, measured in twips.

Returns:
the height of the bounding box in twips.

toString

public String toString()

Overrides:
toString in class Object

equals

public boolean equals(Object object)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode 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.