fillLeftRightGradient method
void
fillLeftRightGradient()
override
Fill a rectangle (x
,y
, width
x height
) with a left right linear gradient.
See fillRightLeftGradient.
Implementation
@override
void fillLeftRightGradient(
num x, num y, num width, num height, PColor colorFrom, PColor colorTo) {
x = transform.x(x);
y = transform.y(y);
var clip = _clip;
if (clip != null) {
var box = PRectangle(x, y, width, height);
var r = clip.intersection(box);
if (r.isZeroDimension) return;
x = r.x;
y = r.y;
width = r.width;
height = r.height;
}
var cFrom = colorFrom.toPColorRGBA();
var cTo = colorTo.toPColorRGBA();
var r1 = cFrom.r;
var g1 = cFrom.g;
var b1 = cFrom.b;
var a1 = cFrom.alpha;
var r2 = cTo.r;
var g2 = cTo.g;
var b2 = cTo.b;
var a2 = cTo.alpha;
var rd = r2 - r1;
var gd = g2 - g1;
var bd = b2 - b1;
var ad = a2 - a1;
var w = width;
var h = height;
var steps = 256;
var s = w ~/ steps;
while (s == 0 && steps > 1) {
--steps;
s = w ~/ steps;
}
var end = (w ~/ s) - 1;
if (a1 == 1 && a1 == a2) {
for (var x = 0; x < w; x += s) {
var ratio = x / end;
var r = (r1 + rd * ratio).toInt();
var g = (g1 + gd * ratio).toInt();
var b = (b1 + bd * ratio).toInt();
var c = PColorRGB(r, g, b);
fillRect(x, y, s, h, PStyle(color: c));
}
} else {
for (var x = 0; x < w; x += s) {
var ratio = x / end;
var r = (r1 + rd * ratio).toInt();
var g = (g1 + gd * ratio).toInt();
var b = (b1 + bd * ratio).toInt();
var a = (a1 + ad * ratio);
var c = PColorRGBA(r, g, b, a);
fillRect(x, y, s, h, PStyle(color: c));
}
}
}