A problem with GradientBrush()

User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: A problem with GradientBrush()

Post by Enrico Maria Giordano »

Ok, this is even better:


Code: Select all | Expand

#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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: A problem with GradientBrush()

Post by Enrico Maria Giordano »

Now the image can be set to not-transparent:

Code: Select all | Expand

#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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: A problem with GradientBrush()

Post by nageswaragunupudi »

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


Code given below is more generic

Code: Select all | Expand

     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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: A problem with GradientBrush()

Post by Enrico Maria Giordano »

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

EMG
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: A problem with GradientBrush()

Post by Enrico Maria Giordano »

There is a problem in the bEraseBkGnd of TSay. The following sample doesn't show a colored SAY if the theme is activated:

Code: Select all | Expand

#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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: A problem with GradientBrush()

Post by Enrico Maria Giordano »

This is a possible fix:

Code: Select all | Expand

METHOD EraseBkGnd( hDC ) CLASS TSay

   DEFAULT ::lTransparent := .f.

   if ::lTransparent
      return 1
   endif

return Super:EraseBkGnd( hDC )


Antonio, please review.

EMG
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: A problem with GradientBrush()

Post by Enrico Maria Giordano »

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

EMG
User avatar
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Re: A problem with GradientBrush()

Post by Antonio Linares »

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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: A problem with GradientBrush()

Post by Enrico Maria Giordano »

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: Select all | Expand

#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
User avatar
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Re: A problem with GradientBrush()

Post by Antonio Linares »

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
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: A problem with GradientBrush()

Post by James Bott »

>In my opinion it is a right behavior

I agree.

Regards,
James
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: A problem with GradientBrush()

Post by James Bott »

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
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: A problem with GradientBrush()

Post by James Bott »

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
User avatar
Antonio Linares
Site Admin
Posts: 42529
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 77 times
Contact:

Re: A problem with GradientBrush()

Post by Antonio Linares »

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