Page 1 of 2

How to paint a Transparent Bitmap on a Gradiant Dialog

Posted: Thu Dec 21, 2006 5:32 am
by RAMESHBABU
Hello

Can anybody guide me on the subject.

I tried with the following code and the result is :

Image

Regards

- Ramesh Babu P

Code: Select all


#include "FiveWin.ch"

FUNCTION Main()

LOCAL oDlg, oBmp, hDC

DEFINE DIALOG oDlg SIZE 212, 106                                  ;
       COLORS CLR_BLACK, nRGB(224,167,64) TRANSPARENT PIXEL

@ 10, 15 BITMAP oBmp FILE "C:\FWH\BITMAPS\QUESTION.BMP" OF oDlg   ;
       SIZE 20, 30 PIXEL NOBORDER

ACTIVATE DIALOG oDlg CENTERED  ON PAINT                           ;
         gradiate_(oDlg, hDC, {CLR_WHITE, nRgb(224,167,64)},      ;
                   2,{0,0,oDlg:nHeight,oDlg:nWidth})

RETURN nil

******************************************************************

FUNCTION gradiate_( hWnd, hDC, aClrPan, nFund, aCoors)

LOCAL nColor1,  nColor2,  nSoma,    nSteps
LOCAL nColorR1, nColorB1, nColorG1, nColorR2, nColorB2, nColorG2
LOCAL nSomaR,   nSomaG,   nSomaB
LOCAL nTamaAlt, nTamaLar, nFundAlt, nFundLar, aRect, aRect1, oBrush

nTamaAlt := (aCoors[3]-aCoors[1]) 
nTamaLar := (aCoors[4]-aCoors[2]) 

nFundAlt := nTamaAlt 
aRect    := {0,0,nFundAlt,nTamaLar}
nSteps   := nFundAlt
nSoma    := nSteps / 100

nColor1  := aClrPan[Iif(nFund>0,1,2)]
nColor2  := aClrPan[Iif(nFund>0,2,1)]

nColorR1 := nRgbRed(nColor1)
nColorG1 := nRgbGreen(nColor1)
nColorB1 := nRgbBlue(nColor1)

nColorR2 := nRgbRed(nColor2)
nColorG2 := nRgbGreen(nColor2)
nColorB2 := nRgbBlue(nColor2)

nSomaR   := Abs(nColorR2-nColorR1)
nSomaG   := Abs(nColorG2-nColorG1)
nSomaB   := Abs(nColorB2-nColorB1)

nSomaR   := IIF( nSomaR < 0,1,(nSomaR/(nFundAlt/2)))
nSomaG   := IIF( nSomaG < 0,1,(nSomaG/(nFundAlt/2)))
nSomaB   := IIF( nSomaB < 0,1,(nSomaB/(nFundAlt/2)))

aRect[3] := 0

DO WHILE aRect[3] <= nFundAlt

   aRect[ 3 ] += nSoma

   DEFINE BRUSH oBrush COLOR nRGB(nColorR1 , nColorG1, nColorB1 )

	 FillRect( hDC, aRect, oBrush:hBrush )

	 RELEASE Brush oBrush

   aRect[ 1 ] += nSoma

   nColorR1 := INT(IIF(nColorR2 >= nColorR1,nColorR1+nSomaR,nColorR1-nSomaR))
 	 nColorG1 := INT(IIF(nColorG2 >= nColorG1,nColorG1+nSomaG,nColorG1-nSomaG))
	 nColorB1 := INT(IIF(nColorB2 >= nColorB1,nColorB1+nSomaB,nColorB1-nSomaB))
	 nColorR1 := IIF(nColorR1<0,0,IIF(nColorR1>255,255,nColorR1))
	 nColorG1 := IIF(nColorG1<0,0,IIF(nColorG1>255,255,nColorG1))
   nColorB1 := IIF(nColorB1<0,0,IIF(nColorB1>255,255,nColorB1))

ENDDO

SysRefresh()

RETURN nil

**********


Posted: Thu Dec 21, 2006 8:05 am
by Antonio Linares
Ramesh,

Please try this:

Code: Select all

@ 10, 15 BITMAP oBmp FILE "C:\FWH\BITMAPS\QUESTION.BMP" OF oDlg   ; 
       SIZE 20, 30 PIXEL NOBORDER 

oBmp:lTransparent = .t.

Posted: Thu Dec 21, 2006 8:51 am
by areang
Mr. Antonio

Code: Select all

@ 10, 15 BITMAP oBmp FILE "C:\FWH\BITMAPS\QUESTION.BMP" OF oDlg   ; 
       SIZE 20, 30 PIXEL NOBORDER 


oBmp:lTransparent = .t.

Not work.

Areang

Posted: Thu Dec 21, 2006 9:02 am
by Antonio Linares
Areang,

Using FWH 6.12:
Image

Code: Select all

#include "FiveWin.ch"

function Main()

   local oDlg, oBrush, oBmp
   local cName := "Test"

   DEFINE BRUSH oBrush FILENAME "..\bitmaps\backgrnd\rainbow.bmp"

   DEFINE DIALOG oDlg FROM 5, 5 TO 15, 40 TITLE "Testing Valid" BRUSH oBrush

   @ 2, 5 GET cName SIZE 80, 12
   
   @ 20, 10 BITMAP oBmp FILE "..\BITMAPS\QUESTION.BMP" OF oDlg ; 
       SIZE 20, 30 PIXEL NOBORDER 

   oBmp:lTransparent = .t.   

   ACTIVATE DIALOG oDlg ;
      VALID( MsgInfo( "Valid Clause" ), .t. )
      
   oBrush:End()   

return nil

Posted: Thu Dec 21, 2006 9:07 am
by areang
Mr. Antonio

Yes that's work but Mr. Ramesh paint Bitmap on this source code

Code: Select all

gradiate_(oDlg, hDC, {CLR_WHITE, nRgb(224,167,64)},      ; 
                   2,{0,0,oDlg:nHeight,oDlg:nWidth})
not on bmp object !!

best Regard
areang

Posted: Thu Dec 21, 2006 9:16 am
by Antonio Linares
I see, but its much better to use a bitmap (that can simulate a gradient too) as it executes much faster

Posted: Thu Dec 21, 2006 9:20 am
by areang
Mr. Ramesh, Mr. Antonio

Yes I agree !!! :lol:


regards
Areang

Posted: Thu Dec 21, 2006 9:27 am
by Antonio Linares
Using a bitmap with the same gradient:

Image

Posted: Thu Dec 21, 2006 9:39 am
by areang
Mr. Antonio

That's bitmap brush.

When the size of Bitmap < (less than) my dialog size, the brush get tile on my dialog surfaces.

Regards
Areang

Posted: Thu Dec 21, 2006 10:01 am
by Antonio Linares
Areang,

Yes, the bitmap has to be larger or equal than the dialog height.

Posted: Thu Dec 21, 2006 11:15 am
by RAMESHBABU
Mr.Antonio and Mr.Areang

Thank you very much for your replies.

I know that the gradiant dialog can be painted using a gradiant bitmap brush. But if I use different bitmaps for different dialogs, the size of my application, is becoming much bigger depending on the size of dialogs and the their bitmaps used as brushes.

Can you please suggest me any work around to stick to my requirement.

Regards and Greetings to You both and Fivetech Staff also.

- Ramesh Babu P

Posted: Thu Dec 21, 2006 1:32 pm
by Antonio Linares
Ramesh,

It looks as the controls get painted before the ON PAINT event, thats why the bitmap does not paints transparent.

You may have several differents gradients bitmaps and use the right one for the dialog height that you need.

Posted: Thu Dec 21, 2006 5:07 pm
by RAMESHBABU
Mr.Antonio
It looks as the controls get painted before the ON PAINT event, thats why the bitmap does not paints transparent.
Can you please give me some guidance to check the above point and
find a work around way?

By the way ON PAINT and ON INIT which one occurs first ?

Regards

- Ramesh Babu P

Posted: Thu Dec 21, 2006 5:55 pm
by Antonio Linares
Ramesh,

ON INIT is executed before ON PAINT.

Anyhow, its not easy to find a workaround for that issue. Maybe the bitmap Method Paint() should call the parent window gradient painting function directly before it paints the bitmap. You may try it.

Posted: Fri Dec 22, 2006 2:48 am
by RAMESHBABU
Mr.Antonio

Thank you much for your replies.

I hope that I can find out a solution.

Regards to you,

- Ramesh Babu P