Page 1 of 2

XBrowse, 2 colores en celda ( Solved )

PostPosted: Fri Jun 25, 2010 12:33 am
by Raymundo Islas M.
Masters Antonio/Daniel,

Existe un post donde es posible combinar diferentes fonts en una misma celda, me pregunto si sera posible combinar colores.

Genero este calendario y me gustaria mostrar los dias del mes en color diferente para que resalten y no se pierdan con los demas datos.

Image

Que en este caso, son totales de ventas por cada dia.

Saludos

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 5:24 am
by anserkk
Try this,

Code: Select all  Expand view

   AEval(oBrw:aCols,{ |oCol| oCol:bClrStd:=CellClr(oCol) }  )

//----------------------------------------//
Function CellClr(oCol)

   Return {|| { iif(oCol:Value = <Your Condition>,CLR_YELLOW,CLR_BLACK) } }


You can have multiple conditions too
Regards

Anser

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 6:24 am
by Raymundo Islas M.
Anserkk,

Thanks a lot for your reply.

This code works really good, but it paints the whole cell's data and what I'm really trying to get is to change only the day number.

( I did this with Paint ) :lol:

Image

I'm filling each cell with strzero( nXDay, 2 ) + CRLF + TransForm( ObtXDayTots(), "999,999.99" ) using a month's loop

However, I'm gonna use your code on another browse than I need to show diferents color on cells depending on some conditions.

Thanks a lot

You're a genius :P


Best regards

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 7:45 am
by anserkk
Did you check the sample TestXbr6.Prg ?

This sample demonstrates the usage of multiple fonts on the same cell.

Regards
Anser

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 12:41 pm
by Carles

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 2:34 pm
by Bayron
Raymundo,

No estoy seguro de como aplicarlo, pero esto podria ser una forma de empezar:
Si bien entiendo, a un gradient se le pueden aplicar 4 colores, los dos primeros, aplican a la parte superior, y los ultimos dos, a la parte inferior, entonces si aplicas colores similares a la parte superior, y colores similares a la parte inferior, podrias obtener el efecto deseado.

Nunca he usado la opcion de gradient y no estoy completamente seguro de como funciona, pero esto es solo una idea....
Juega con los numeros a ver que pasa....

Code: Select all  Expand view

aRowGrad := { { .5, RGB(  0,251,220), RGB( 0,251,220) }, ;
                 { .5, RGB(221,255,251), RGB(221,255,25) } }



   WITH OBJECT oBrw
      :bClrSelFocus  := { || { CLR_BLACK, aSelGrad } }
      /////:bClrRowFocus  := { || { CLR_BLACK, aRowGrad } }
   END

 



Tomado de:

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=18554&p=97241&hilit=gradient#p97245

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 2:44 pm
by Raymundo Islas M.
Anserkk,

Yes I did, but it shows how to apply 2 different fonts into a single cell, and I was trying to apply 2 different colors.

I guess is not possible, so in the meantime, I'm gonna use a bold font for days numbers and another one for totals.

This is how my browse ( another one ) looks using your code for coloring cells
Image

I appreciate you help.


Carles,

De hecho ese es el post que tome como base, pero indica para aplicar 2 fonts en la celda, y lo que busco es poner 2 colores para diferenciar los 2 datos de cada celda.
Lo que que resta hacer es usar un bold para los dias del mes y otro ( quizas italic ) para los importes, creo que con eso lograre diferenciar los datos.


Muchas gracias a ambos


Saludos

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 3:38 pm
by Armando
Ray:

Si puedes definir dos fonts para la misma celda intenta definirlos pero con diferentes colores.

No lo he probado, es solo una idea.

Saludos

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 4:38 pm
by Daniel Garcia-Gil
Raymundo


lo que intentas no es muy complicado pero tiene su tecnica

mira este ejemplo
Code: Select all  Expand view

#include "FiveWin.ch"
#include "xbrowse.ch"

function main()
   
   local oDlg, oBrw
   local aArray := {}
   local nI
   
   for nI = 1 to 20
      aadd( aArray, { StrZero(nI,2), 0, 0, 0, 0, 0 } )
   next
   
   DEFINE DIALOG oDlg Title "Test xBrowse - Color Cell" size 300,300
   
   
   oBrw:= txbrowse():new( oDlg )
   oBrw:nColDividerStyle := LINESTYLE_BLACK
   oBrw:nRowDividerStyle := LINESTYLE_BLACK
   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLCELL
   oBrw:SetArray( aArray )
   oBrw:lFastEdit = .T.
   oBrw:CreateFromCode()
   
   for nI = 2 to Len( oBrw:aCols )
      oBrw:aCols[ nI ]:bClrStd := ChangeColor( oBrw, nI )
      oBrw:aCols[ nI ]:nEditType = 1
   next
   
     
   
   oDlg:oClient := oBrw
   
   ACTIVATE DIALOG oDlg center on init oDlg:Resize()
   
