Page 10 of 35

Posted: Mon Nov 07, 2005 5:33 pm
by gnozal
RichardL wrote:Any suggestions for what I might be doing wrong?
The more items you are coloring, the slower it becomes.

Some suggestions :
1 : PureCOLOR_SetRowColor() should not be used to alternate background color ; better use PureCOLOR_SetGadgetColorEx(#ListIcon, TextColor, BackColor1, BackColor2, #PureCOLOR_LV_AlternateColors) : it's much faster.
2 : I see you are using WM_SETREDRAW = #False before the For/Next loop, so you could also try PureCOLOR_RedrawGadgetAfterColor(#False) before the For/Next loop, and PureCOLOR_RedrawGadgetAfterColor(#True) after the loop and refresh the ListIcon.
3 : Try to avoid rewriting completly the ListIcon as much as possible.

Posted: Mon Nov 07, 2005 6:52 pm
by RichardL
OK, thanks for the suggestion. I use this to set up the alternate line colouring, just after the gadget is created:

Code: Select all

  PureCOLOR_SetGadgetColorEx(001,0,$FFFFFF,$FFFFFF!$30,#PureCOLOR_LV_AlternateColors)
I'm now down to the following each time I change the data:

Code: Select all

Procedure ReWriteDisplay()             ;- Refresh feeder data to screen
  
  SendMessage_(GadgetID(001),#WM_SETREDRAW, #False, 0)   ; Turn off redraw until we have finished
  ClearGadgetItemList(001)                               ; Clear the gadget
  AddGadgetItem(1,0,"") 
  For n.w = 1 To MaxNumFeeders                           ; Typically 1000 units
    AddGadgetItem(1,n.w,FeederData$(n.w))                ; Put data from array into display gadget
    If FeederFlags(n.w)                                  ; If to be marked as defective...
      PureCOLOR_SetCellColor(001,n.w,0,0,$8080FF)        ; Colour the first cell light red
    EndIf
  Next
  SendMessage_(GadgetID(001),#WM_SETREDRAW, #True, 0)    ; Turn on redraw
  While WindowEvent() : Wend                             ; Allow re-draw
EndProcedure
I have to mark defective units / units due to be calibrated etc which is why I colour the first cell. I also have to add/delete items from the list. It all works OK but STILL slows down progressively. Here are the timings in milliseconds:

47,63,78,78,94,109,125,141.... 734.......953....etc

Any idea why it get slower? I checked that nothing is eating RAM or CPU speed, it all looks OK to me!

Richard

Posted: Tue Nov 08, 2005 8:54 am
by gnozal
RichardL wrote:Any idea why it get slower? I checked that nothing is eating RAM or CPU speed, it all looks OK to me!Richard
Are you clearing unused colors before adding new ones ?
When you clear the listicon ( ClearGadgetItemList() ), do you also clear the cell colors for this listicon ( PureCOLOR_ClearAllColorsForGadget() ) ?

Posted: Tue Nov 08, 2005 9:39 am
by RichardL
Hi,
No, I was not clearing the colours first, I did not realise I had to. The following code now executes at a consistent and acceptable speed of in the range 69 to 78 mSec; no creeping upwards:

Code: Select all

Procedure ReWriteDisplay()             ;- Refresh feeder data to screen
  SendMessage_(GadgetID(001),#WM_SETREDRAW, #False, 0)   ; Turn off redraw until we have finished
  ClearGadgetItemList(001)                               ; Clear the gadget text
  PureCOLOR_ClearAllColorsForGadget(001)                 ; Remove colours
  
  PureCOLOR_SetGadgetColorEx(001,0,$FFFFFF,$FFFFFF!$30,#PureCOLOR_LV_AlternateColors) ; 'Read-across' improvement
  AddGadgetItem(1,0,"") 
  ColV = $FFFFFF                                         ; Cell colour for first col
  For n.w = 1 To MaxNumFeeders                           ; For each feeder unit
    ColV ! $30                                           ; Toggle colour for first cell
    AddGadgetItem(1,n.w,FeederData$(n.w))                ; Put text from array into display gadget
    If FeederFlags(n.w)                                  ; If to be marked as defective/out-of-calibration etc
      PureCOLOR_SetCellColor(001,n.w,0,0,$8080FF)        ; Colour the first cell light red
    Else
      PureCOLOR_SetCellColor(001,n.w,0,0,ColV)           ; ** TEMPORARY **
    EndIf
  Next
  SendMessage_(GadgetID(001),#WM_SETREDRAW, #True, 0)    ; Turn on redraw
  While WindowEvent() : Wend                             ; Allow re-draw
EndProcedure
Will the modified GetCellColor() return background colours set by SetRowColor() and SetGadgetColorEx() as you suggested?
I can then get rid of the *TEMPORARY* line above and the speed goes to 46 / 47 mSec.

Thank you for your assistance.

Posted: Tue Nov 08, 2005 10:04 am
by gnozal
RichardL wrote:Will the modified GetCellColor() return background colours set by SetRowColor() and SetGadgetColorEx() as you suggested?
I can then get rid of the *TEMPORARY* line above and the speed goes to 46 / 47 mSec.
GetCellColor() should return colors set with SetRowColor().
Note that GetCellColor() only returns colors set with SetCell/Column/RowColor(), not with SetGadgetColorEx().
However, it's easy to know the backcolors set with PureCOLOR_SetGadgetColorEx(#ListIcon, TextColor, BackColor1, BackColor2, #PureCOLOR_LV_AlternateColors) : it's BackColor1 if row is even or BackColor2 if row is odd.

Posted: Tue Nov 08, 2005 10:46 am
by RichardL
Thanks.

I have sent a first cut of the program to the end user for an exhibition in Germany next week... now he gets a chance to find the bugs (Features :wink: ) that I left for him to discover.

Posted: Tue Nov 22, 2005 2:04 pm
by gnozal
Update

Changes :
- Fixed some ListView/TreeView coloring problems with ImageList
- Added support for PanelGadget (see example 15)
- After ClearGadgetItemList(#ListIcon), PureCOLOR_ClearAllColorsForGadget(#ListIcon) is automatically called
- Added ListIcon cell coloring callback (see example 14)

PanelGadget :

Code: Select all

Procedure GUI_CB(WindowId,message,wParam,lParam)
  Result = #PB_ProcessPureBasicEvents
  Result = PureCOLOR_CallBack(WindowId,message,wParam,lParam, Result)
  ProcedureReturn Result
EndProcedure
;
Enumeration
  #gFrame
  #gPanel
  #gPanelB1
  #gPanelB2
  #gContainer
  #gContainerExplorer
EndEnumeration
;
OpenWindow(0, 303, 182, 347, 300, #PB_Window_SystemMenu|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered, "PureCOLOR : PanelGadget demo")
CreateGadgetList(WindowID(0))
Frame3DGadget(#gFrame, 5, 5, 335, 75, "Frame3D Gadget", #PB_Frame3D_Single)
PanelGadget(#gPanel, 5, 85, 335, 100)
AddGadgetItem(#gPanel,-1,"Panel Gadget - 1")
ButtonGadget(#gPanelB1,5,5,320,22,"Button inside Panel Gadget - 1")
AddGadgetItem(#gPanel,-1,"Panel Gadget - 2")
ButtonGadget(#gPanelB2,5,5,320,22,"Button inside Panel Gadget - 2")
CloseGadgetList()
ContainerGadget(#gContainer,5,190,335,105,#PB_Container_Flat)
ExplorerTreeGadget(#gContainerExplorer,5,5,325,95,"c:\")
CloseGadgetList()
;
SetWindowCallback(@GUI_CB())
PureCOLOR_SetGadgetColor(#gPanel, #Yellow, #Blue)
PureCOLOR_SetGadgetColor(#gContainer, #Yellow, #Black)
PureCOLOR_SetGadgetColor(#gContainerExplorer, #Black, #Red)
PureCOLOR_SetButtonColor(#gPanelB1, #Blue, #Red)
PureCOLOR_SetButtonColor(#gPanelB2, #Yellow, #Black)
PureCOLOR_SetWindowColor(0, #Blue)
;
Repeat
  Select WaitWindowEvent()
    Case #PB_EventCloseWindow
      Break
  EndSelect
Until WaitWindowEvent()=#PB_EventCloseWindow
;
End
Cell Callback :

Code: Select all

Procedure.l WindowCallBack(WindowId.l, message.l, wParam.l, lParam.l)
  ReturnValue.l = #PB_ProcessPureBasicEvents
  ;
  ReturnValue = PureCOLOR_CallBack(WindowId, message, wParam, lParam, ReturnValue)
  ;
  ProcedureReturn ReturnValue
EndProcedure
;
Procedure MyCellColorCallback(GadgetNumber.l, CellRow.l, CellColumn.l, *TextColor, *BackColor)
  If GadgetNumber = 1
    CellText.s = GetGadgetItemText(GadgetNumber, CellRow, CellColumn)
    Debug Str(CellRow) + ":" + Str(CellColumn) + ">" + CellText
    Select CellText
      Case "Red"
        PokeL(*TextColor, #Red)
        Debug "-> Red"
      Case "Blue"
        PokeL(*BackColor, #Blue)
        PokeL(*TextColor, #White)
        Debug "-> Blue"
      Case "Green"
        PokeL(*TextColor, #Green)
        Debug "-> Green"
    EndSelect
  EndIf
EndProcedure
; Create Window
OpenWindow(0, 100, 300, 400, 200, #PB_Window_SystemMenu, "PureCOLOR test : cell callback demo")
SetWindowCallback(@WindowCallBack())
If CreateGadgetList(WindowID())
  ListIconGadget(1, 1, 1, 300, 160, "0", 100, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ;
  AddGadgetColumn(1, 1, "1", 100)
  AddGadgetColumn(1, 2, "2", 100)
  AddGadgetItem(1, -1, "0:0" + Chr(10) + "0:1" + Chr(10) + "Red")
  AddGadgetItem(1, -1, "1:0" + Chr(10) + "1:1" + Chr(10) + "1:2")
  AddGadgetItem(1, -1, "Blue" + Chr(10) + "Green" + Chr(10) + "2:2")
  AddGadgetItem(1, -1, "3:0" + Chr(10) + "Red" + Chr(10) + "3:2")
  AddGadgetItem(1, -1, "Red" + Chr(10) + "4:1" + Chr(10) + "Red")
  AddGadgetItem(1, -1, "Green" + Chr(10) + "Blue" + Chr(10) + "5:2")
  AddGadgetItem(1, -1, "6:0" + Chr(10) + "6:1" + Chr(10) + "6:2")
  AddGadgetItem(1, -1, "Red" + Chr(10) + "Blue" + Chr(10) + "7:2")
EndIf
PureCOLOR_SetCellColorCallback(@MyCellColorCallback())
Repeat
  EventID.l = WaitWindowEvent()
  If EventID = #PB_EventCloseWindow
    Break
  EndIf
ForEver
;
End

Posted: Tue Nov 22, 2005 2:14 pm
by DoubleDutch
Very nice! :D

Posted: Thu Nov 24, 2005 12:20 am
by Flype
sorry but it seem that TextGadget coloring doesn't work anymore :?

Code: Select all

Procedure.l myCallback(hWnd.l,uMsg.l,wParam.l,lParam.l)
  result.l = #PB_ProcessPureBasicEvents
  PureCOLOR_CallBack(hWnd,uMsg,wParam,lParam,result)
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,320,240,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"test")

CreateGadgetList(WindowID())
TextGadget(0,20,20,280,50,"TITLE - SHOULD BE COLORED !",#PB_Text_Border)

PureCOLOR_SetGadgetColor(0,$FFFFFF,$000000)

SetWindowCallback(@myCallback())

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow

Posted: Thu Nov 24, 2005 11:41 am
by gnozal
Flype wrote:sorry but it seem that TextGadget coloring doesn't work anymore :?
It works
Your callback is wrong : it should be result = PureCOLOR_CallBack(hwnd,uMsg,wParam,lParam,result) :wink:

Code: Select all

Procedure.l myCallback(hwnd.l,uMsg.l,wParam.l,lParam.l) 
  result.l = #PB_ProcessPureBasicEvents 
  result = PureCOLOR_CallBack(hwnd,uMsg,wParam,lParam,result) 
  ProcedureReturn result 
EndProcedure 

OpenWindow(0,0,0,320,240,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"test") 

CreateGadgetList(WindowID()) 
TextGadget(0,20,20,280,50,"TITLE - SHOULD BE COLORED !",#PB_Text_Border) 

PureCOLOR_SetGadgetColor(0,$FFFFFF,$000000) 

SetWindowCallback(@myCallback()) 

Repeat 
Until WaitWindowEvent()=#PB_Event_CloseWindow

Posted: Sat Nov 26, 2005 3:37 am
by Flype
oh yes sorry gnozal :lol: pfff

Posted: Wed Nov 30, 2005 2:14 am
by PHP
Is there also a solution for ListIconGadget()?

Filling the whole (!) LIG with a color and not only some rows of it?

Posted: Wed Nov 30, 2005 11:48 am
by gnozal
PHP wrote:Filling the whole (!) LIG with a color and not only some rows of it?
:?:

Did you try PureCOLOR_SetGadgetColor(#MyListIconGadget, TextColor.l, BackColor.l) ?

Posted: Sat Dec 03, 2005 7:38 pm
by Straker
I am trying to use PureCOLOR but can't seem to get it to work with a simple Text gadget. I am using jaPBe.

Code: Select all

PureCOLOR_SetGadgetColor(#Text_0,RGB(255,0,0),RGB(255,255,255)) 
Unless I am mistaken this should draw red text on a white background. But it just gives me the standard black on window color background.

Posted: Sat Dec 03, 2005 8:05 pm
by rsts
Hmm - i use code like that all the time and it works perfectly.

Are you sure you have your window callback set?

cheers