|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.flagstone.transform.FSTransformObject
com.flagstone.transform.FSFillStyle
com.flagstone.transform.FSGradientFill
public class FSGradientFill
FSGradientFill defines how a colour changes across an area to be filled with colour.
Two types of gradient fill are supported:
Linear | The gradient changes in one direction across the area to be filled. |
Radial | The gradient changes radially from the centre of the area to be filled. |
Gradients are defined in terms of a standard space called the gradient square, centred at (0,0) and extending from (-16384, -16384) to (16384, 16384).
A coordinate transform is required to map the gradient square to the coordinates of the filled area. The transformation is applied in two steps. First the gradient square is scaled so the colour covers the shape followed by a translation to map the gradient square coordinates to the coordinate range of the shape.
A series of control points is used to control how the colour displayed changes across the gradient. At least two control points are required to define a gradient - one for the starting colour and one for the final colour. Up to eight control points may be specified to generate complex colour transitions. When the Flash Player displays the control points they are sorted by the ratio defined in each FSGradient object, with the smallest ratio value displayed first.
Attributes | |
---|---|
type | The type of gradient fill, either FSFillStyle.Linear or FSFillStyle.Radial. |
transform | A coordinate transformation used to map the gradient square into the coordinates of the area to be filled. |
gradients | An array of up to eight FSGradient objects that define the control points across the gradient square that control the colour transitions. The Flash Player performs the interpolation of the colour values between the control points. |
In addition to specifying the type of gradient fill that will be displayed the type attribute may be used when iterating through an array of fill style objects to identify the type of fill style without using run-time type checking.
For the coordinate transformation, the scaling factor is calculated by diving the width of the gradient square by the width of the shape:
float gradientSquareWidth = 32768.0f; float scale = gradientSquareWidth / shapeWidth;
The translation is defined by calculating the difference between the minimum coordinates of the scaled gradient square and the minimum coordinates of the shape:
int gradientX = -16384; // minimum x coordinate of the gradient square. int gradientY = -16384; // minimum y coordinate of the gradient square. // Get the minimum coordinates of the shape being filled; int shapeX = shape.getBounds().getMinX(); int shapeY = shape.getBounds().getMinY(); // Now calculate the translation int translateX = shapeX - (gradientX / scale); int translateY = shapeY - (gradientY / scale);
The FSCoordTransform has a convenient constructor to create the two-step transformation:
FSCoordTransform composite = new FSCoordTransform(translateX, translateY, scale, scale);
The transform is independent of any transformation defined for the parent shape in which the gradient is displayed. The gradient will be displayed correctly if the shape is scaled, rotated, etc., when it is added to the display list.
The FSGradientFill class represents the FillStyle structure from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.
Field Summary |
---|
Fields inherited from class com.flagstone.transform.FSFillStyle |
---|
Clipped, Linear, Radial, Solid, Tiled, type, Unsmoothed_Clipped, Unsmoothed_Tiled |
Constructor Summary | |
---|---|
FSGradientFill(FSCoder coder)
Construct an FSGradientFill object, initialising it with values decoded from an encoded object. |
|
FSGradientFill(FSGradientFill obj)
Constructs an FSGradientFill object by copying values from an existing object. |
|
FSGradientFill(int aType,
FSCoordTransform aTransform,
java.util.ArrayList anArray)
Constructs an FSGradientFill object specifying the type, coordinate transform and array of gradient records. |
Method Summary | |
---|---|
void |
add(FSGradient aGradient)
Add a FSGradient object to the array of gradient objects. |
void |
appendDescription(java.lang.StringBuffer buffer,
int depth)
AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. |
java.lang.Object |
clone()
Creates a deep copy of the entire object. |
void |
decode(FSCoder coder)
|
void |
encode(FSCoder coder)
|
boolean |
equals(java.lang.Object anObject)
Returns true if anObject is equal to this one. |
java.util.ArrayList |
getGradients()
Gets the array of up to eight FSGradient objects defining the control points for the gradient. |
FSCoordTransform |
getTransform()
Gets the coordinate transform mapping the gradient square onto physical coordinates. |
int |
length(FSCoder coder)
|
void |
setGradients(java.util.ArrayList anArray)
Sets the array of control points that define the gradient. |
void |
setTransform(FSCoordTransform aTransform)
Sets the coordinate transform mapping the gradient square onto physical coordinates. |
Methods inherited from class com.flagstone.transform.FSFillStyle |
---|
getType, setType |
Methods inherited from class com.flagstone.transform.FSTransformObject |
---|
name, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FSGradientFill(FSCoder coder)
coder
- an FSCoder containing the binary data.public FSGradientFill(int aType, FSCoordTransform aTransform, java.util.ArrayList anArray)
aType
- the type of gradient fill, either FSFillStyle.Linear or
FSFillStyle.Radial.aTransform
- the coordinate transform mapping the gradient square onto
physical coordinates.anArray
- an array of up to eight FSGradient objects defining the
control points for the gradient.public FSGradientFill(FSGradientFill obj)
obj
- an FSGradientFill object.Method Detail |
---|
public void add(FSGradient aGradient)
aGradient
- an FSGradient object.public FSCoordTransform getTransform()
public java.util.ArrayList getGradients()
public void setTransform(FSCoordTransform aTransform)
aTransform
- the coordinate transform.public void setGradients(java.util.ArrayList anArray)
anArray
- an array of up to eight FSGradient objects.public java.lang.Object clone()
FSTransformObject
clone
in class FSTransformObject
public boolean equals(java.lang.Object anObject)
FSFillStyle
equals
in class FSFillStyle
public void appendDescription(java.lang.StringBuffer buffer, int depth)
FSTransformObject
appendDescription
in class FSTransformObject
buffer
- a StringBuffer to which the description of each object is
appended.depth
- the maximum level of nesting up to which objects will be
displayed.public int length(FSCoder coder)
length
in class FSFillStyle
public void encode(FSCoder coder)
encode
in class FSFillStyle
public void decode(FSCoder coder)
decode
in class FSFillStyle
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |