|
|||||||||
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.FSMorphGradientFill
public class FSMorphGradientFill
FSMorphGradientFill defines how a colour changes across an area filled in a morphing shape.
Two type 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. |
startTransform | The coordinate transform used to map the logical coordinates of the gradient square on to a set of physical coordinates at the start of the morphing process. |
endTransform | The coordinate transform used to map the logical coordinates of the gradient square on to a set of physical coordinates at the end of the morphing process. |
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. Alpha channel (defining transparency) must be defined for the colour in each control point. |
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 above process is repeated to calculate the transform for the gradient fill at the end of the morphing process. The transforms are independent of any transformation defined for the parent morphing shape in which the gradients are displayed.
The FSMorphGradientFill class represents the MorphFillStyle structure from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 3.
Field Summary |
---|
Fields inherited from class com.flagstone.transform.FSFillStyle |
---|
Clipped, Linear, Radial, Solid, Tiled, type, Unsmoothed_Clipped, Unsmoothed_Tiled |
Constructor Summary | |
---|---|
FSMorphGradientFill(FSCoder coder)
Construct an FSMorphGradientFill object, initialising it with values decoded from an encoded object. |
|
FSMorphGradientFill(FSMorphGradientFill obj)
Constructs an FSMorphGradientFill object by copying values from an existing object. |
|
FSMorphGradientFill(int aType,
FSCoordTransform aStartTransform,
FSCoordTransform anEndTransform,
java.util.ArrayList anArray)
Constructs an FSMorphGradientFill object specifying the type of fill, starting and ending coordinate transforms and the array of gradient records. |
Method Summary | |
---|---|
void |
add(FSMorphGradient aGradient)
Add a FSMorphGradient 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. |
FSCoordTransform |
getEndTransform()
Gets the coordinate transform mapping the gradient square onto physical coordinates at the end of the morphing process. |
java.util.ArrayList |
getGradients()
Gets the array of up to eight FSMorphGradient objects defining the control points for the gradient. |
FSCoordTransform |
getStartTransform()
Gets the coordinate transform mapping the gradient square onto physical coordinates at the start of the morphing process. |
int |
length(FSCoder coder)
|
void |
setEndTransform(FSCoordTransform aTransform)
Sets the coordinate transform mapping the gradient square onto physical coordinates at the end of the morphing process. |
void |
setGradients(java.util.ArrayList anArray)
Sets the array of control points that define the gradient. |
void |
setStartTransform(FSCoordTransform aTransform)
Sets the coordinate transform mapping the gradient square onto physical coordinates at the start of the morphing process. |
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 FSMorphGradientFill(FSCoder coder)
coder
- an FSCoder containing the binary data.public FSMorphGradientFill(int aType, FSCoordTransform aStartTransform, FSCoordTransform anEndTransform, java.util.ArrayList anArray)
aType
- the type of gradient fill, either FSFillStyle.Linear or
FSFillStyle.Radial.aStartTransform
- the coordinate transform mapping the gradient square onto
physical coordinates at the start of the morphing process.anEndTransform
- the coordinate transform mapping the gradient square onto
physical coordinates at the end of the morphing process.anArray
- an array of up to eight FSMorphGradient objects defining the
control points for the gradient.public FSMorphGradientFill(FSMorphGradientFill obj)
obj
- an FSMorphGradientFill object.Method Detail |
---|
public void add(FSMorphGradient aGradient)
aGradient
- an FSMorphGradient object.public FSCoordTransform getStartTransform()
public FSCoordTransform getEndTransform()
public java.util.ArrayList getGradients()
public void setStartTransform(FSCoordTransform aTransform)
aTransform
- the starting coordinate transform.public void setEndTransform(FSCoordTransform aTransform)
aTransform
- the ending coordinate transform.public void setGradients(java.util.ArrayList anArray)
anArray
- an array of up to eight FSMorphGradient 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 |