How to paint a Transparent Bitmap on a Gradiant Dialog

User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

How to paint a Transparent Bitmap on a Gradiant Dialog

Post 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

**********

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
areang
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

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

Antonio Linares
www.fivetechsoft.com
areang
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
areang
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Post by areang »

Mr. Ramesh, Mr. Antonio

Yes I agree !!! :lol:


regards
Areang
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Using a bitmap with the same gradient:

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
areang
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Areang,

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

Antonio Linares
www.fivetechsoft.com
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post 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
Post Reply