Recent

Author Topic: [Wiki] Double Gradient article  (Read 31258 times)

lainz

  • Guest
Re: [Wiki] Double Gradient article
« Reply #15 on: February 19, 2011, 04:53:46 pm »
Or you OO-ify it a bit so it's easier to re-use, something like:
Code: Pascal  [Select][+][-]
  1.   // Gradientfiller for the form background
  2.   // It's a 50/50 scale so both gradients meet in the middle.
  3.   gfPaint := TGradientFiller.Create(gdHorizontal);
  4.   gfPaint.AddGradient(clYellow, clBlue, gdHorizontal, 50);
  5.   gfPaint.AddGradient(clBlue, clGreen, gdHorizontal, 50);
  6.   //...
  7.   // Form paint:
  8.   gfPaint.Draw(self.Canvas, self.ClientRect);
  9.  
Couldn't resist  :D



here is a new article about this 'Gradient Filler':

http://wiki.lazarus.freepascal.org/Gradient_Filler

The article is a draft.
« Last Edit: February 19, 2011, 04:57:39 pm by lainz »

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: [Wiki] Double Gradient article
« Reply #16 on: February 19, 2011, 05:49:48 pm »
Errors, I would not say something, if it worked fine.
Whats on you not on me?  I think where both using Lazarus latest stable version. :D
Couldn't say. My version is in my sig; do you have the same (or newer) version?
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

mac.1

  • Newbie
  • Posts: 6
Re: [Wiki] Double Gradient article
« Reply #17 on: February 19, 2011, 08:22:47 pm »
If there were errors, pls say the error message and the line.

I'm working on a Transparent Version - So you can overlay 2 Gradients. But it is very slow ( 100ms for 400x300 on intel 2500k)
It's also working, but it seems only to work with TImage.

Maybe a multithreading version will follow - but at the moment i haven't enought time for that...

lainz

  • Guest
Re: [Wiki] Double Gradient article
« Reply #18 on: February 20, 2011, 02:16:42 am »
nGradient with alpha is very slow, try to use TBGRABitmap instead TBitmap.

I think 'Gradient Filler' is better than 'Double Gradient' & 'nGradient' because is object oriented and have more features.

EDIT: but Gradient Filler has a flickering bug, when you change a property, like 'globaldirection' and repaint a paintbox the first thing you can see is a red background, also if you are using 'self.doublebuffered:=true', to avoid this first you need to store the gradient in a bitmap and then draw the bitmap instead drawing directly the Tgradientfiller.
« Last Edit: February 20, 2011, 07:40:26 pm by lainz »

qdos

  • Full Member
  • ***
  • Posts: 112
Re: [Wiki] Double Gradient article
« Reply #19 on: February 21, 2011, 12:19:15 pm »
I get a an error message.
It reacts to "  for p in FGradients do  " ??

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: [Wiki] Double Gradient article
« Reply #20 on: February 21, 2011, 02:28:10 pm »
I get a an error message.
It reacts to "  for p in FGradients do  " ??
I use the new 'for x in y' syntax that was introduced in a recent version of FPC (see my sig).
If you use an older version you'll have to iterate through the list via an integer:
Code: Pascal  [Select][+][-]
  1. var i: integer;
  2.     gi: TGradientInfo;
  3. //...
  4.   for i := 0 to FGradients.Count-1 do        
  5.   begin
  6.     gi := FGradients(i) as TGradientInfo;
  7.     // do processing...
Note the brackets in 'FGradients(i)' are square brackets, but I don't know how to post them.

EDIT: but Gradient Filler has a flickering bug
Not really: the idea is that GradientFiller paints a gradient on a canvas be it a Form.Canvas or a Bitmap.Canvas.
If used directly on a visible canvas it might flicker, as does all painting on a visible Canvas.
FWIW: if I set DoubleBuffered to true on my own forms, the flicker is gone.

Having said that: it's very easy to exend the functionality of TGradientFiller to store a local copy of the gradient and use that in the Draw method.
And only regenerate when any of the properties change...
« Last Edit: February 21, 2011, 02:51:54 pm by eny »
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

lainz

  • Guest
Re: [Wiki] Double Gradient article
« Reply #21 on: February 21, 2011, 10:45:42 pm »
Code: [Select]
Not really: the idea is that GradientFiller paints a gradient on a canvas be it a Form.Canvas or a Bitmap.Canvas.
If used directly on a visible canvas it might flicker, as does all painting on a visible Canvas.
FWIW: if I set DoubleBuffered to true on my own forms, the flicker is gone.

