Color DropDown Menu

Just starting out? Need help? Post your questions and find answers here.
jeslar360
User
User
Posts: 20
Joined: Thu Aug 28, 2008 6:24 am

Color DropDown Menu

Post 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 ]
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Do you need a cross platform solution :?:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
jeslar360
User
User
Posts: 20
Joined: Thu Aug 28, 2008 6:24 am

Post by jeslar360 »

Nope. This software uses Windows API for some of its features...so cross platform is out.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Try a search here for ComboBoxEx and see what you find. :wink:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply