TransformTraitAnimpublic class TransformTraitAnim extends FloatTraitAnim
Constructors Summary |
---|
public TransformTraitAnim(ElementNode targetElement, String traitName)Constructs a new TransformTraitAnim for a given ElementNode trait.
super(targetElement,
traitName,
ElementNode.TRAIT_TYPE_SVG_MATRIX);
|
Methods Summary |
---|
public java.lang.Object[] | multiply(java.lang.Object[] value, int iter)Used to multiply an animated trait value by a number of iterations.
for (int i = 1; i < iter; i++) {
value = sum(value, value);
}
return value;
| public java.lang.Object[] | sum(java.lang.Object[] valueA, java.lang.Object[] valueB)Used to sum two animated trait values.
if (valueA == null) {
return valueB;
}
float[][] fva = (float[][]) valueA;
float[][] fvb = (float[][]) valueB;
// For transforms, we should do matrices multiplication, not
// simple float additions.
float[][] fv = new float[6][1];
fv[0][0] = fvb[0][0] * fva[0][0] + fvb[1][0] * fva[2][0];
fv[1][0] = fvb[0][0] * fva[1][0] + fvb[1][0] * fva[3][0];
fv[2][0] = fvb[2][0] * fva[0][0] + fvb[3][0] * fva[2][0];
fv[3][0] = fvb[2][0] * fva[1][0] + fvb[3][0] * fva[3][0];
fv[4][0] = fvb[4][0] * fva[0][0] + fvb[5][0] * fva[2][0] + fva[4][0];
fv[5][0] = fvb[4][0] * fva[1][0] + fvb[5][0] * fva[3][0] + fva[5][0];
return fv;
| RefValues | toRefValues(Animation anim, java.lang.String[] values, java.lang.String reqTraitNamespace, java.lang.String reqTraitName)Converts the input values set to a RefValues object.
// If we are dealing with a generic animation, the values should be
// as in the transform attribute: we can use the default FloatTraitAnim
// toRefValues.
if (anim.type == Animation.TYPE_GENERIC) {
return super.toRefValues(anim, values, reqTraitNamespace,
reqTraitName);
}
// The interpretation of values depends on the animation type.
TransformRefValues refValues = new TransformRefValues();
if (values.length < 1) {
throw new IllegalArgumentException();
}
if (values.length == 1) {
String[] tmpValues = new String[2];
tmpValues[0] = values[0];
tmpValues[1] = values[0];
values = tmpValues;
}
int nSegments = values.length - 1;
TransformSegment[] segments = new TransformSegment[nSegments];
// Build the first segment.
segments[0] = new TransformSegment();
segments[0].start =
validateValue(anim,
reqTraitNamespace,
reqTraitName,
values[0]);
segments[0].end =
validateValue(anim,
reqTraitNamespace,
reqTraitName,
values[1]);
segments[0].type = anim.type;
TransformSegment prevSegment = segments[0];
for (int i = 1; i < nSegments; i++) {
segments[i] = new TransformSegment();
segments[i].start = prevSegment.end;
segments[i].end =
validateValue(anim,
reqTraitNamespace,
reqTraitName,
values[i + 1]);
segments[i].type = anim.type;
prevSegment = segments[i];
}
refValues.segments = segments;
return refValues;
| public float[] | validateValue(Animation anim, java.lang.String traitNamespace, java.lang.String traitName, java.lang.String value)Validates the input trait value.
float[] v = null;
switch (anim.type) {
case AnimateTransform.TYPE_TRANSLATE:
v = anim.parseFloatArrayTrait(traitName, value);
if (v.length < 1 || v.length > 2) {
throw anim.illegalTraitValue(traitName, value);
}
if (v.length == 1) {
float[] tv = new float[2];
tv[0] = v[0];
tv[1] = 0;
v = tv;
}
return v;
case AnimateTransform.TYPE_SCALE:
v = anim.parseFloatArrayTrait(traitName, value);
if (v.length < 1 || v.length > 2) {
throw anim.illegalTraitValue(traitName, value);
}
if (v.length == 1) {
float[] tv = new float[2];
tv[0] = v[0];
tv[1] = v[0];
v = tv;
}
return v;
case AnimateTransform.TYPE_ROTATE:
// This should be enhanced to support
v = anim.parseFloatArrayTrait(traitName, value);
if (v.length != 1 && v.length != 3) {
throw anim.illegalTraitValue(traitName, value);
}
if (v.length != 3) {
float[] tv = new float[3];
tv[0] = v[0];
tv[1] = 0;
tv[2] = 0;
v = tv;
}
v[0] = MathSupport.toRadians(v[0]);
return v;
case AnimateTransform.TYPE_SKEW_X:
case AnimateTransform.TYPE_SKEW_Y:
default:
v = new float[] {anim.parseFloatTrait(traitName, value)};
v[0] = MathSupport.toRadians(v[0]);
return v;
}
|
|