Page 1 of 1

Color DropDown Menu

Posted: Tue Sep 09, 2008 4:06 am
by jeslar360
I have seen some programs able to have a Drop Down menu to select colors, where the selections themselves are the colors...and then the top display box changes color, to match.

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
[edit by Rings, set a usefull topic ]

Posted: Thu Sep 18, 2008 2:22 am
by Sparkie
Do you need a cross platform solution :?:

Posted: Sun Sep 28, 2008 6:02 pm
by jeslar360
Nope. This software uses Windows API for some of its features...so cross platform is out.

Posted: Sun Sep 28, 2008 9:25 pm
by Sparkie
Try a search here for ComboBoxEx and see what you find. :wink: