
The code I posted is just a rip from the main code thats why it looks a bit wierd - its fine in the main code.
Thanks once again and Merry Christmas!
-Anthony
Moderator: gnozal
Code: Select all
PureCOLOR_SetGadgetColor(EventGadget, -1, lcolor)
Could I have some code examples ?TerryHough wrote:The -1 sets it to the system color (black). However, in some cases the text color has been changed to a different color.
Theoritically, when TextColor = #PureCOLOR_SystemColor (-1), TextColor is replaced by GetSysColor_(#COLOR_XXX), where #COLOR_XXX is chosen accordingly to the gadget class.TerryHough wrote:Is there anyway to leave the text color unchanged and change just the background?
Or, query for the text color and use that in place of the -1 when the
command is issued?
Code: Select all
; Set Callback
Procedure.l WindowCallBack(WindowId.l, Message.l, wParam.l, lParam.l)
ReturnValue = #PB_ProcessPureBasicEvents
;
ReturnValue = PureCOLOR_CallBack(WindowId, Message, wParam, lParam, ReturnValue)
;
ProcedureReturn ReturnValue
EndProcedure
; Create Window
OpenWindow(0, 100, 300, 400, 400, #PB_Window_ScreenCentered|#PB_Window_SystemMenu, "PureCOLOR test")
SetWindowCallback(@WindowCallBack())
If CreateGadgetList(WindowID())
StringGadget(1, 10, 10, 90, 20, "StringGadget 1")
ListIconGadget(2, 10, 40, 150, 100, "", 146, #PB_ListIcon_GridLines)
AddGadgetItem(2, -1, "ListIconGadget 2-1")
AddGadgetItem(2, -1, "ListIconGadget 2-2")
AddGadgetItem(2, -1, "ListIconGadget 2-3")
AddGadgetItem(2, -1, "ListIconGadget 2-4")
AddGadgetItem(2, -1, "ListIconGadget 2-5")
TextGadget(3, 10, 160, 300, 200, "TextGadget 3")
ButtonGadget(4, 200, 10, 80, 20, "Button 4")
ComboBoxGadget(5, 295, 10, 100, 100)
AddGadgetItem(5, -1, "ComboBox 5-1")
AddGadgetItem(5, -1, "ComboBox 5-2")
SetGadgetState(5, 0)
CheckBoxGadget(6, 110, 10, 80, 20, "CheckBox 6")
ListViewGadget(7, 160, 40, 150, 100, #PB_ListIcon_GridLines)
AddGadgetItem(7, -1, "ListViewGadget 7-1")
AddGadgetItem(7, -1, "ListViewGadget 7-2")
AddGadgetItem(7, -1, "ListViewGadget 7-3")
EndIf
; Adding colors
Msg$ = "The StringGadget gets the text changed to Red, system Default background "
Msg$ + "But after a 10 second delay, let's change its background color without changing "
Msg$ + "its text color. However, lets assume we don't know its current text color. We "
Msg$ + "want to change the background without knowing or affecting the text color. "
PureCOLOR_SetGadgetColor(1, RGB(255,0,0), -1)
SetGadgetText(3,Msg$)
; -----------------------------------------------------------------------------------
; PureCOLOR_SetGadgetColor(2, RGB(0,255,0), -1)
; PureCOLOR_SetGadgetColorEx(2, RGB(0,0,0), RGB(255, 255, 255), RGB(255, 255, 223), #PureCOLOR_LV_AlternateColors)
; PureCOLOR_SetGadgetColor(3, RGB(255,0,0), RGB(0,0,0))
; PureCOLOR_SetButtonColor(4, RGB(255,0,0), RGB(0,255,0))
; PureCOLOR_SetGadgetColor(5, RGB(255,0,0), RGB(255,255,0))
; PureCOLOR_SetGadgetColor(6, RGB(255,255,0), -1)
; PureCOLOR_SetGadgetColor(7, RGB(255,0,0), RGB(100,100,0))
; PureCOLOR_ClearGadgetColor(2)
;
Msg$ = "OK. let's wait 10 seconds so we can see how it looks to begin with."
Msg$ + "and then change the StringGadget's background color only."
SetGadgetText(3,Msg$)
While WindowEvent(): Wend
Delay(10000)
PureCOLOR_SetGadgetColor(1, -1, RGB(150,150, 255))
Msg$ = "Nope, that didn't work. The text was changed to black (System default). "
Msg$ + " So, lets set it back to the original and try again."
SetGadgetText(3,Msg$)
While WindowEvent(): Wend
Delay(10000)
PureCOLOR_SetGadgetColor(1, RGB(255,0,0), -1)
While WindowEvent(): Wend
Delay(1000)
PureCOLOR_SetGadgetColor(1, 0, RGB(150,150, 255))
While WindowEvent(): Wend
Msg$ = "Nope, that didn't work. The text was changed to black (System default) again. "
Msg$ + "So, lets set it back to the original and try again. This time lets see if we can "
Msg$ + "find out its current color and just reset to that."
SetGadgetText(3,Msg$)
PureCOLOR_SetGadgetColor(1, RGB(255,0,0), -1)
While WindowEvent(): Wend
Delay(1000)
ActivateGadget(1)
TextColor = GetSysColor_(#COLOR_WINDOWTEXT)
PureCOLOR_SetGadgetColor(1, TextColor, RGB(150,150, 255))
Msg$ = "Nope, that didn't work. The text was changed to black (System default) again. "
Msg$ + "But, obviously, I don't know how to use the WinAPI to get the current text color."
SetGadgetText(3,Msg$)
While WindowEvent(): Wend
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
End
Code: Select all
PureCOLOR_SetGadgetColor(#Gadget, #Red, #White) ; --> Text = Red : Background = White
; You have to define the colors a first time before using #PureCOLOR_LastDefinedValue
PureCOLOR_SetGadgetColor(#Gadget, #PureCOLOR_LastDefinedValue, #Green) ; --> Text = Red : Background = Green
PureCOLOR_SetGadgetColor(#Gadget, #Blue, #PureCOLOR_LastDefinedValue) ; --> Text = Blue : Background = Green
gnozal wrote:PureCOLOR library V12.04 (Jan 02nd 2006)
PurposeFunctionsCode: Select all
Coloring gadgets as simply as possible, and some other nice coloring functions
ExampleCode: Select all
* PureCOLOR_SetGadgetColor(GadgetNumber.l, TextColor.l, BackColor.l) Set gadget colors (any gadget except a ButtonGadget). For buttons, use PureCOLOR_SetButtonColor(). TextColor and BackColor are RGB values. Special values : - TextColor : #PureCOLOR_SystemColor => TextColor is system color #PureCOLOR_UseLastColor => TextColor is the last color set (don't change current color) - BackColor : #PureCOLOR_SystemColor => BackColor is system color #PureCOLOR_DontSetBackColor => BackColor is parent window color (simulates transparency) #PureCOLOR_UseLastColor => BackColor is the last color set (don't change current color) * PureCOLOR_SetGadgetColorEx(GadgetNumber.l, TextColor.l, BackColor.l, Param.l, Flag.l) Extended version of PureCOLOR_SetGadgetColor() PureCOLOR_SetGadgetColorEx(GadgetNumber.l, TextColor.l, BackColor.l, 0, #PureCOLOR_LV_Standard) is equivalent to PureCOLOR_SetGadgetColor(GadgetNumber.l, TextColor.l, BackColor.l) Colors : TextColor and BackColor are RGB values. Special values : - TextColor : #PureCOLOR_SystemColor => TextColor is system color - BackColor : #PureCOLOR_SystemColor => BackColor is system color #PureCOLOR_DontSetBackColor => BackColor is parent window color (simulates transparency) Flags : * LISTICON GADGET - #PureCOLOR_LV_AlternateColors [Param is a long (Param.l)] Alternate ListIconView row colors :BackColor -> Even row color Param.l -> Odd row color - #PureCOLOR_LV_AlternateColors2 [Param is a long (Param.l)] Alternate ListIconView column colors :BackColor -> Even column color Param.l -> Odd column color - #PureCOLOR_LV_GreaterThan [Param is a structure address (@Param.PureCOLOR_ParamStructure)] Value dependant cell colors :Param\SpecialTextColor -> text color Param\SpecialBackColor -> back color Param\SpecialTestValue -> test value Gadget cell color is (Param\SpecialTextColor, Param\SpecialBackColor) if the cell value is > Param\SpecialTestValue If Param\SpecialBackColor = #PureCOLOR_DontSetBackColor, there is no background color change [WORKS WITH NUMERIC CELL VALUES ONLY] - #PureCOLOR_LV_LesserThan [Param is a structure address (@Param.PureCOLOR_ParamStructure)] Value dependant cell colors :Param\SpecialTextColor -> text color Param\SpecialBackColor -> back color Param\SpecialTestValue -> test value Gadget cell color is (Param\SpecialTextColor, Param\SpecialBackColor) if the cell value is < Param\SpecialTestValue If Param\SpecialBackColor = #PureCOLOR_DontSetBackColor, there is no background color change [WORKS WITH NUMERIC CELL VALUES ONLY] * TREE GADGET - #PureCOLOR_TV_NodeLevel1 [Param is a long (Param.l)] Set colors for node level 1 (and TreeGadget background color) : TextColor.l, BackColor.l If Param = #PureCOLOR_DontSetBackColor, there is no background color change - #PureCOLOR_TV_NodeLevel2 [Param = 0] Set colors for node level 2 (and TreeGadget background color) : TextColor.l, BackColor.l - #PureCOLOR_TV_NodeLevel3 [Param = 0] Set colors for node level 3 (and TreeGadget background color) : TextColor.l, BackColor.l - #PureCOLOR_TV_NodeLevel4 [Param = 0] Set colors for node level 4 (and TreeGadget background color) : TextColor.l, BackColor.l The node levels > 4 are colored like node 1 * TREE OR LISTICON GADGETS - #PureCOLOR_LTV_SelectedItem [Param = 0] Set colors for the selected item (selection bar) : TextColor.l, BackColor.l * MISCELLANOUS GADGETS - #PureCOLOR_BackgroundImage [Param is a long (Param.l)] Set a 'transparent' backcolor for the gadget (backcolor = image color) Param is the image output id. * PureCOLOR_SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l, [TextColorPushed.l, [BackColorPushed.l]]) Set button colors. All colors are are RGB values. Optional parameters : TextColorPushed :text color when button is pushed (and toggle text color) BackColorPushed :back color when button is pushed (and toggle back color) Special values : #PureCOLOR_SystemColor => color is system color #PureCOLOR_UseLastColor => color is the last color set (don't change current color) * PureCOLOR_ClearGadgetColor(GadgetNumber.l) Clear gadget color set with PureCOLOR_SetGadgetColor(), PureCOLOR_SetGadgetColorEx() or PureCOLOR_SetButtonColor(). * PureCOLOR_SetCellColor(ListIconNumber.l, Row.l, Column.l, TextColor.l, BackColor.l) Set listicon cell color. TextColor and BackColor are RGB values. Special values : - TextColor : #PureCOLOR_SystemColor => TextColor is system color - BackColor : #PureCOLOR_SystemColor => BackColor is system color Note : the listicon cell / row / column coloring functions use dynamic coordinates, e.g. the colorized cells / rows / columns coordinates are changed in realtime when the listicon [Add|Remove]Gadget[Item|Column]() functions are used. For example : if cell (1,1) is colorized and a column is added at position 1, the cell coordinates are changed to (1,2) : the cell remains colorized (the new cell (1,1) is not). The coloring priority is Cells > Columns > Rows. * PureCOLOR_SetCellColorCallback(*ProcedureAddress) Declare a ListIcon coloring callback. The callback is a procedure called for each cell in a ListIconGadget. It allows the user to modify the cell colors according to its content. * PureCOLOR_GetCellColor(ListIconNumber.l, Row.l, Column.l, WhatColor.l) Get the listicon cell color, set with the PureCOLOR SetCellColor() / SetColumnColor() / SetRowColor() functions. Returned values - Cell TextColor if WhatColor = 1 - Cell BackColor if WhatColor = 2 - #CLR_DEFAULT if no color is set for the cell or the cell don't exist TextColor and BackColor are RGB values. * PureCOLOR_ClearCellColor(ListIconNumber.l, Row.l, Column.l) Clear listicon cell color. * PureCOLOR_SetColumnColor(ListIconNumber.l, Column.l, TextColor.l, BackColor.l) Set listicon column color. TextColor and BackColor are RGB values. Special values : - TextColor : #PureCOLOR_SystemColor => TextColor is system color - BackColor : #PureCOLOR_SystemColor => BackColor is system color Note : the listicon cell / row / column coloring functions use dynamic coordinates, e.g. the colorized cells / rows / columns coordinates are changed in realtime when the listicon [Add|Remove]Gadget[Item|Column]() functions are used. For example : if cell (1,1) is colorized and a column is added at position 1, the cell coordinates are changed to (1,2) : the cell remains colorized (the new cell (1,1) is not). The coloring priority is Cells > Columns > Rows. * PureCOLOR_ClearColumnColor(ListIconNumber.l, Column.l) Clear listicon column color. * PureCOLOR_SetRowColor(ListIconNumber.l, Row.l, TextColor.l, BackColor.l) Set listicon row color. TextColor and BackColor are RGB values. Special values : - TextColor : #PureCOLOR_SystemColor => TextColor is system color - BackColor : #PureCOLOR_SystemColor => BackColor is system color Note : the listicon cell / row / column coloring functions use dynamic coordinates, e.g. the colorized cells / rows / columns coordinates are changed in realtime when the listicon [Add|Remove]Gadget[Item|Column]() functions are used. For example : if cell (1,1) is colorized and a column is added at position 1, the cell coordinates are changed to (1,2) : the cell remains colorized (the new cell (1,1) is not). The coloring priority is Cells > Columns > Rows. * PureCOLOR_ClearRowColor(ListIconNumber.l, Row.l) Clear listicon row color. * PureCOLOR_SetTreeItemColor(TreeNumber.l, ItemNumber.l, TextColor.l, BackColor.l) Set tree item color. TextColor and BackColor are RGB values. Special values : - TextColor : #PureCOLOR_SystemColor => TextColor is system color - BackColor : #PureCOLOR_SystemColor => BackColor is system color * PureCOLOR_ClearTreeItemColor(TreeNumber.l, ItemNumber.l) Clear tree item color. * PureCOLOR_SetColumnHeaderColor(ListIconNumber.l, Column.l, TextColor.l, BackColor.l) Set listicon column header color. TextColor and BackColor are RGB values. Special values : - TextColor : #PureCOLOR_SystemColor => TextColor is system color - BackColor : #PureCOLOR_SystemColor => BackColor is system color Note : this function uses dynamic coordinates, e.g. the colorized columns coordinates are changed in realtime when the listicon [Add|Remove]GadgetColumn() functions are used. * PureCOLOR_ClearColumnHeaderColor(ListIconNumber.l, Column.l) Clear listicon column header color. * PureCOLOR_ClearAllColorsForGadget(GadgetNumber.l) Clear all colors for the specified gadget. Usefull for complex gadgets like ListIcon or TreeView (clears cells colors, row colors, column colors, etc...). * PureCOLOR_ClearAllGadgetColors() Clear all gadget colors. * PureCOLOR_SetWindowColor(WindowNumber.l, BackColor.l) Set window back color. BackColor is a RGB value. Special values : - BackColor : #PureCOLOR_SystemColor => BackColor is system color * PureCOLOR_ClearWindowColor(WindowNumber.l) Clear window color. * PureCOLOR_SetMenuColors(MenuNumber.l , TextColor.l, BackColor.l, TextColorSelected.l, BackColorSelected.l) Set menu text and back colors [may not work with WinNT4]. Up to 3 menu levels are supported. Colors : All colors are RGB values. TextColorSelected and BackColorSelected are the colors of a selected or hotlighted menu item. Special values : #PureCOLOR_SystemColor => color is system color * PureCOLOR_SetMenuItemColors(MenuNumber.l, MenuItemID.l, TextColor.l, BackColor.l, TextColorSelected.l, BackColorSelected.l) Set menu item colors for an existing ownerdrawn menu [may not work with WinNT4] Up to 3 menu levels are supported. Colors : All colors are RGB values. TextColorSelected and BackColorSelected are the colors of a selected or hotlighted menu item. Special values : #PureCOLOR_SystemColor => color is system color * PureCOLOR_SetPopupMenuBackColor(MenuNumber.l, BackColor.l) Set menu backcolor [may not work with WinNT4]. * PureCOLOR_RedrawGadgetAfterColor(TrueOrFalse.l) Set gadget redraw mode after color is set or cleared. Values : #TRUE :the gadget is redrawn [WinAPI RedrawWindow()] after color is set or cleared [Default]; #FALSE :the gadget is not redrawn after color is set or cleared.
Code: Select all
; Create Window OpenWindow(0, 100, 300, 400, 200, #PB_Window_SystemMenu, "PureCOLOR test") If CreateGadgetList(WindowID()) StringGadget(1, 10, 10, 90, 20, "StringGadget 1") ListIconGadget(2, 10, 40, 150, 100, "", 146, #PB_ListIcon_GridLines) AddGadgetItem(2, -1, "ListIconGadget 2-1") AddGadgetItem(2, -1, "ListIconGadget 2-2") AddGadgetItem(2, -1, "ListIconGadget 2-3") AddGadgetItem(2, -1, "ListIconGadget 2-4") AddGadgetItem(2, -1, "ListIconGadget 2-5") TextGadget(3, 10, 160, 300, 30, "TextGadget 3", #PB_Text_Center) ButtonGadget(4, 200, 10, 80, 20, "Button 4") ComboBoxGadget(5, 295, 10, 100, 100) AddGadgetItem(5, -1, "ComboBox 5-1") AddGadgetItem(5, -1, "ComboBox 5-2") SetGadgetState(5, 0) CheckBoxGadget(6, 110, 10, 80, 20, "CheckBox 6") ListViewGadget(7, 160, 40, 150, 100, #PB_ListIcon_GridLines) AddGadgetItem(7, -1, "ListViewGadget 7-1") AddGadgetItem(7, -1, "ListViewGadget 7-2") AddGadgetItem(7, -1, "ListViewGadget 7-3") EndIf ; Adding colors PureCOLOR_SetGadgetColor(1, RGB(255,0,0), -1) ;PureCOLOR_SetGadgetColor(2, RGB(0,255,0), -1) PureCOLOR_SetGadgetColorEx(2, RGB(0,0,0), RGB(255, 255, 255), RGB(255, 255, 223), #PureCOLOR_LV_AlternateColors) PureCOLOR_SetGadgetColor(3, RGB(255,0,0), RGB(0,0,0)) PureCOLOR_SetButtonColor(4, RGB(255,0,0), RGB(0,255,0)) PureCOLOR_SetGadgetColor(5, RGB(255,0,0), RGB(255,255,0)) PureCOLOR_SetGadgetColor(6, RGB(255,255,0), -1) PureCOLOR_SetGadgetColor(7, RGB(255,0,0), RGB(100,100,0)) ;PureCOLOR_ClearGadgetColor(2) ; Repeat Until WaitWindowEvent() = #PB_EventCloseWindow ; End
Download
http://people.freenet.de/gnozal/PureCOLOR.zip
Other libs and tools at http://people.freenet.de/gnozal
Should be fixed now.TerryHough wrote:Works great! At least for the text portion.
But, I am getting a white background when using
#PureCOLOR_UseLastColor for the background sometimes. I will work
with it a bit more to make sure I haven't used it incorrectly.
It seems to work in my example, but not in the main program.![]()
Thanks,
Terry
Maybewcardoso wrote:sorry if I repeat someone request, but, can you add coloring statusbar items ?. Both fore & back one.![]()
thanks
Code: Select all
PureCOLORParam.PureCOLOR_ParamStructure
PureCOLORParam\SpecialTextColor = $0000FF
PureCOLORParam\SpecialBackColor = #PureCOLOR_DontSetBackColor
PureCOLORParam\SpecialTestValue = 0
PureCOLOR_SetGadgetColorEx(#gListe,0,0,@PureCOLORParam,#PureCOLOR_LV_LesserThan)
PureCOLORParam.PureCOLOR_ParamStructure
PureCOLORParam\SpecialTextColor = $00AA00
PureCOLORParam\SpecialBackColor = #PureCOLOR_DontSetBackColor
PureCOLORParam\SpecialTestValue = 0
PureCOLOR_SetGadgetColorEx(#gListe,0,0,@PureCOLORParam,#PureCOLOR_LV_GreaterThan)
What about the new PureCOLOR_SetCellColorCallback() function ?Flype wrote:hello gnozal,
when i use coloring for values in a listicongadget, for example, all positives values in GREEN, and all negatives values in RED. It's Ok, it's works. BUT, can i specify only a specific column and let the others unchanged which is important for my soft ?
Code: Select all
Procedure MyCellColorCallback(GadgetNumber.l, CellRow.l, CellColumn.l, *TextColor, *BackColor)
If GadgetNumber = 1 And CellColumn = 1 ; <----- Example modified to color only column 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")
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(0, @MyCellColorCallback())
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventCloseWindow
Break
EndIf
ForEver
;
End