Transparent Controls using < FILLRECT > ?

Transparent Controls using < FILLRECT > ?

Postby ukoenig » Sun May 12, 2013 4:38 pm

Hello,

is there a solution, painting controls
transparent on FILLRECT ?
The dialog background is splitted in 3 sections with different bush-styles.

Called inside the Dialog :

oGDialog:bPainted := {|hDC| D_BRUSH2 (oGDialog, hDC, nSplTop, cPBrush) }

Defined inside the Function ::

hBmp = ReadBitmap( 0, c_path1 + cPBrush[I] )
hBrush = CreatePatternBrush( hBmp )
DeleteObject( hBmp )
FillRect( hDC, { nSplTop[I], 0, nSplBott[I], oGDialog:nWidth }, hBrush )

Image

A sample :

Image

Code: Select all  Expand view

FUNCTION MAIN()
LOCAL oDlg, oSay1, oSay2
c_path := cFilePath(GetModuleFileName( GetInstance() ) )
c_path1 := c_path + "IMAGES\"
oFont := TFont():New("
Arial",0,-40,.F.,.T.,0,0,0,.T. )

DEFINE BRUSH oBrush FILE c_path1 + "
Paper.bmp"

DEFINE DIALOG oDlg from 0,0 to 400, 500 pixel TITLE "
Brush-Test" BRUSH oBrush TRANSPARENT

@ 30, 30 SAY oSay1 PROMPT "
Transparent Say 1" ;
OF oDlg SIZE 190, 30 FONT oFont PIXEL
oSay1:SetColor( 0, )

@ 130, 30 SAY oSay2 PROMPT "
Transparent Say 2" ;
OF oDlg SIZE 190, 30 FONT oFont PIXEL
oSay2:SetColor( 0, )

oDlg:bPainted := {|hDC| SET_BRUSH( oDlg, hDC, "
Blustone.bmp" ) }

ACTIVATE DIALOG oDlg CENTERED

oFont:End()

RETURN NIL

//--------- 2. Brush ------------------------

FUNCTION SET_BRUSH( oDlg, hDC, cBrush )
LOCAL oImage, oBrush, hBmp

hBmp = ReadBitmap( 0, c_path1 + cBrush )
hBack =  CreatePatternBrush( hBmp )
DeleteObject( hBmp )
FillRect( hDC, { 150, 0, oDlg:nHeight, oDlg:nWidth  }, hBack )

RETURN NIL


Best Regards
Uwe :?:
Last edited by ukoenig on Mon May 13, 2013 9:05 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Transparent Controls using < Fillrect > ?

Postby Antonio Linares » Mon May 13, 2013 12:36 pm

Uwe,

Try to reassign the brush on the second SAY:

oSay2:SetBrush( oNewBrush )
regards, saludos

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

Re: Transparent Controls using < Fillrect > ?

Postby ukoenig » Mon May 13, 2013 7:20 pm

Antonio,

Thank You very much.
It works, but only with Controls supporting brushes like xbrowse.
I added 2 browser to the sample ( used a very simple style )
as well transparent TTitles with Alpha-image..
The new sample detects the control-position
and uses the defined dialog-brush-section as own brush
As soon a control supports brushes, it works.
( maybe sounds a little bit complicated )
Instead of using < Fillrect > a solution would be, to define a brush-area ?
For the moment the complete contol is filled with a defined brush.

Image

Code: Select all  Expand view

FUNCTION MAIN()
LOCAL oDlg, oBrw1, oBrw2, oSay1, oSay2, oBrush1, oBrush2, oBrush3
LOCAL aArray := {}, oTitle1, oTitle2

if empty( aArray )                          
      aArray := {{"one","two","three","four"},;
        {"one","two","three","four"}}    
endif

c_path := cFilePath(GetModuleFileName( GetInstance() ) )
c_path1 := c_path + "IMAGES\"
oFont := TFont():New("
Arial",0,-40,.F.,.T.,0,0,0,.T. )

DEFINE BRUSH oBrush1 FILE c_path1 + "
Paper.bmp"
DEFINE BRUSH oBrush2 FILE c_path1 + "
Blustone.bmp"
DEFINE BRUSH oBrush3 FILE c_path1 + "
Marble.bmp"

DEFINE DIALOG oDlg from 0,0 to 400, 500 pixel TITLE "
Brush-Test"

@ 10, 30 SAY oSay1 PROMPT "
Transparent Say 1" ;
OF oDlg SIZE 190, 30 FONT oFont PIXEL UPDATE
// oSay1:lTransparent := .T.
oSay1:SetColor( 0,  )

@ 40, 25 XBROWSE oBrw1 SIZE 180, 50 PIXEL OF oDlg               ;
COLUMNS 1, 2, 3, 4                    ;
HEADERS "
One","Two","Three","Four"   ;
COLSIZES 50, 50, 50, 50           ;
ARRAY aArray LINES FASTEDIT CELL

WITH OBJECT oBrw1
      :nEditTypes   := EDIT_GET
      :CreateFromCode()
END

@ 45,165 TITLE oTitle1 size 70, 45 of oDlg SHADOW TOPRIGHT
oTitle1:lTransparent := .T.
@ 5,  30 TITLEIMG OF oTitle1 BITMAP c_path1 + "
Logo7.bmp"  ;
SIZE 100, 80 REFLEX TRANSPARENT

@ 110, 30 SAY oSay2 PROMPT "
Transparent Say 2" ;
OF oDlg SIZE 190, 30 FONT oFont PIXEL UPDATE
// oSay2:lTransparent := .T.
oSay2:SetColor( 0, )

oDlg:bPainted := {|hDC| SET_BR1( oDlg, hDC, 1, "
Paper.bmp" ), ;
                                               SET_BR1( oDlg, hDC, 2, "
Blustone.bmp" ) }

@ 140, 25 XBROWSE oBrw2 SIZE 180, 50 PIXEL OF oDlg               ;
COLUMNS 1, 2, 3, 4                    ;
HEADERS "
One","Two","Three","Four"   ;
COLSIZES 50, 50, 50, 50           ;
ARRAY aArray LINES FASTEDIT CELL

WITH OBJECT oBrw2
      :nEditTypes   := EDIT_GET
      :CreateFromCode()
END

@ 145,165 TITLE oTitle2 size 70, 45 of oDlg SHADOW TOPRIGHT
oTitle2:lTransparent := .T.
@ 5,  30 TITLEIMG OF oTitle2 BITMAP c_path1 + "
Logo7.bmp"  ;
SIZE 100, 80 REFLEX TRANSPARENT

ACTIVATE DIALOG oDlg CENTERED ;
ON INIT SET_BR2( oDlg, oBrush1, oBrush2 )

oFont:End()
oBrush1:End()
oBrush2:End()

RETURN NIL

//--------- Background ------------------------

FUNCTION SET_BR1( oDlg, hDC, nSection, cBrush )
LOCAL oImage, hBmp

hBmp = ReadBitmap( 0, c_path1 + cBrush )
hBack =  CreatePatternBrush( hBmp )
DeleteObject( hBmp )
IF nSection = 1
    FillRect( hDC, { 0, 0, 190, oDlg:nWidth  }, hBack )
ENDIF
IF nSection = 2
    FillRect( hDC, { 190, 0, oDlg:nBottom, oDlg:nWidth  }, hBack )
ENDIF

RETURN NIL

// ---------------------

FUNCTION SET_BR2( oDlg, oBrush1, oBrush2 )
LOCAL oBrush, nColor := 0

I := 1
FOR I := 1 TO LEN( oDlg:aControls )
//  IF oDlg:aControls[I]:lTransparent = .T.
        IF oDlg:aControls[I]:nTop < 150  // Define top Section
            // MsgAlert( oDlg:aControls[I]:nTop, "
1. Section" )
            oBrush := oBrush1
            nColor := 255
        ELSEIF oDlg:aControls[I]:nTop > 150
            // MsgAlert( oDlg:aControls[I]:nTop, "
2. Section" )
            oBrush := oBrush2
            nColor := 8454143 // 16711680
        ENDIF
        oDlg:aControls[I]:SetBrush( oBrush )
        // oDlg:aControls[I]:SetColor ( 0, nColor ) // SetBrush( oBrush )
//  ENDIF
NEXT

RETURN NIL


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: jmartial and 76 guests