Since I can't get colors to work with with the ComboBox gadget, I tried something else. But it seems to be a NoGo as well. Would someone take a look at this code, and offer suggestions as to a better way?
Code: Select all
Enumeration
#IconView_Colors
#Image_ColorView
#Image_ColorDisp
EndEnumeration
Procedure Add_Color(NewColor)
n.l = CountGadgetItems(#IconView_Colors)
AddGadgetItem(#IconView_Colors, -1, " ")
SetGadgetItemColor(#IconView_Colors, n, #PB_Gadget_BackColor, NewColor, -1)
SetGadgetItemColor(#IconView_Colors, n, #PB_Gadget_FrontColor, NewColor, -1)
EndProcedure
Procedure ShowColor(color.l)
If IsImage(#Image_ColorDisp)
FreeImage(#Image_ColorDisp)
EndIf
CreateImage(#Image_ColorDisp, 49, 18)
StartDrawing(ImageOutput(#Image_ColorDisp))
FillArea(1,1,color)
StopDrawing()
ProcedureReturn(ImageID(#Image_ColorDisp))
EndProcedure
If OpenWindow(0, 1, 1, 200, 100, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
ListIconGadget(#IconView_Colors, 5, 5, 70, 80, "", 49)
ImageGadget(#Image_ColorView, 6, 6, 68, 18, ShowColor(color.l))
Add_Color(RGB(255, 0, 0))
Add_Color(RGB(127, 0, 0))
Add_Color(RGB( 0,255, 0))
Add_Color(RGB( 0,127, 0))
Add_Color(RGB( 0, 0,255))
Add_Color(RGB( 0, 0,127))
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = #True
Case #PB_Event_Gadget
Gadget = EventGadget()
Select Gadget
Case #IconView_Colors
If GetGadgetState(#IconView_Colors) < 0
FreeGadget(#Image_ColorView)
ImageGadget(#Image_ColorView, 6, 6, 68, 18, ShowColor(color.l))
Else
FreeGadget(#Image_ColorView)
ImageGadget(#Image_ColorView, 6, 6, 68, 18, ShowColor(color.l))
EndIf
item = GetGadgetState(#IconView_Colors)
color = GetGadgetItemColor(#IconView_Colors, item, #PB_Gadget_BackColor)
SetGadgetState(#Image_ColorView, ShowColor(color))
EndSelect
EndSelect
Delay(1)
Until Quit
EndIf