Page 1 of 1

Gradient

PostPosted: Wed Nov 28, 2007 12:21 am
by Silvio
Antonio,

where I can found gradient function ?

I can create Horizontal gradient or vertical gradient also ?

Thanks

PostPosted: Wed Nov 28, 2007 5:07 am
by James Bott

PostPosted: Wed Nov 28, 2007 8:20 am
by Antonio Linares
Silvio,

You can create both of them, just use .T. or .F. as the last parameter when calling Gradient()

PostPosted: Wed Nov 28, 2007 12:46 pm
by Maurilio Viana
How can I create a gradient like Windows Vista buttons?
The gradient top is clear, the middle of object is darker and bottom is clear

Regards
Maurilio

PostPosted: Thu Nov 29, 2007 12:33 am
by Silvio
Antonio,
thanks but which is the file ?
where i can found the function gradient source code ?

PostPosted: Thu Nov 29, 2007 12:44 am
by toya
Maurilio, para teres uma idéia, faça uma pequena alteração nos exemplos do link acima:
Code: Select all  Expand view
...
for i = 255 TO 0 STEP -1


   DEFINE BRUSH oBrush COLOR RGB( 0, i, 0 ) //<--- aqui


   FILLRECT( hDC, aRect, oBrush:hBrush )
   RELEASE BRUSH oBrush
   aRect[ 1 ] += nStep
   aRect[ 3 ] += nStep
next
...

PostPosted: Thu Nov 29, 2007 12:45 am
by Antonio Linares
Maurilio,

Two calls to Gradient() functions are done:

1. From clear to dark
2. From dark to clear

PostPosted: Thu Nov 29, 2007 12:45 am
by Antonio Linares
Silvio,

We have not published the Gradient() source code yet

PostPosted: Thu Nov 29, 2007 5:27 am
by James Bott
Antonio,

It would be nice to have gradient capability added to the TWindow class. You could add a couple of parameters to the setColor() method to handle the extra needed color and the vertical/horzontal parameter. Then all the subclasses would inherit the gradient capability.

But, I expect you have already thought of that.

Regards,
James

PostPosted: Thu Nov 29, 2007 10:16 am
by Antonio Linares
James,

Gradient() should not be used intensively because it is a very slow function that creates lots of brushes (pushing the GDI to its limits) and takes too long to do its work.

The right way is to copy a bitmap (stretching it) instead of using gradients. We have used this technique in FWH 7.12 to paint the message bar and now it works much more faster.

Keep in mind that copying a bitmap you can use any drawing design, so the final result is much richer in details :-)

PostPosted: Thu Nov 29, 2007 3:30 pm
by James Bott
Antonio,

>Gradient() should not be used intensively because it is a very slow function that creates lots of brushes (pushing the GDI to its limits) and takes too long to do its work.

Good point. Are you using a C function for this. I have tried gradients with a few test programs and it didn't seem too slow, but these were very small programs like with one dialog.

>The right way is to copy a bitmap (stretching it) instead of using gradients. We have used this technique in FWH 7.12 to paint the message bar and now it works much more faster.

So where is the bitmap stored? Is it embedded in the FW code somehow?

I have used bitmaps to do this also, but my bitmaps are stored in the RC file and I did not know we could stretch them to fit so it was very tedious making a bitmap of the proper size. Can you show us how to stretch a bitmap to fit a dialog or window?

>Keep in mind that copying a bitmap you can use any drawing design, so the final result is much richer in details.

I like that idea.

James

PostPosted: Thu Nov 29, 2007 3:53 pm
by Antonio Linares
James,

> Are you using a C function for this.

Yes, and even using C code, it is slow. Thats why we should try to avoid it and use StretchBlt().

> So where is the bitmap stored? Is it embedded in the FW code somehow?

Yes, it is embedded in a C module. Its quite simple: You open the bitmap with the Borland resources workshop, edit it as text, and then copy the bytes to a C array. From that C array, the bitmap is dinamically created in memory.

> I did not know we could stretch them to fit

Thats what StretchBlt() is for.

> Can you show us how to stretch a bitmap to fit a dialog or window?

In just few days FWH 7.12 will be published and the source code for stretching a bitmap will be available, and a working sample: the Class TMsgBar.

PostPosted: Thu Nov 29, 2007 3:58 pm
by James Bott
Antonio,

Got it. Thanks.

James

PostPosted: Fri Dec 07, 2007 9:17 am
by StefanHaupt
Dear friends,

I wrote a little tool that manages the conversion from a bitmap into a C array . So you can embed the bitmap in your C file very easily.

May be it´s useful.

You can download it here:
BmpInfo.zip (1.66 MB)

Image