return nil


function ChangeColor( oBrw, n )
return {|| { CLR_BLACK, ColorCell( oBrw:aRow[ n ] ) } }

function ColorCell( uDato )
   local nColor
   DO CASE
      CASE uDato == 1
         nColor := CLR_GREEN
      CASE uDato == 2
         nColor := CLR_YELLOW
      CASE uDato == 3
         nColor := CLR_HRED
      CASE uDato == 4
         nColor := CLR_CYAN
      OTHERWISE
         nColor := GetSysColor( 5 )
   ENDCASE
return nColor
 


Image

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 8:33 pm
by Carles
Raymundo,

lo que busco es poner 2 colores para diferenciar los 2 datos de cada celda.


Uhmm, yo diria que en la tercera fila, tercera columna tienes una celda con tres bitmaps, tres fonts y dos colores :D

Re: XBrowse, 2 colores en celda

PostPosted: Fri Jun 25, 2010 9:40 pm
by Raymundo Islas M.
Bayron,

El gradiente que comentas ya esta aplicado en el cursor ( barra amarilla ), el fondo del browse es un bitmap ( stone.bmp ) el asunto en cuestion es el texto que que se muestra en las celdas. Me gustaria poder mostrarlo usando 2 colores.

Armando,

Si fuera posible hacer lo que comentas estaria fantastico !!!
Ya cheque el archivo font.ch y no permite la asignacion de algun color ( lastima Margarito ) por ahi no puedo hacer nada :?

Daniel,

Excelente opcion, sin ambargo, no es el color del fondo de la celda el que quiero cambiar, es el color del texto pero solo en forma parcial, como ya comente, en cada celda pongo el dia del mes y en la siguiente linea un total, seria mas facil de disitinguir si el dia esta en otro color.
Pero ya que comentas esto, creo haber leido un post donde se puede "pigmentar" con otro color un bitmap, en este caso para cambiar el tono gris del stone.bmp a un tono azul.


Creo que la unica opcion que tendria, es hacer pequeños bitmaps con los numeros 01, 02, 03, .... 31 en color rojo y asignarlos como parte del contenido de cada celda usando como base el post que comenta Carles.

lo probare y les comento.

De momento, les agradezco a todos su apoyo y sugerencias.


Saludos

Re: XBrowse, 2 colores en celda

PostPosted: Sat Jun 26, 2010 12:25 am
by Daniel Garcia-Gil
Raymundo

te dejo el mismo ejemplo, ahora cambiando de color el texto y combinando con 4 tipos de font

segun el ejemplo que te expuse anteriormente solo bastaba cambiar la posicion el color a cambiar, es decir antes cambiaba el color de fondo, bueno ahora cambiemos el color de texto, sigue siendo la misma funcion y la misma tecnica
Antes:
Code: Select all  Expand view
function ChangeColor( oBrw, n )
return {|| { CLR_BLACK, ColorCell( oBrw:aRow[ n ] ) } }


Ahora
Code: Select all  Expand view
function ChangeColor( oBrw, n )
return {|| { ColorCell( oBrw:aRow[ n ] ), GetSysColor( 5 ) } }


Code: Select all  Expand view


#include "FiveWin.ch"
#include "xbrowse.ch"

function main()
   
   local oDlg, oBrw
   local aArray := {}
   local nI
   local aFont := Array( 4 )
   local oBrush
   
   for nI = 1 to 20
      aadd( aArray, { StrZero(nI,2), 0, 0, 0, 0, 0 } )
   next
   
   
   DEFINE FONT aFont[ 1 ] NAME "Arial" SIZE 8, 10
   DEFINE FONT aFont[ 2 ] NAME "Times New Roman" SIZE 10, 16
   DEFINE FONT aFont[ 3 ] NAME "Arial" SIZE 12, 10 ITALIC
   DEFINE FONT aFont[ 4 ] NAME "Courier New" SIZE 14, 10 BOLD
   
   
   DEFINE DIALOG oDlg Title "Test xBrowse - Color Cell" size 300,300
   
   
   oBrw:= txbrowse():new( oDlg )
   oBrw:nColDividerStyle := LINESTYLE_BLACK
   oBrw:nRowDividerStyle := LINESTYLE_BLACK
   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLCELL
   oBrw:SetArray( aArray )
   oBrw:lFastEdit = .T.
   oBrw:CreateFromCode()
   
   for nI = 2 to Len( oBrw:aCols )
      oBrw:aCols[ nI ]:bClrStd := ChangeColor( oBrw, nI )
      oBrw:aCols[ nI ]:oDataFont := ChangeFont( oBrw, nI, aFont )
      oBrw:aCols[ nI ]:nEditType = 1
   next
   
   oDlg:oClient := oBrw
   
   ACTIVATE DIALOG oDlg center on init oDlg:Resize()
   
   AEval( aFont, {| o | o:End() } )
   
