color the cells of the xbrowse

color the cells of the xbrowse

Postby Silvio.Falconi » Tue Apr 19, 2022 9:33 pm

I have this array

Image

I would like to visualize with colors
1) equal numbers (from column 7 to 16) on the same row
2) same numbers (from column 7 to 16) on different rows

when the numbers are colored, I also want to color the columns relating to the headers
example "1-4" I want to color the number of columns 1 and 4

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

function Main()

   local oWnd, oBrw, oFont
   local aData := { ;
      {"XXX", 53, 29, 22, 70, 39, 82, 75,33,2,51,9,68,2,61,19 }, ;
      {"KKK", 15, 21, 60, 38, 44, 36, 75,53,59,81,59,65,8,14,82 }, ;
      {"TTT", 54, 4, 56, 77, 79, 58, 20,41,43,60,81,83,43,45,66 } }

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-20 BOLD
   DEFINE WINDOW oWnd
  * @ 0,0 XBROWSE oBrw OF oWnd AUTOCOLS ARRAY aData ;

  * CELL LINES FASTEDIT FONT oFont

     @ 0,0 XBROWSE oBrw OF oWnd PIXEL NOBORDER;
      COLS 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16;
      HEADERS "Ruote", "1°", "2°", "3°", "4°", "5°", "1-2" ,"1-3","1-4","1-5","2-3","2-4","2-5","3-4","3-5","4-5";
      SIZES  150,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45  ;
      ARRAY adata ;
      CELL LINES

   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw

   ACTIVATE WINDOW oWnd
   RELEASE FONT oFont

return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: color the cells of the xbrowse

Postby Jimmy » Wed Apr 20, 2022 6:16 am

hi Silvio,

i do not know how XBROWSE work

my HMG Sample use GRID and DYNAMICBACKCOLOR which is a Codeblock with RGB-Color
http://www.hmgforum.com/viewtopic.php?f=5&t=7222
Image
you can use 1st Part of Code to "identify" Number in Array which are twice (or more)
this later is use for Color of Background
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: color the cells of the xbrowse

Postby Silvio.Falconi » Wed Apr 20, 2022 9:29 am

What mean with "FindDupe" ?
But it is ...same numbers (from column 7 to 16) on different rows ?
We can try converte it together

my problem is
as the first operation (1) locate the numbers on the same line
second operation (2) the same numbers on different lines
It is the final operator who by selecting a checkbox can highlight the numbers (1) or (2)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: color the cells of the xbrowse

Postby Silvio.Falconi » Wed Apr 20, 2022 10:11 am

Jimmy wrote:hi Silvio,

i do not know how XBROWSE work

my HMG Sample use GRID and DYNAMICBACKCOLOR which is a Codeblock with RGB-Color
http://www.hmgforum.com/viewtopic.php?f=5&t=7222
Image
you can use 1st Part of Code to "identify" Number in Array which are twice (or more)
this later is use for Color of Background


I'm trying to converte

Image



@ 200, 100 CHECKBOX oChk[2] VAR lUgualiRuote PROMPT "Same values on different wheels" SIZE 120, 12 pixel OF oFld:aDialogs[2] ;
ON CHANGE ( Same_Number_all_Rows(aData))


Code: Select all  Expand view
Function Same_Number_all_Rows(aData)
     LOCAL nRowMax  := LEN( aData )
     LOCAL nColMax
     LOCAL ii, jj, nNum, nPosi, nNumColor
     LOCAL nCount   := 0
     local aResult :={}

      // read aData and add Number to aResult
   ii := 1
   FOR ii := 1 TO nRowMax
      jj := 2
      nColMax := LEN( aData[ ii ] )
      FOR jj := 2 TO nColMax
         nNum := aData[ ii ] [ jj ]
         nPosi := ASCAN( aResult, { | e | e[ 1 ] = nNum } )
         IF nPosi > 0
            // increase Counter
            aResult[ nPosi ] [ 2 ] := aResult[ nPosi ] [ 2 ] + 1
         ELSE
            // {Number,Counter,Color}
            AADD( aResult, { nNum, 1, 0 } )
         ENDIF
      NEXT
   NEXT

   xbrowser   aResult

 


at this point it gives me back
Image

I understood are Number and counter and number color right ?


Now I must converte this

Code: Select all  Expand view
ii := 1
   FOR ii := 1 TO nColMax
      AADD( aJustify, GRID_JTFY_LEFT )
      AADD( aBColors, { || FindDupe(aResult) } )
   NEXT


