Page 4 of 5

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 10:41 am
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

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 10:48 am
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

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:04 am
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
 

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:10 am
by Enrico Maria Giordano
I don't understand. Please explain what your generalization is suppose to do.

EMG

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:19 am
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

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:23 am
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

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:30 am
by Enrico Maria Giordano
But that not fixes the initial color problem (ie. the COLOR clause doesn't work with themes activated).

EMG

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:44 am
by Antonio Linares
Enrico,

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

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 12:13 pm
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

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 12:54 pm
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 :-)

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 4:24 pm
by James Bott
>In my opinion it is a right behavior

I agree.

Regards,
James

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 9:04 pm
by Enrico Maria Giordano
Ok, I given up to use colored labels.

EMG

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:29 pm
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

Re: A problem with GradientBrush()

Posted: Wed Feb 03, 2010 11:56 pm
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

Re: A problem with GradientBrush()

Posted: Thu Feb 04, 2010 12:21 am
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 :-)