return nil


function ChangeColor( oBrw, n )
return {|| { ColorCell( oBrw:aRow[ n ] ), GetSysColor( 5 ) } }

function ChangeFont( oBrw, n, aFont )
return {|| aFont[ FontCell( oBrw:aRow[ n ] ) ] }

function ColorCell( uDato )
   local nColor
   DO CASE
      CASE uDato == 1
         nColor := CLR_GREEN
      CASE uDato == 2
         nColor := CLR_YELLOW
      CASE uDato == 3
         nColor := CLR_RED
      CASE uDato == 4
         nColor := CLR_CYAN
   ENDCASE
return nColor

function FontCell( uDato )
   local nFont := 1
   DO CASE
      CASE uDato == 1
         nFont := 4
      CASE uDato == 2
         nFont := 3
      CASE uDato == 3
         nFont := 2
      CASE uDato == 4
         nFont := 1
   ENDCASE
return nFont

 

Image

Re: XBrowse, 2 colores en celda

PostPosted: Sat Jun 26, 2010 5:49 am
by Carles
Raymundo

Image

Uploaded with ImageShack.us

Code: Select all  Expand view
#include 'fivewin.ch'
#include 'colors.ch'
#include 'xbrowse.ch'

*--------------
FUNCTION Main()
*--------------

   LOCAL oDlg, oBrw
   LOCAL oFont, oBold, oRed
   LOCAL aData    := {}

   DEFINE FONT oRed    NAME 'ARIAL'  SIZE 0,-18 ITALIC
   DEFINE FONT oBold   NAME 'TAHOMA' SIZE 0,-12 BOLD

   AAdd( aData, { 1, 'Otto   ', ;
      'Mr.Otto' + CRLF + ;
      'deleveloped using multiple fonts in the same cell' } )
   AAdd( aData, { 2, 'Antonio', ;
      'FWH' + CRLF + ;
      'Provides easier solution for owner drawing data without changing library code' } )
   AAdd( aData, { 3, 'Carles', ;
      "MR.OTTO'S" + CRLF + ;
      'work is well appreciated' } )
   AAdd( aData, { 4, 'Richard', ;
      "MR.OTTO'S" + CRLF + ;
      'work is well appreciated' } )

   DEFINE DIALOG oDlg SIZE 540,440 PIXEL FONT oFont TITLE 'Test ::bPaintText'

     @ 20, 10 XBROWSE oBrw ;
        HEADERS 'No', 'Name', 'Text' ;
        SIZE 250, 200 PIXEL ;
        OF oDlg ;
        ARRAY aData AUTOCOLS ;
        LINES

     WITH OBJECT oBrw:aCols[3]
        :nHeadStrAlign := AL_CENTER
        :nWidth        := 200
        :bPaintText    := { |oCol, hDC, cText, aCoord| DrawCol( oCol, hDC, cText, aCoord, oBold, oRed ) }
     END

     oBrw:nStretchCol      := STRETCHCOL_LAST
     oBrw:nDataLines       := 3
     oBrw:nMarqueeStyle    := 5
     oBrw:nRowDividerStyle := 0
     oBrw:nColDividerStyle := 0
     oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED

   RELEASE FONT oBold
   RELEASE FONT oRed

RETU NIL

*---------------------------------------------------------------
STATIC FUNCTION DrawCol( oCol, hDC, cText, aCoord, oBold, oRed )
*---------------------------------------------------------------

   local nTop     := aCoord[ 1 ], nLeft  := aCoord[ 2 ]
   local nBottom  := aCoord[ 3 ], nRight := aCoord[ 4 ]
   local nWidth   := nRight - nLeft
   local nHeight  := nBottom - nTop
   local nRow     := nTop
   local cLine, nFontHt, nAt


   nAt      := AT( CRLF, cText )

   IF nAt > 0

      cLine    := Left( cText, nAt - 1  )
      oRed:Activate( hDC )
      SetTextColor( hDC, CLR_HRED  )
      nFontHt  := GetTextHeight( oCol:oBrw:hWnd, hDC )
      DrawTextEx( hDC, cLine, { nRow, nLeft, nBottom, nRight }, oCol:nDataStyle )
      oRed:DeActivate( hDC )

      nRow     += nFontHt + 4
      cLine    := SubStr( cText, nAt + 2 )

      oBold:Activate( hDC )
      SetTextColor( hDC, CLR_BLACK  )
      DrawTextEx( hDC, cLine, { nRow, nLeft, nBottom, nRight }, oCol:nDataStyle )
      oBold:DeActivate( hDC )

   ENDIF

