FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour LinearGardientBrush
Posts: 29
Joined: Thu Oct 20, 2005 01:35 PM
LinearGardientBrush
Posted: Mon Jan 09, 2006 04:27 PM

Hola Foro

Estoy buscanco algo como la funci贸n en .net LinearGradienteBrush para fwh.

Lo que quiero es crear un brush similar al solidbrush, que permita hacer una gradiente de colores

Alguien tiene alnuna idea?

Gracias

Arturo Tamayo Daza

thee2d2@entelnet.bo
arturotamayo.hotmail.com

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
LinearGardientBrush
Posted: Mon Jan 09, 2006 06:10 PM

Arturo,

Una soluci贸n f谩cil es similar a la que se usa en las p谩ginas web. Crea un peque帽o bitmap que contenga el gradiente, algo asi como una l铆nea vertical y delgada.

Crea un brush con ese bitmap y d谩selo a la ventana 贸 di谩logo, y ellos te crear谩n el gradiente de forma automatica.

Otra posible implementaci贸n la tienes en el ejemplo samples\install.prg. El modo en que se dibuja el color del fondo, es una forma de hacer un gradiente mediante programaci贸n.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 29
Joined: Thu Oct 20, 2005 01:35 PM
LinearGardientBrush
Posted: Mon Jan 09, 2006 07:36 PM

Gracias Antonio

Esa soluci贸n ya la he visto pero no me sirve ya que los colores ser铆an fijos de acuerdo al bmp.

lo que yo estoy buscando es una funci贸n similar a lineragradientbrush, que permita definir los colores, mas o menos asi

Obrush := (ntop,nleft,nbotton,nrght,Color1, Color2, posicion )

si fuera posible dar este entonces los colores variarian de acuerdo con lo difinido en el windows

Saludos

Arturo

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
LinearGardientBrush
Posted: Mon Jan 09, 2006 07:55 PM

Arturo,

Entonces revisa el c贸digo fuente de samples\install.prg

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
LinearGardientBrush
Posted: Mon Jan 09, 2006 08:26 PM

si no recuerdo mal, la clase tsbutton de manuel mercado implementa una funcion que realiza un degradado con dos colores, similar a lo que busca.

salu2
carlos vargas

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 172
Joined: Fri Oct 07, 2005 12:00 PM
Gradient
Posted: Mon Jan 09, 2006 09:03 PM
Hola a todos:

Si le parece bien a Antonio podemos incluir la funci贸n Degrada en fivewin.

Existe una funci贸n GradientFill en una dll del sistema pero no siempre esta disponible en todos los Windows asi que creo que es mejor utilizar esta forma

void GradientFill( HDC hDC, RECT* rct, COLORREF crStart, COLORREF crEnd, int bVertical )
    {
       int nSegments = 100;
       COLORREF cr;

       int nR      = GetRValue(crStart);
       int nG      = GetGValue(crStart);
       int nB      = GetBValue(crStart);
       int neB     = GetBValue(crEnd);
       int neG     = GetGValue(crEnd);
       int neR     = GetRValue(crEnd);
       int nDiffR  = (neR - nR);
       int nDiffG  = (neG - nG);
       int nDiffB  = (neB - nB);
       int ndR ;
       int ndG ;
       int ndB ;
       int nCX ;
       int nCY ;
       int nTop    = rct->top;
       int nBottom = rct->bottom;
       int nLeft   = rct->left;
       int nRight  = rct->right;
       HBRUSH hBrush;
       RECT rc;

       int i;

       if( !bVertical )
       {
          if( nSegments > ( rct->right - rct->left ) )
          {
            nSegments = ( rct->right - rct->left );
          }
       }
       else
       {
          if( nSegments > ( rct->bottom - rct->top ) )
          {
            nSegments = ( rct->bottom - rct->top );
          }
       }

       ndR = 256 * (nDiffR) / (max(nSegments,1));
       ndG = 256 * (nDiffG) / (max(nSegments,1));
       ndB = 256 * (nDiffB) / (max(nSegments,1));
       nCX = (rct->right-rct->left) / max(nSegments,1);
       nCY = (rct->bottom-rct->top) / max(nSegments,1);



       nR *= 256;
       nG *= 256;
       nB *= 256;

       for (i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)
       {

               if(i == (nSegments - 1))
               {
                  nRight  = rct->right;
                  nBottom = rct->bottom;
               }
               else
               {
                  nBottom = nTop + nCY;
                  nRight = nLeft + nCX;
               }

               cr = RGB(nR / 256, nG / 256, nB / 256);

               {
                  hBrush = CreateSolidBrush( cr );
                  if( bVertical )
                  {
                     rc.top    = nTop;
                     rc.left   = rct->left;
                     rc.bottom = nBottom + 1;
                     rc.right  = rct->right;
                  }
                  else
                  {
                     rc.top    = rct->top;
                     rc.left   = nLeft;
                     rc.bottom = rct->bottom;
                     rc.right  = nRight+1;
                  }
                  FillRect(hDC, &rc, hBrush );
                  DeleteObject( hBrush );
               }

               nLeft = nRight;
               nTop = nBottom;
       }
    }


   HB_FUNC( DEGRADA )
   {
           RECT rct;

           rct.top      = hb_parni( 2, 1 );
           rct.left      = hb_parni( 2, 2 );
           rct.bottom = hb_parni( 2, 3 );
           rct.right    = hb_parni( 2, 4 );

           GradientFill( ( HDC ) hb_parnl( 1 ) , &rct, hb_parnl( 3 ), hb_parnl( 4 ), hb_parl(5) );
   }


