-
-
-
-
-
-
-
-
-
- /*
- public static abstract class GradientPaint extends Paint {
- public GradientPaint(boolean reflect, boolean repeat, Affine gradientTransform,
- int[] stop_colors, float[] stop_offsets) {
- this.reflect = reflect; this.repeat = repeat;
- this.gradientTransform = gradientTransform;
- this.stop_colors = stop_colors;
- this.stop_offsets = stop_offsets;
- }
- Affine gradientTransform = Affine.identity();
- boolean useBoundingBox = false; // FIXME not supported
- boolean patternUseBoundingBox = false; // FIXME not supported
-
- // it's invalid for both of these to be true
- boolean reflect = false; // FIXME not supported
- boolean repeat = false; // FIXME not supported
- int[] stop_colors;
- float[] stop_offsets;
-
- public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) {
- Affine a = buf.a;
- Affine inverse = a.copy().invert();
- float slope1 = (tx3 - tx1) / (ty2 - ty1);
- float slope2 = (tx4 - tx2) / (ty2 - ty1);
- for(float y=ty1; y<ty2; y++) {
- float _x1 = (y - ty1) * slope1 + tx1;
- float _x2 = (y - ty1) * slope2 + tx2;
- if (_x1 > _x2) { float _x0 = _x1; _x1 = _x2; _x2 = _x0; }
-
- for(float x=_x1; x<_x2; x++) {
-
- float distance = isLinear ?
- // length of projection of <x,y> onto the gradient vector == {<x,y> \dot {grad \over |grad|}}
- (x * (x2 - x1) + y * (y2 - y1)) / (float)Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) :
-
- // radial form is simple! FIXME, not quite right
- (float)Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
-
- // FIXME: offsets are 0..1, not 0..length(gradient)
- int i = 0; for(; i<stop_offsets.length; i++) if (distance < stop_offsets[i]) break;
-
- // FIXME: handle points beyond the bounds
- if (i < 0 || i >= stop_offsets.length) continue;
-
- // gradate from offsets[i - 1] to offsets[i]
- float percentage = ((distance - stop_offsets[i - 1]) / (stop_offsets[i] - stop_offsets[i - 1]));
-
- int a = (int)((((stop_colors[i] >> 24) & 0xff) - ((stop_colors[i - 1] >> 24) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 24) & 0xff);
- int r = (int)((((stop_colors[i] >> 16) & 0xff) - ((stop_colors[i - 1] >> 16) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 16) & 0xff);
- int g = (int)((((stop_colors[i] >> 8) & 0xff) - ((stop_colors[i - 1] >> 8) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 8) & 0xff);
- int b = (int)((((stop_colors[i] >> 0) & 0xff) - ((stop_colors[i - 1] >> 0) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 0) & 0xff);
- int argb = (a << 24) | (r << 16) | (g << 8) | b;
- buf.drawPoint((int)x, (int)Math.floor(y), argb);
- }
- }
- }
- }
-
- public static class LinearGradientPaint extends GradientPaint {
- public LinearGradientPaint(float x1, float y1, float x2, float y2, boolean reflect, boolean repeat,
- Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
- super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
- this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2;
- }
- float x1 = 0, y1 = 0, x2 = 300, y2 = 300;
- }
-
- public static class RadialGradientPaint extends GradientPaint {
- public RadialGradientPaint(float cx, float cy, float fx, float fy, float r, boolean reflect, boolean repeat,
- Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
- super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
- this.cx = cx; this.cy = cy; this.fx = fx; this.fy = fy; this.r = r;
- }
-
- float cx, cy, r, fx, fy;
-
- }
- */
-