Graeme Geldenhuys ha scritto:
Hi,

Seeing that I've seen some graphics pros in this list, I thought I
would ask.  In fpGUI I'm creating a new custom component theme for our
project.  For example, Edit components have a sunken 3D effect.
Anybody have some code or a link to some code that can paint gradients
to a corner of a rectangle?

The code attached provides a functions which gives the effect shown in the screenshot, called with: FillRectGradient(canvas,0,0,Width,Height,40,TfpgColor($0),TfpgColor($FFFFFF));
(I used fpgui for your convenience!)
Of course it can be improved, but what cannot? :-)

Regards,

Giuliano


{ This procedure creates a sunken 3d effect in a rectangle with a color 
gradient }
procedure FillRectGradient(canvas: TfpgCanvas; X,Y,W,H: TfpgCoord; Strip: 
Integer; Astart,Astop: TfpgColor);
var
  RGBStart: TRGBTriple;
  RGBStop: TRGBTriple;
  RDiff, GDiff, BDiff: Integer;
  count: Integer;
  i: Integer;
  newcolor: TRGBTriple;
  Hx,Hy: TfpgCoord; // Coordinates for Horizontal Lines
  Vx,Vy: TfpgCoord; // Coordinates for Vertical Lines

begin
  RGBStart := fpgColorToRGBTriple(fpgColorToRGB(AStart));
  RGBStop  := fpgColorToRGBTriple(fpgColorToRGB(AStop));

  count := Strip;
  Hx := X;
  Hy := Y;
  Vx := X;
  Vy := Y;

  RDiff := RGBStop.Red - RGBStart.Red;
  GDiff := RGBStop.Green - RGBStart.Green;
  BDiff := RGBStop.Blue - RGBStart.Blue;

//  Changing;
  canvas.BeginDraw;
  for i := 0 to count do
  begin
    newcolor.Red    := RGBStart.Red + (i * RDiff) div count;
    newcolor.Green  := RGBStart.Green + (i * GDiff) div count;
    newcolor.Blue   := RGBStart.Blue + (i * BDiff) div count;


    canvas.SetLineStyle(1,lsSolid);
    canvas.SetColor(RGBTripleTofpgColor(newcolor));
    canvas.DrawLine(Hx,Hy,W,Hy); // Horizontal Line
    canvas.DrawLine(Vx,Vy,Vx,H); // Vertical Line
    // next Horizontal Line: one pixel lower, one pixel shorter on the left
    Hx := Hx + 1;
    Hy := Hy + 1;
    // Next Vertical Line: One pixel to the right, one pixel shorter on top
    Vx := Vx + 1;
    Vy := Vy + 1;
  end;
//  Changed;
    canvas.EndDraw;
end;

<<inline: SunkenRect.png>>

Reply via email to