on FindDupe(aResult)
I not Know How converte this

LOCAL CellRowIndex := This.CellRowIndex
LOCAL CellColIndex := This.CellColIndex
LOCAL CellValue := This.CellValue
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: color the cells of the xbrowse

Postby Silvio.Falconi » Wed Apr 20, 2022 10:27 am

Perhaps

FOR n = 2 to len( oBrw:aCols )
oCol := oBrw:aCols[ n ]
AADD( aBColors, { || FindDupe(aResult,oCol) } )
NEXT

// sort Result
ASORT( aResult,,, { | aX, aY | aX[ 1 ] < aY[ 1 ] } )

// set Color when "dupe"
nNumColor := 600000
nCount := 0
ii := 1
FOR ii := 1 TO LEN( aResult )
IF aResult[ ii ] [ 2 ] > 1
nCount ++
aResult[ ii ] [ 3 ] := NumColor2RGB( nNumColor * nCount )
ENDIF
NEXT
return aBColors



FUNCTION FindDupe(aResult,oCol)
LOCAL nPosi
LOCAL bColor := {255,255,255}
LOCAL nCellValue


nCellValue := oCol:value
nPosi := ASCAN( aResult, { | e | e[ 1 ] = nCellValue } )
IF nPosi > 0
IF aResult[ nPosi ] [ 2 ] > 1
bColor := aResult[ nPosi ] [ 3 ]
ENDIF
ENDIF

RETURN bColor
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: color the cells of the xbrowse

Postby Jimmy » Wed Apr 20, 2022 11:11 am

hi Silvio,

as i say 1st Part of Code seems to work for you

Code: Select all  Expand view
AADD( aJustify, GRID_JTFY_LEFT )

not need, just "justfy" Value in Column

Code: Select all  Expand view
AADD( aBColors, { || FindDupe(aResult) } )

a Codeblock for each Column

Code: Select all  Expand view
LOCAL CellRowIndex := This.CellRowIndex
LOCAL CellColIndex := This.CellColIndex
LOCAL CellValue := This.CellValue


as i say i do not know how XBROWSE work with Color
i saw you can set Color for hole Column but how on single Cell :?:

Question : does Fivewin use "Ownerdraw" (WM_DRAWITEM) :?:

---

GRID = WC_LISTVIEW does have Style LVS_OWNERDATA and LVN_GETDISPINFO for Notify Event
using NMLVDISPINFO Structure you got "Row/Col"

Code: Select all  Expand view
   st := NMLVDISPINFO():New()

   // ZERO-based :iItem and :iSubItem
   nRec := st:item:iItem              // This.CellRowIndex
   nSub := st:item:iSubItem+1         // This.CellColIndex

   // use Array ::aSource
   ctext := ::aSource[nRec+1][nSub]   // This.CellValue


benefit : you can use a "virtual GRID" and "assign hole Array (Limit 100.000.000)

Code: Select all  Expand view
  nItemCache := LEN( ::aSource )
   // get Memory for (big) Array
   ::lv_SetItemCount(nItemCache)
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: color the cells of the xbrowse

Postby Jimmy » Wed Apr 20, 2022 11:19 am

Silvio.Falconi wrote:Perhaps

Code look good ... but how to "use" aBColors :idea:
how to "color" single Cell :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: color the cells of the xbrowse

Postby Silvio.Falconi » Wed Apr 20, 2022 11:22 am

Perhaps


Code: Select all  Expand view

