Recent

Author Topic: [SOLVED] Gradient  (Read 475 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 528
[SOLVED] Gradient
« on: September 02, 2023, 06:14:57 pm »
Hello, I have a question, is it possible to adjust the position of the gradient?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel1Paint(Sender: TObject);
  2. var
  3.   R: TRect;
  4. begin
  5.   R := Rect(0, 0, Panel1.Width, Panel1.Height);
  6.   Panel1.Canvas.GradientFill(R, clGreen, clRed, gdHorizontal);
  7. end;
  8.  
« Last Edit: September 02, 2023, 09:01:11 pm by Pe3s »

lainz

  • Hero Member
  • *****
  • Posts: 4278
    • https://lainz.github.io/
Re: Gradient
« Reply #1 on: September 02, 2023, 06:54:32 pm »
Hello, I have a question, is it possible to adjust the position of the gradient?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel1Paint(Sender: TObject);
  2. var
  3.   R: TRect;
  4. begin
  5.   R := Rect(0, 0, Panel1.Width, Panel1.Height);
  6.   Panel1.Canvas.GradientFill(R, clGreen, clRed, gdHorizontal);
  7. end;
  8.  

You say the angle, or the x, y values? The angle gdHorizontal or gdVertical, the position is defined in the rectangle.

If you want more advanced gradients with more angles try BGRABitmap.

Pe3s

  • Hero Member
  • *****
  • Posts: 528
Re: Gradient
« Reply #2 on: September 02, 2023, 07:00:03 pm »
Yes, x or y value. Sorry, I didn't write it


wp

  • Hero Member
  • *****
  • Posts: 11482
Re: Gradient
« Reply #3 on: September 02, 2023, 07:44:17 pm »
The TCanvas.GradientFill is quite limited, compared to BGRABitmap or other high-end graphics libraries. It fills the specified rectangle from left to right (gdHorizontal) or from top to bottom (gdVertical) using only the two specified colors at the gradient start and end positions (left/right or top/bottom, respectively).

If you need a multi-color gradient you can split the rectangle into several parts and fill them by their own two-color gradients. The attached project, for example, draws a horizontal gradient between yellow and red over the left part of the PaintBox where the width of this part is defined by the relative position of the scrollbar, and a gradient from red to blue over the rest of the Paintbox.

Pe3s

  • Hero Member
  • *****
  • Posts: 528
Re: Gradient
« Reply #4 on: September 02, 2023, 09:00:56 pm »
Thank you all for your help  :)

 

TinyPortal © 2005-2018