Yes i forget it, thanks I will try Bitmap.Canvas.

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: [Wiki] Double Gradient article
« Reply #22 on: February 26, 2011, 04:53:27 pm »
An update on the gradient subject.
There is a Delphi component TGradient that generates some more fancy gradients (http://www.delphiarea.com/downloads). It's incompatible with Lazarus because of the use of TBitmap.ScanLine.
The attachment contains a lazarus class (TGradientsFiller) that solves that and a demo app to show it's use.
Have fun.
« Last Edit: February 26, 2011, 05:07:15 pm by eny »
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: [Wiki] Double Gradient article
« Reply #23 on: February 26, 2011, 06:41:31 pm »
Nice Form;
I'm only using
Quote
lazarus-0.9.28.2-fpc-2.2.4-win32 <stable>
Probably it won't work out, just as I tried the first sample code.

The error line;
Quote
// Populate the listbox with all style descriptions
  for s in C_STYLE_DESCRIPTION do

The error message;
Quote
ufrmmain1.pas(87,7) Error: Ordinal expression expected
ufrmmain1.pas(87,9) Fatal: Syntax error, ":=" expected but "in" found

Can you attach an exe zip file, just exited to view it personally.


thanks
« Last Edit: February 26, 2011, 07:29:34 pm by xenablaise »

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: [Wiki] Double Gradient article
« Reply #24 on: February 26, 2011, 08:03:19 pm »
The 'downgrade' is fairly easy to do. Change the loop to:
Code: Pascal  [Select][+][-]
  1. var i: TGradientstyle;
  2. //...
  3.   for i := low(C_STYLE_DESCRIPTION) to high(C_STYLE_DESCRIPTION) do
  4.     cbStyles.Items.Append(C_STYLE_DESCRIPTION[ i ]);

Can you attach an exe zip file, just exited to view it personally.

Sure: Win$ only...
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: [Wiki] Double Gradient article
« Reply #25 on: February 26, 2011, 08:40:30 pm »
I got the binary, but I didn't fix the code with the one you gave
 
Quote
  var i: TGradientstyle; 

 for i := low(C_STYLE_DESCRIPTION) to high(C_STYLE_DESCRIPTION) do 
cbStyles.Items.Append(C_STYLE_DESCRIPTION[ i ]); 

Probably because I'm using;
lazarus-0.9.28.2-fpc-2.2.4-win32 <stable>
and NOT like your signature version


but, thanks a lot, really. :D

lainz

  • Guest
Re: [Wiki] Double Gradient article
« Reply #26 on: February 28, 2011, 10:19:52 pm »
I got the binary, but I didn't fix the code with the one you gave
 
Quote
  var i: TGradientstyle; 

 for i := low(C_STYLE_DESCRIPTION) to high(C_STYLE_DESCRIPTION) do 
cbStyles.Items.Append(C_STYLE_DESCRIPTION[ i ]); 

Probably because I'm using;
lazarus-0.9.28.2-fpc-2.2.4-win32 <stable>
and NOT like your signature version


but, thanks a lot, really. :D

is very old 'stable' 0.9.28.

The new gradients filler is cool :D

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: [Wiki] Double Gradient article
« Reply #27 on: March 03, 2011, 01:31:59 am »
Quote
The new gradients filler is cool
Very Cool :D

The usage?
is the problem, because you have to use semi transparent buttons, listboxex, labels, and others.

If you don't?, your form will look very fancy and lazy :P


It's much better if you guys include transparent tabsets, boxes, buttons, labels.  From that, lets see what the form looks like. :o

lainz

  • Guest
Re: [Wiki] Double Gradient article
« Reply #28 on: March 03, 2011, 04:23:34 am »
Quote
The new gradients filler is cool
Very Cool :D

The usage?
is the problem, because you have to use semi transparent buttons, listboxex, labels, and others.

If you don't?, your form will look very fancy and lazy :P


It's much better if you guys include transparent tabsets, boxes, buttons, labels.  From that, lets see what the form looks like. :o

I don't know how.

This isn't only for Forms backround, you can use with paintbox or with custom controls.

 

TinyPortal © 2005-2018