Apply transformation matrices to gradient fills
Fixes
Fixes
@@ -24,6 +24,7 @@ class GradientFillContent implements DrawingContent, BaseKeyframeAnimation.Anima
private final String name;
private final LongSparseArray<LinearGradient> linearGradientCache = new LongSparseArray<>();
private final LongSparseArray<RadialGradient> radialGradientCache = new LongSparseArray<>();
+ private final Matrix shaderMatrix = new Matrix();
private final Path path = new Path();
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final RectF boundsRect = new RectF();
@@ -81,11 +82,16 @@ class GradientFillContent implements DrawingContent, BaseKeyframeAnimation.Anima
path.computeBounds(boundsRect, false);
+ Shader shader;
if (type == GradientType.Linear) {
- paint.setShader(getLinearGradient());
+ shader = getLinearGradient();
} else {
- paint.setShader(getRadialGradient());
+ shader = getRadialGradient();
}
+ shaderMatrix.set(parentMatrix);
+ shader.setLocalMatrix(shaderMatrix);
+ paint.setShader(shader);
+
int alpha = (int) ((parentAlpha / 255f * opacityAnimation.getValue() / 100f) * 255);
paint.setAlpha(alpha);
@@ -128,11 +134,8 @@ class GradientFillContent implements DrawingContent, BaseKeyframeAnimation.Anima
GradientColor gradientColor = colorAnimation.getValue();
int[] colors = gradientColor.getColors();
float[] positions = gradientColor.getPositions();
- int x0 = (int) (boundsRect.left + boundsRect.width() / 2 + startPoint.x);
- int y0 = (int) (boundsRect.top + boundsRect.height() / 2 + startPoint.y);
- int x1 = (int) (boundsRect.left + boundsRect.width() / 2 + endPoint.x);
- int y1 = (int) (boundsRect.top + boundsRect.height() / 2 + endPoint.y);
- gradient = new LinearGradient(x0, y0, x1, y1, colors, positions, Shader.TileMode.CLAMP);
+ gradient = new LinearGradient(startPoint.x, startPoint.y, endPoint.x, endPoint.y, colors,
+ positions, Shader.TileMode.CLAMP);
linearGradientCache.put(gradientHash, gradient);
return gradient;
}
@@ -148,10 +151,10 @@ class GradientFillContent implements DrawingContent, BaseKeyframeAnimation.Anima
GradientColor gradientColor = colorAnimation.getValue();
int[] colors = gradientColor.getColors();
float[] positions = gradientColor.getPositions();
- int x0 = (int) (boundsRect.left + boundsRect.width() / 2 + startPoint.x);
- int y0 = (int) (boundsRect.top + boundsRect.height() / 2 + startPoint.y);
- int x1 = (int) (boundsRect.left + boundsRect.width() / 2 + endPoint.x);
- int y1 = (int) (boundsRect.top + boundsRect.height() / 2 + endPoint.y);
+ float x0 = startPoint.x;
+ float y0 = startPoint.y;
+ float x1 = endPoint.x;
+ float y1 = endPoint.y;
float r = (float) Math.hypot(x1 - x0, y1 - y0);
gradient = new RadialGradient(x0, y0, r, colors, positions, Shader.TileMode.CLAMP);
radialGradientCache.put(gradientHash, gradient);