RETU NIL

Re: XBrowse, 2 colores en celda

PostPosted: Sat Jun 26, 2010 7:32 am
by Raymundo Islas M.
Carles,

Simplemente espectacular !!!!

Funciona a la perfeccion, tal y como lo deseaba.

Image

Te agradezco de manera infinita, por igual a los demas compañeros que me apoyaron en este tema.


Muchas gracias a todos y saludos

Re: XBrowse, 2 colores en celda ( Solved )

PostPosted: Wed Feb 22, 2012 9:01 pm
by elmoiquique
Hola

Necesito una ayuda,, uso FW1107 y tengo un problema depintado conel XBROWSE con ARRAY, ocurre lo siguiente:
dependiendo de la condicion que tenga cada registro dentro del ARRAY debiera pintarse la linea de un color cualquiera, pero sucede algo muy raro,, cuando el ARRAY tiene una linea la pinta dependiendo del estado, pero cuando tiene especificamente 2 lineas no pinta ninguna de las dos, es curioso, pero de 1, 3 o mas lineas todo funciona bien, pero con dos no funciona, aca les dejo mi programa a ver si lago estoy haciendo mal

Code: Select all  Expand view

#include "Fivewin.ch"
#include "Folder.ch"
#include "Xbrowse.ch"
#include "Xml.ch"
#include "hbxml.ch"
#include "ribbon.ch"
#include "image.ch"
#include "FastReph.ch"
#include "codebar.ch"

FUNCTION prg_202()
 LOCAL oDlg,oDbf1,oLbx
 LOCAL acAnexo2:={}
 PRIVATE r_orden:=1,r_clifac:='',r_docfac:=''

 CGreen:={ { 0.50,65280,16777215 },{ 0.50,16777215,65280 } }
 CYellow:= { { 0.50,65535,16777215 },{ 0.50,16777215,65535 }}
 CRed:= { { 0.50,255,16777215 },{ 0.50,16777215,255 }}
 COrange:= { { 0.50,33023,16777215 },{0.50,16777215,33023 }}

 IF NetUse("NOTAVNTA", .T. )
  DATABASE oDbf1
  oDbf1:Load()
 ELSE
  MsgStop( "Fichero NOTA DE VENTAS Bloqueado" )
  RETURN NIL
 ENDIF
 
 dbSelectArea(oDbf1:cAlias)
 set order to 2
 go top
 do while .not. eof().and.val((odbf1:calias)->restado)<4
  aadd(acAnexo2,{ (odbf1:calias)->rfolio,dtoc((oDbf1:cAlias)->rfecha),;
                  (oDbf1:cAlias)->rtipod,(oDbf1:cAlias)->rnombre,;
                  (oDbf1:cAlias)->rtotalnv1,(odbf1:calias)->rorden,;
                  (odbf1:calias)->rselect,(odbf1:calias)->ratencion,;
                  (odbf1:calias)->rprovisor} )
  skip
 enddo
 if empty(acAnexo2)
  aadd(acAnexo2,{"","","","",0,0,"","",""})
 endif

 DEFINE DIALOG oDlg RESOURCE "SVE202"

  REDEFINE XBROWSE oLbx ID 101 OF Odlg;
           COLUMNS 1,2,3,4,5,6,7,8,9;
          HEADERS "Folio","Fecha","T/D","Nombre Factura","Valor Total",;
                   "Orden","Estado","Nro.Atencion","Nro.Provisorio";
           COLSIZES 70,65,30,200,70,55,90,90,75;
           PICTURE ,,,,'999,999,999.99';
           ARRAY acAnexo2 AUTOSORT UPDATE FOOTERS LINES AUTOCOLS CELL;
           ON RIGHT CLICK (prgres2(olbx:aArraydata[olbx:narrayat][7],;
                            val(olbx:aArraydata[olbx:narrayat][1])))


   olbx:bClrStd := {|| {CLR_BLACK, IF( olbx:aArrayData[olbx:nArrayAt][7]='SELECCIONADO',cYellow,;
                                   IF( olbx:aArrayData[olbx:nArrayAt][7]='PENDIENTE',cOrange,;
                                   IF( olbx:aArrayData[olbx:nArrayAt][7]='VISADO',cGreen,;
                                   IF( olbx:aArrayData[olbx:nArrayAt][7]='ERROR XML',cRed,;
                                   IF( olbx:aArrayData[olbx:nArrayAt][7]='RECHAZADO',cRed,CLR_WHITE ))))) } }



 ACTIVATE DIALOG oDlg CENTERED ON INIT (olbx:maketotals(),olbx:gotop(),olbx:refresh())

 NETCLOSEALL()
RETURN .T.