local lVertical := .t.
Degrada( hDC, { 10, 10, 200, 200},  CLR_WHITE, CLR_BLUE, lVertical )


Este c贸digo est谩 inspirado en alguno que he visto por internet, no lo he imaginado yo solo.

Un saludo

Paco
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
LinearGardientBrush
Posted: Tue Jan 10, 2006 08:06 AM

Gracias!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 16
Joined: Thu Dec 01, 2005 04:15 PM
LinearGardientBrush
Posted: Wed Jan 11, 2006 02:40 PM

Tambien ando en busca de una soluci贸n, pero en lugar de la funcion quisiera definir un brush, para independizarme del pintado.
Com se puede generar un bitmap en memoria, por ejemplo con el rectangulo generado por la funcion anterior?
Con ese bitmap seria posible definir el brush
Actualmenet tengo definido bitmaps de 1 pixel de ancho en los recursos y los uso com brushes, pero creo que el bitmap deberia ser hecho a mano, a la medida del di谩logo al que se le aplique.
Saludos

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
LinearGardientBrush
Posted: Thu Jan 26, 2006 07:12 PM

Me gustaria usar la function en c que sugiere Paco para lograr el efecto. Como le hago para compilarla e integrarla a mis aplicaciones?

Gracias.

Reinaldo Crespo

Posts: 172
Joined: Fri Oct 07, 2005 12:00 PM
LinearGardientBrush
Posted: Thu Jan 26, 2006 09:40 PM
Hola

Pon al final de tu c贸digo prg lo siguente:

#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"

.... la funci贸n c

#pragma ENDDUMP


y ya est谩.

Un saludo

Paco
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
LinearGardientBrush
Posted: Thu Jan 26, 2006 11:10 PM

Paco;

Gracias por tu respuesta. Inclu铆 la funci贸n al fondo de uno de los prgs que componen la aplicaci贸n. Recibo el siguiente error:

f:\borland\bcc55\bin\bcc32.exe -c -O2 -If:\xharbour_0.99\include;f:\borland\bcc55\include -o\mp\patients\shared.obj \mp\patients\shared.xhrb

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
\mp\patients\shared.xhrb:
Error E2356 ..\shared\shared.prg 2762: Type mismatch in redeclaration of 'GradientFill'
Error E2344 f:\borland\bcc55\include\wingdi.h 3453: Earlier declaration of 'GradientFill'
*** 2 errors in Compile ***

La linea 2762 de shared.prg es la que solamente tiene el parentesis abriendo.

Reinaldo.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
LinearGardientBrush
Posted: Fri Jan 27, 2006 01:08 AM

Reinaldo,

Cambia el nombre GradientFill por GradientFILL, por ejemplo.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
LinearGardientBrush
Posted: Fri Jan 27, 2006 01:19 AM

Antonio;

Hola. Gracias por tu respuesta.

Pues no veo que diferencia podria hacer, pero hice como me dices. Y misteriosamente (para mi), ya no existe ese problema. Ahora tengo los errors que te muestro a continuacion:

Warning W8004 ..\shared\shared.prg 2772: 'nRight' is assigned a value that is never used in function GradientFILL
Warning W8004 ..\shared\shared.prg 2770: 'nBottom' is assigned a value that is never used in function GradientFILL
Warning W8075 ..\shared\shared.prg 2855: Suspicious pointer conversion in function HB_FUN_DEGRADA
Error E2340 ..\shared\shared.prg 2855: Type mismatch in parameter 4 (wanted 'void *', got 'long') in function HB_FUN_DEGRADA
Error E2193 ..\shared\shared.prg 2855: Too few parameters in call to 'GradientFill' in function HB_FUN_DEGRADA
*** 2 errors in Compile ***

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
LinearGardientBrush
Posted: Fri Jan 27, 2006 01:24 AM

Reinaldo,

Tambien tienes que cambiar el nombre aqu铆:

GradientFILL( ( HDC ) hb_parnl( 1 ) , &rct, hb_parnl( 3 ), hb_parnl( 4 ), hb_parl(5) );

El lenguaje C es "case sensitive", es decir, distingue entre may煤sculas y min煤sculas. El API de Windows proporciona una funci贸n que se llama GradientFill que entraba en conflicto con la de Paco. Al cambiarle el nombre, el conflicto desaparece.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
LinearGardientBrush
Posted: Fri Jan 27, 2006 01:31 AM

Antonio;

Parece que hoy has estado bastante ocupado. Asi que gracias por responder tan pronto.

Saludos,

Reinaldo.