#define ACOLOR3  { CLR_BROWN,CLR_WHITE }
#define ACOLOR4  { CLR_YELLOW, CLR_WHITE }


 Function Same_Number_all_Rows(aData,oBrw)
     LOCAL nRowMax  := LEN( aData )
     LOCAL nColMax
     LOCAL ii, jj, nNum, nPosi, nNumColor
     LOCAL nCount   := 0
     local aResult :={}
     LOCAL aJustify := {}
     LOCAL aBColors := {}

      // read aData and add Number to aResult
   ii := 1
   FOR ii := 1 TO nRowMax
      jj := 2
      nColMax := LEN( aData[ ii ] )
      FOR jj := 2 TO nColMax
         nNum := aData[ ii ] [ jj ]
         nPosi := ASCAN( aResult, { | e | e[ 1 ] = nNum } )
         IF nPosi > 0
            // increase Counter
            aResult[ nPosi ] [ 2 ] := aResult[ nPosi ] [ 2 ] + 1
         ELSE
            // {Number,Counter,Color}
            AADD( aResult, { nNum, 1, 0 } )
         ENDIF
      NEXT
   NEXT
   XBROWSER aResult





   *FOR n = 2 to len( oBrw:aCols )
   *      oCol         := oBrw:aCols[ n ]
    *     oCol:bClrStd := CellColorBlockResult( oCol, aResult)
   *   NEXT

   * return NIL

   // add for each Column



  FOR n = 2 to len( oBrw:aCols )
        oCol         := oBrw:aCols[ n ]
         AADD( aBColors, { || FindDupe(@aResult,oCol) } )
     NEXT

   *  xbrowser aBColors


   // sort Result
   ASORT( aResult,,, { | aX, aY | aX[ 1 ] < aY[ 1 ] } )

   // set Color when "dupe"
   nNumColor := 1
   nCount := 0
   ii := 1
   FOR ii := 1 TO LEN( aResult )
      IF aResult[ ii ] [ 2 ] > 1
         nCount ++
         aResult[ ii ] [ 3 ] := nCount //( nNumColor * nCount )
      ENDIF
   NEXT
           xbrowser   aResult


   FOR n = 2 to len( oBrw:aCols )
         oCol         := oBrw:aCols[ n ]
         oCol:bClrStd := CellColorBlockResult( oCol, aResult)
      NEXT
   RETURN NIL



STATIC FUNCTION CellColorBlockResult( oCol, aPos )
   LOCAL oBrw := oCol:oBrw
   RETURN { || If( IsBit( aPos[ oBrw:nArrayAt ][1], oCol:nArrayCol ),NumColor2RGB( aPos[ oBrw:nArrayAt ][3] ), ACOLOR4 ) }





FUNCTION FindDupe(aResult,oCol)
LOCAL nPosi
LOCAL bColor     := {255,255,255}
LOCAL nCellValue

   // these Variable are avaiable for GRID
*LOCAL CellRowIndex := This.CellRowIndex
*LOCAL CellColIndex := This.CellColIndex
*LOCAL CellValue    := This.CellValue


   nCellValue :=  oCol:value
   nPosi := ASCAN( aResult, { | e | e[ 1 ] = nCellValue } )
   IF nPosi > 0
      IF aResult[ nPosi ] [ 2 ] > 1
         bColor := aResult[ nPosi ] [ 3 ]
      ENDIF
   ENDIF

RETURN  bColor








FUNCTION NumColor2RGB( nColor )

LOCAL aRetVal

   DEFAULT nColor TO - 1

   IF nColor == - 1
      aRetVal := { NIL, NIL, NIL }
   ELSE
      aRetVal := { GetRed( nColor ), GetGreen( nColor ), GetBlue( nColor ) }
   ENDIF



RETURN aRetVal
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: color the cells of the xbrowse

Postby Silvio.Falconi » Wed Apr 20, 2022 11:28 am

LOCAL CellRowIndex := This.CellRowIndex
LOCAL CellColIndex := This.CellColIndex

LOCAL CellValue := This.CellValue

CellRowIndex -> oBrw:nArrayAt
CellColIndex -> oCol := oBrw:aCols[ n ]
CellValue -> nCellValue := oCol:value

I believe this is the case in fivewin but I'm not sure
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: color the cells of the xbrowse

Postby Jimmy » Fri Apr 22, 2022 8:29 pm

hi Silvio,
Silvio.Falconi wrote:I believe this is the case in fivewin but I'm not sure

would like to "see" FiveWin Code when working, thx
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: color the cells of the xbrowse

Postby Silvio.Falconi » Sat Apr 23, 2022 8:45 am

Jimmy wrote:hi Silvio,
Silvio.Falconi wrote:I believe this is the case in fivewin but I'm not sure

would like to "see" FiveWin Code when working, thx



Jimmy i can send you a small sample to see fivewin working with colors, my mail is silvio[dot]falconi[at]gmail[dot]com
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: color the cells of the xbrowse

Postby Silvio.Falconi » Thu Apr 28, 2022 5:53 pm

