FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to paint a Transparent Bitmap on a Gradiant Dialog
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 05:32 AM
Hello

Can anybody guide me on the subject.

I tried with the following code and the result is :



Regards

- Ramesh Babu P

#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

**********
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 08:05 AM
Ramesh,

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

oBmp:lTransparent = .t.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 128
Joined: Mon Jul 31, 2006 03:23 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 08:51 AM
Mr. Antonio
@ 10, 15 BITMAP oBmp FILE "C:\FWH\BITMAPS\QUESTION.BMP" OF oDlg   ; 
       SIZE 20, 30 PIXEL NOBORDER 


oBmp:lTransparent = .t.


Not work.

Areang
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 09:02 AM
Areang,

Using FWH 6.12:

#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 128
Joined: Mon Jul 31, 2006 03:23 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 09:07 AM
Mr. Antonio

Yes that's work but Mr. Ramesh paint Bitmap on this source code
gradiate_(oDlg, hDC, {CLR_WHITE, nRgb(224,167,64)},      ; 
                   2,{0,0,oDlg:nHeight,oDlg:nWidth})


not on bmp object !!

best Regard
areang
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 09:16 AM

I see, but its much better to use a bitmap (that can simulate a gradient too) as it executes much faster

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 128
Joined: Mon Jul 31, 2006 03:23 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 09:20 AM

Mr. Ramesh, Mr. Antonio

Yes I agree !!! :lol:

regards
Areang

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 09:27 AM
Using a bitmap with the same gradient:

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 128
Joined: Mon Jul 31, 2006 03:23 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 09:39 AM

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

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 10:01 AM

Areang,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 11:15 AM

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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 01:32 PM

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.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 05:07 PM
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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Thu Dec 21, 2006 05:55 PM

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.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
How to paint a Transparent Bitmap on a Gradiant Dialog
Posted: Fri Dec 22, 2006 02:48 AM

Mr.Antonio

Thank you much for your replies.

I hope that I can find out a solution.

Regards to you,

  • Ramesh Babu P