How to paint a Transparent Bitmap on a Gradiant Dialog

How to paint a Transparent Bitmap on a Gradiant Dialog

Postby RAMESHBABU » Thu Dec 21, 2006 5:32 am

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  Expand view

#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
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Thu Dec 21, 2006 8:05 am

Ramesh,

Please try this:
Code: Select all  Expand view
@ 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby areang » Thu Dec 21, 2006 8:51 am

Mr. Antonio
Code: Select all  Expand view
@ 10, 15 BITMAP oBmp FILE "C:\FWH\BITMAPS\QUESTION.BMP" OF oDlg   ;
       SIZE 20, 30 PIXEL NOBORDER


oBmp:lTransparent = .t.



Not work.

Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Postby Antonio Linares » Thu Dec 21, 2006 9:02 am

Areang,

Using FWH 6.12:
Image
Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby areang » Thu Dec 21, 2006 9:07 am

Mr. Antonio

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


not on bmp object !!

best Regard
areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Postby Antonio Linares » Thu Dec 21, 2006 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby areang » Thu Dec 21, 2006 9:20 am

Mr. Ramesh, Mr. Antonio

Yes I agree !!! :lol:


regards
Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Postby Antonio Linares » Thu Dec 21, 2006 9:27 am

Using a bitmap with the same gradient:

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby areang » Thu Dec 21, 2006 9: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
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

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

Postby RAMESHBABU » 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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Thu Dec 21, 2006 1: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby RAMESHBABU » Thu Dec 21, 2006 5: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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Thu Dec 21, 2006 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby RAMESHBABU » Fri Dec 22, 2006 2: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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 70 guests