Any solution pls ?
Nages?
how converte this source of Jimmy ?
Code: Select all  Expand view
*+--------------------------------------------------------------------
*+
*+ Source Module => c:\hmg.3.4.4\0\Lotto\\LOTTO.PRG
*+
*+    Copyright(C) 1983-2021 by Auge & Ohr
*+
*+    Functions: Procedure MAIN()
*+               Function FindDupe()
*+               Function NumColor2RGB()
*+
*+    Reformatted by Click! 2.05.39 on Apr-20-2022 at  7:35 am
*+
*+--------------------------------------------------------------------

#include "HMG.CH"
#include "Common.ch"

STATIC aResult := {}

MEMVAR _HMG_SYSDATA

*+--------------------------------------------------------------------
*+
*+    Procedure MAIN()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE MAIN

LOCAL aData := { { "XXX", 53, 29, 22, 70, 39, 82, 75, 33, 2, 51, 9, 68, 2, 61, 19 }, ;
                 { "KKK", 15, 21, 60, 38, 44, 36, 75, 53, 59, 81, 59, 65, 8, 14, 82 }, ;
                 { "TTT", 54, 4, 56, 77, 79, 58, 20, 41, 43, 60, 81, 83, 43, 45, 66 } }

LOCAL nRowMax  := LEN( aData )
LOCAL nColMax
LOCAL ii, jj, nNum, nPosi, nNumColor
LOCAL nCount   := 0
LOCAL aJustify := {}
LOCAL aBColors := {}

   // read aData and add Number to aResult
   ii := 1
   FOR ii := 1 TO nRowMax
      jj := 2
      nColMax := LEN( aData[ ii ] )
      FOR jj := 2 TO nColMax
         nNum := aData[ ii ] [ jj ]
         nPosi := ASCAN( aResult, { | e | e[ 1 ] = nNum } )
         IF nPosi > 0
            // increase Counter
            aResult[ nPosi ] [ 2 ] := aResult[ nPosi ] [ 2 ] + 1
         ELSE
            // {Number,Counter,Color}
            AADD( aResult, { nNum, 1, 0 } )
         ENDIF
      NEXT
   NEXT

   // add for each Column
   ii := 1
   FOR ii := 1 TO nColMax
      AADD( aJustify, GRID_JTFY_LEFT )
      AADD( aBColors, { || FindDupe() } )
   NEXT

   // sort Result
   ASORT( aResult,,, { | aX, aY | aX[ 1 ] < aY[ 1 ] } )

   // set Color when "dupe"
   nNumColor := 600000
   nCount := 0
   ii := 1
   FOR ii := 1 TO LEN( aResult )
      IF aResult[ ii ] [ 2 ] > 1
         nCount ++
         aResult[ ii ] [ 3 ] := NumColor2RGB( nNumColor * nCount )
      ENDIF
   NEXT

   DEFINE WINDOW Form_1 ;
         AT 0, 0 ;
         WIDTH 800 ;
         HEIGHT 400 ;
         MAIN

      @ 10,  0 GRID Grid_1 ;
              WIDTH 800 ;
              HEIGHT 330 ;
              HEADERS { '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' } ;
              WIDTHS { 31, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50 } ;
              ITEMS aData ;
              CELLNAVIGATION ;
              DYNAMICBACKCOLOR aBColors ;
              JUSTIFY aJustify

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

RETURN

*+--------------------------------------------------------------------
*+
*+    Function FindDupe()
*+
*+    Called from ( lotto.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION FindDupe()

LOCAL nPosi
LOCAL bColor     := {255,255,255}
LOCAL nCellValue

   // these Variable are avaiable for GRID
LOCAL CellRowIndex := This.CellRowIndex
LOCAL CellColIndex := This.CellColIndex
LOCAL CellValue    := This.CellValue

   nCellValue := VAL( CellValue )
   nPosi := ASCAN( aResult, { | e | e[ 1 ] = nCellValue } )
   IF nPosi > 0
      IF aResult[ nPosi ] [ 2 ] > 1
         bColor := aResult[ nPosi ] [ 3 ]
      ENDIF
   ENDIF
RETURN bColor

*+--------------------------------------------------------------------
*+
*+    Function NumColor2RGB()
*+
*+    Called from ( lotto.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION NumColor2RGB( nColor )

LOCAL aRetVal

   DEFAULT nColor TO - 1

   IF nColor == - 1
      aRetVal := { NIL, NIL, NIL }
   ELSE
      aRetVal := { GetRed( nColor ), GetGreen( nColor ), GetBlue( nColor ) }
   ENDIF

RETURN aRetVal

*+ EOF: LOTTO.PRG
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

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