A problem with GradientBrush()

A problem with GradientBrush()

Postby Enrico Maria Giordano » Thu Jan 28, 2010 4:37 pm

In the sample gradbrus.prg, please try to click on "First" button, then on "Another" button and then close and reopen the second dialog many times. Now move the second dialog over the first. You will see that the first dialog is now painted with robbish.

Any hint on how to fix this behavior?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Fri Jan 29, 2010 8:57 am

A reduced sample of the problem. Just click on the button and move the second dialog over the first. You will see the problem:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld
   
    IF EMPTY( oDlg:oBrush:hBitmap )
        hDC = CREATECOMPATIBLEDC( oDlg:GetDC() )
        hBmp = CREATECOMPATIBLEBITMAP( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
        hBmpOld = SELECTOBJECT( hDC, hBmp )
        GRADIENTFILL( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby anserkk » Fri Jan 29, 2010 9:25 am

Dear EMG,

I tested your sample code but I did not experience the problem which you have explained. For me it is working fine.

I am using Vista Business, FWH 9.08.

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Fri Jan 29, 2010 9:27 am

So the problem is at least under XP.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby anserkk » Fri Jan 29, 2010 9:36 am

So the problem is at least under XP.


or with the recent versions of FWH ( after 9.08 )

Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Fri Jan 29, 2010 10:11 am

This is a workaround:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    oDlg:aControls[ 1 ]:bLostFocus = { || oDlg:Refresh() }

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SendMsg( WM_PAINT );
             ON PAINT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld
   
    IF EMPTY( oDlg:oBrush:hBitmap )
        hDC = CREATECOMPATIBLEDC( oDlg:GetDC() )
        hBmp = CREATECOMPATIBLEBITMAP( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
        hBmpOld = SELECTOBJECT( hDC, hBmp )
        GRADIENTFILL( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL


Any better ideas?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Fri Jan 29, 2010 10:23 am

Even worst. In the following sample, try to move the second dialog and you will see that the first dialog is painted:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SendMsg( WM_PAINT );
             ON PAINT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld
   
    IF EMPTY( oDlg:oBrush:hBitmap )
        hDC = CREATECOMPATIBLEDC( oDlg:GetDC() )
        hBmp = CREATECOMPATIBLEBITMAP( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
        hBmpOld = SELECTOBJECT( hDC, hBmp )
        GRADIENTFILL( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Fri Jan 29, 2010 10:24 am

It looks like the gradient technique is currently not usable. :-(

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby ukoenig » Fri Jan 29, 2010 11:58 am

Enrico,

like Anser, I use Vista as well.
I call the Gradient-painting ON INIT using Function GRADIENTBRUSH

Pushing the < Test-button >, opens Dialog 2
Image

Using a 2. Dialog, moving over Dialog 1
Image

It is not a XP-problem. Maybe a change in Function < GRADIENTBRUSH > needed ?

Code: Select all  Expand view

#include "FiveWin.ch"

FUNCTION MAIN()
LOCAL oDlg1

DEFINE DIALOG oDlg1

@ 1, 1 BUTTON "Test";
           ACTION TEST()

ACTIVATE DIALOG oDlg1 CENTER ;
ON INIT ( GRADBRUSH( oDlg1, { { 1, 14198567, 16117445 } }, .T. ), ;
                 oDlg1:Move( 110, 460, 430, 215, .f. ) )

RETURN NIL

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

FUNCTION TEST()
LOCAL oDlg2

DEFINE DIALOG oDlg2

ACTIVATE DIALOG oDlg2 CENTER ;
ON INIT ( GRADBRUSH( oDlg2, { { 1, 128, 16117445 } }, .T. ), ;
                 oDlg2:Move( 200, 500, 430, 215, .f. ) )

*ON INIT oDlg2:SendMsg( WM_PAINT )

RETURN NIL

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

FUNCTION GradBrush( oDlg, aColors, lPos )
local hDC, hBmp, hBmpOld, oBrush

if Empty( oDlg:oBrush:hBitmap )
      hDC = CreateCompatibleDC( oDlg:GetDC() )
      hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
      hBmpOld = SelectObject( hDC, hBmp )
      GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
      DeleteObject( oDlg:oBrush:hBrush )
      oDlg:oBrush:hBitmap = hBmp
      oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
      SelectObject( hDC, hBmpOld )
      oDlg:ReleaseDC()
endif  

RETURN NIL
 


A working Solution using ON PAINT only with GradientFill :
( GRADIENTBRUSH was created, to solve the Transparent-Problem )
Image

Code: Select all  Expand view

#include "FiveWin.ch"
Static hDC

FUNCTION MAIN()
LOCAL oDlg1

DEFINE DIALOG oDlg1

@ 1, 1 BUTTON "Test";
           ACTION TEST()

ACTIVATE DIALOG oDlg1 ;
ON PAINT  DLG_GRAD( hDC, oDlg1, { { 1, 14198567, 16117445 } }, .T. ) ;
ON INIT oDlg1:Move( 110, 460, 430, 215, .f. )

RETURN NIL

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

FUNCTION TEST()
LOCAL oDlg2

DEFINE DIALOG oDlg2

ACTIVATE DIALOG oDlg2 CENTER ;
ON PAINT DLG_GRAD( hDC, oDlg2, { { 1, 128, 16117445 } }, .T. ) ;
ON INIT oDlg2:Move( 200, 500, 430, 215, .f. )

RETURN NIL

// --------------  GRADIENT --------------------

STATIC FUNCTION DLG_GRAD( hDC, oDlg, aGrad, lPos )

GradientFill( hDC,  0, 0, oDlg:nHeight, oDlg:nWidth, aGrad, lPos )

RELEASEDC( hDC )

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

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Sat Jan 30, 2010 5:11 pm

This seems to work fine but the checkbox is not transparent. :-( Why?

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL lVar := .F.

    DEFINE DIALOG oDlg;
           TRANSPARENT

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    @ 3, 1 CHECKBOX lVar

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:oBrush := GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg;
           TRANSPARENT

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:oBrush := GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld, oBrush
   
    hDC = CREATECOMPATIBLEDC( oDlg:GetDC() )
    hBmp = CREATECOMPATIBLEBITMAP( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
    hBmpOld = SELECTOBJECT( hDC, hBmp )
    GRADIENTFILL( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors )
    oBrush = TBrush():New( , , , , hBmp )
    SELECTOBJECT( hDC, hBmpOld )
    DELETEDC( hDC )
    oDlg:ReleaseDC()

    RETURN oBrush


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby ukoenig » Sat Jan 30, 2010 5:59 pm

Enrico,

the transparent-painting for the checkbox works,
but uses a wrong gradient ( from top )

with same colors ( no gradient ) :
GRADIENTBRUSH( oDlg1, { { 1, RGB( 103, 154, 194 ), RGB( 103, 154, 194 ) } } )
Image

Moving the checkbox to Dialog-Top-position :
GRADIENTBRUSH( oDlg1, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } )
Image

to solve this problem, I used only the checkbox-square and a extra text.
Image

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

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Sat Jan 30, 2010 7:06 pm

ukoenig wrote:to solve this problem, I used only the checkbox-square and a extra text.


It doesn't solve the problem because also the radio buttons are not transparent. :-(

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Sat Jan 30, 2010 7:09 pm

This is one more sample that unfortunately still shows the first problem I reported:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL lVar := .F.

    DEFINE DIALOG oDlg;
           TRANSPARENT

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    @ 3, 1 CHECKBOX lVar

    oDlg:oBrush = TBrush():New()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg;
           TRANSPARENT

    oDlg:oBrush = TBrush():New()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld

    hDC = CREATECOMPATIBLEDC( oDlg:GetDC() )

    hBmp = CREATECOMPATIBLEBITMAP( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )

    hBmpOld = SELECTOBJECT( hDC, hBmp )

    GRADIENTFILL( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors )

    DELETEOBJECT( oDlg:oBrush:hBrush )

    oDlg:oBrush:hBitmap = hBmp
    oDlg:oBrush:hBrush  = CREATEPATTERNBRUSH( hBmp )

    SELECTOBJECT( hDC, hBmpOld )

    DELETEDC( hDC )

    oDlg:ReleaseDC()

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8373
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby nageswaragunupudi » Sun Jan 31, 2010 12:58 am

Solution for the first sample posted.
( I have set another gradient brush to the second dialog also.)

Code: Select all  Expand view
#include "Fivewin.ch"

FUNCTION MAIN()

    LOCAL oDlg, oBrush  // added oBrush

    DEFINE BRUSH oBrush   // inserted
    DEFINE DIALOG oDlg BRUSH oBrush

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RELEASE BRUSH oBrush // inserted
    RETURN NIL

FUNCTION TEST()

    LOCAL oDlg, oBrush
 
    // gradient brush for this dialog also
    DEFINE BRUSH oBrush  
    DEFINE DIALOG oDlg BRUSH oBrush

    ACTIVATE DIALOG oDlg;
             CENTER ;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, CLR_RED, CLR_WHITE } } );


    RELEASE BRUSH oBrush
    RETURN NIL

FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld

    IF EMPTY( oDlg:oBrush:hBitmap )
        hDC = CREATECOMPATIBLEDC( oDlg:GetDC() )
        hBmp = CREATECOMPATIBLEBITMAP( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
        hBmpOld = SELECTOBJECT( hDC, hBmp )
        GRADIENTFILL( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        oDlg:oBrush:cBmpfile = LTrim( Str( hBmp ) ) // inserted to trick the aBrushes behavior
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 29 guests