A problem with GradientBrush()

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Wed Feb 03, 2010 10:41 am

Ok, this is even better:


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 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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Wed Feb 03, 2010 10:48 am

Now the image can be set to not-transparent:

Code: Select all  Expand view
#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
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby nageswaragunupudi » 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: Select all  Expand view
     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
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Wed Feb 03, 2010 11:10 am

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

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

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » 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: Select all  Expand view
#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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Wed Feb 03, 2010 11:23 am

This is a possible fix:

Code: Select all  Expand view
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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » 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: Select all  Expand view
#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
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: A problem with GradientBrush()

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: A problem with GradientBrush()

Postby James Bott » Wed Feb 03, 2010 4:24 pm

>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

Re: A problem with GradientBrush()

Postby Enrico Maria Giordano » Wed Feb 03, 2010 9:04 pm

Ok, I given up to use colored labels.

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

Re: A problem with GradientBrush()

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

Re: A problem with GradientBrush()

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

Re: A problem with GradientBrush()

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests