FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour A problem with GradientBrush()
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 10:41 AM
Ok, this is even better:


Code (fw): Select all Collapse
#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 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 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 )

    oDlg:SetBrush( oBrush )

    AEVAL( oDlg:aControls, { | oCtl | If( oCtl:lTransparent, oCtl:SetBrush( oDlg:oBrush ), ) } )

    RELEASE BRUSH oBrush

    SELECTOBJECT( hDC, hBmpOld )

    DELETEDC( hDC )

    oDlg:ReleaseDC()

    RETURN NIL


EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 10:48 AM
Now the image can be set to not-transparent:

Code (fw): Select all Collapse
#include "Fivewin.ch"
#include "Image.ch"


FUNCTION MAIN()

    LOCAL oDlg, oImg

    DEFINE DIALOG oDlg;
           TRANSPARENT

    @ 0, 0 SAY "This is a test"

    @ 1, 1 IMAGE oImg;
           SIZE 50, 50;
           FILE "e:\fwharbour\bitmaps\select.bmp";
           NOBORDER ADJUST

    ACTIVATE DIALOG oDlg;
             ON INIT ( GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } ),;
                       oImg:lTransparent := .F. );
             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 )

    oDlg:SetBrush( oBrush )

    AEVAL( oDlg:aControls, { | oCtl | If( oCtl:lTransparent, oCtl:SetBrush( oDlg:oBrush ), ) } )

    RELEASE BRUSH oBrush

    SELECTOBJECT( hDC, hBmpOld )

    DELETEDC( hDC )

    oDlg:ReleaseDC()

    RETURN NIL


EMG
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:04 AM
AEVAL( oDlg:aControls, { | oCtl | If( oCtl:lTransparent, oCtl:SetBrush( oDlg:oBrush ), ) } )


Code given below is more generic
Code (fw): Select all Collapse
      if ValType( ::oWnd:aControls ) == 'A'
         if oWnd:IsKindOf( 'TDIALOG' )
            if IsAppThemed()
               AEval( ::oWnd:aControls, { |o| If( o:ClassName $ 'TCHECKBOX', o:oBrush := Self, nil ) } )
            else
               AEval( ::oWnd:aControls, { |o| If( o:ClassName $ 'TCHECKBOX,TRADIO', o:oBrush := Self, nil ) } )
            endif
         elseif ownd:ClassName $ 'TWINDOW,TPANEL,TMDICHILD'
            AEval( ::oWnd:aControls, { |o| If( o:ClassName $ 'TCHECKBOX,TRADIO,TSAY', o:oBrush := Self, nil ) } )
         endif
      endif
Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:10 AM

I don't understand. Please explain what your generalization is suppose to do.

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:19 AM
There is a problem in the bEraseBkGnd of TSay. The following sample doesn't show a colored SAY if the theme is activated:

Code (fw): Select all Collapse
#include "Fivewin.ch"
#include "Image.ch"


FUNCTION MAIN()

    LOCAL oDlg, oSay

    DEFINE DIALOG oDlg;
           TRANSPARENT

    @ 1, 1 BUTTON "Test";
           ACTION ( oSay:SetColor( , CLR_HGREEN ),;
                    oSay:Refresh() )

    @ 3, 1 SAY oSay PROMPT "This is a test";
           COLOR NIL, CLR_HRED

    ACTIVATE DIALOG oDlg;
             ON INIT ( GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } ),;
                       oSay:lTransparent := .F.,;
                       oSay:SetColor( , CLR_HRED ) );
             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 )

    oDlg:SetBrush( oBrush )

    AEVAL( oDlg:aControls, { | oCtl | If( oCtl:lTransparent, oCtl:SetBrush( oDlg:oBrush ), ) } )

    RELEASE BRUSH oBrush

    SELECTOBJECT( hDC, hBmpOld )

    DELETEDC( hDC )

    oDlg:ReleaseDC()

    RETURN NIL


EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:23 AM
This is a possible fix:

Code (fw): Select all Collapse
METHOD EraseBkGnd( hDC ) CLASS TSay 

   DEFAULT ::lTransparent := .f. 

   if ::lTransparent 
      return 1 
   endif 

return Super:EraseBkGnd( hDC )


Antonio, please review.

EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:30 AM

But that not fixes the initial color problem (ie. the COLOR clause doesn't work with themes activated).

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:44 AM

Enrico,

Are those examples working fine for you ? Here they are working fine on both Windows 7 and XP.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 12:13 PM
Please try this sample. The SAY doesn't get the background color. When I click on the button it gets the background color (using XP):

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg, oSay

    DEFINE DIALOG oDlg;
           TRANSPARENT

    @ 1, 1 BUTTON "Test";
           ACTION ( oSay:SetColor( CLR_HGREEN, CLR_HRED ),;
                    oSay:Refresh() )

    @ 3, 1 SAY oSay PROMPT "This is a test";
           COLOR CLR_HGREEN, CLR_HRED

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 12:54 PM

Enrico,

In my opinion it is a right behavior, I explain you why :-)

clause TRANSPARENT on the dialog means that we want to use the "background" of the dialog, thats why the dialog overrides the SAY background color (the SAY brush is replaced). Later on, if you want to change it, then you can do it. But before, FWH changes all the backgrounds as the clause TRANSPARENT is instructing.

We could change this behavior if we all decide to make it work on a different way :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 04:24 PM

>In my opinion it is a right behavior

I agree.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 09:04 PM

Ok, I given up to use colored labels.

EMG

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:29 PM
Enrico,

Well I would also like to see folders with colored tabs.

clause TRANSPARENT on the dialog means that we want to use the "background" of the dialog, thats why the dialog overrides the SAY background color (the SAY brush is replaced).


Actually, I am not sure this is the best way. I have been saying for quite some time that I thought all contols should be transparent. That way they will always show the color of their parent (window, dialog, panel, folder, toolbar, or whatever).

Setting the dialog to transparent seems backward. If the dialog was transparent then one would expect whatever is behind the dialog to show through--which is not what we want. I am guessing that what it does mean is that all the controls on the dialog are made transparent by the dialog. But, if the controls were all transparent by default, then this wouldn't be needed. Perhaps I am missing something.

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: A problem with GradientBrush()
Posted: Wed Feb 03, 2010 11:56 PM
Enrico,

But that not fixes the initial color problem (ie. the COLOR clause doesn't work with themes activated).


I'm not sure how this is supposed to work. Are themes supposed to override all defined colors in the application, or only certain colors?

It does seem that it would be useful to be able to override certain colors when using themes. It does also seem that it could get complicated since you may want some colors defined when not using themes and defined by the theme when using themes. Or, you may want some colors always defined with or without themes. I guess you would need an isThemed() function to use when defining colors.

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: A problem with GradientBrush()
Posted: Thu Feb 04, 2010 12:21 AM

Enrico,

As far as I understand you, it seems as you want to have dialogs that use the clause TRANSPARENT but have SAYs with colored backgrounds (instead of using "transparent" ones).

Is that what you mean ? thanks

I guess we can easily implement it :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com