type TDirection = (dVert,dHorz);
procedure DrawGradientFillRect(Canvas: TCanvas; Rect: TRect;
StartColor, EndColor: TColor; Direction: TDirection);
var
Steps: Integer;
StartR, StartG, StartB, EndR, EndG, EndB: Byte;
CrrR, CrrG, CrrB: Double;
IncR, IncG, incB: Double;
i: integer;
begin
case Direction
of
dVert: Steps := Rect.Bottom - Rect.Top;
dHorz: Steps := Rect.Right - Rect.Left;
else
Steps := 0;
end;
if Steps = 0
then Exit;
StartR := GetRValue(StartColor); EndR := GetRValue(EndColor);
StartG := GetGValue(StartColor); EndG := GetGValue(EndColor);
StartB := GetBValue(StartColor); EndB := GetBValue(EndColor);
IncR := (EndR - StartR) / steps;
IncG := (EndG - StartG) / steps;
IncB := (EndB - StartB) / steps;
CrrR := StartR;
CrrG := StartG;
CrrB := StartB;
for i := 0
to Steps
do
begin
Canvas.Pen.Color :=
RGB(Round(CrrR), Round(CrrG), Round(CrrB));
case Direction
of
dVert:
begin
MoveToEx(Canvas.Handle,Rect.Left,i,
nil);
LineTo(Canvas.Handle,Rect.Right + Rect.Left, i);
end;
dHorz:
begin
MoveToEx(Canvas.Handle,i,Rect.Top,
nil);
LineTo(Canvas.Handle,i,Rect.Top + Rect.Bottom);
end;
end;
CrrR := CrrR + IncR;
CrrG := CrrG + IncG;
CrrB := CrrB + IncB;
end;
end;