Page 1 of 1

Splitter Gadget as Slider Example

Posted: Sun May 20, 2007 10:12 am
by electrochrisso
Playing around with the splitter gadget, I thought it could come in useful as a slider as well.
The buttons could also be used in combination like in the example.

Code: Select all

;
; Splitter Gadget as Slider by Electrochrisso, PB4 2007
;

CreateImage(0,20,100)
Procedure SetGadgets()
  Shared Value
  Value=100-GetGadgetState(2)
  SetGadgetText(3,Str(Value))
  SetGadgetColor(3,#PB_Gadget_BackColor,RGB(200,100,Value*2))
  StartDrawing(ImageOutput(0))
    Box(0,0,20,100,RGB(0,0,0))
    Box(0,100-Value,20,Value,RGB(255,0,0))
  StopDrawing()
  SetGadgetState(4,ImageID(0))
EndProcedure

If OpenWindow(0, 0, 0, 200, 150, "Splitter as Slider",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ButtonGadget(0, 0, 0, 0, 0, "Up")
    ButtonGadget(1, 0, 0, 0, 0, "Dn")
    SplitterGadget(2, 5, 5, 25, 107, 0, 1, #PB_Splitter_Separator)
    TextGadget(3, 60, 52, 20, 13, Str(GetGadgetState(2)),#PB_Text_Center )
    ImageGadget(4,35,8,20,100,ImageID(0))
    SetGadgets()
    Repeat
      Event=WaitWindowEvent()
      Select Event
        Case #PB_Event_Gadget
          EventGadgetID = EventGadget()
          If EventGadgetID=2
            SetGadgets()
          EndIf
          If EventGadgetID=0
            SetGadgetState(2,0)
            SetGadgets()
          EndIf
          If EventGadgetID=1
            SetGadgetState(2,107)
            SetGadgets()
          EndIf
      EndSelect
    Until Event=#PB_Event_CloseWindow
  EndIf
EndIf
End

Posted: Sun May 20, 2007 10:57 am
by dell_jockey
Works as advertised, verynice idea. Thank you for posting this code.
Shouldn't an admin move this to 'tips & Tricks' ?

Posted: Sun May 20, 2007 11:12 am
by electrochrisso
Thanks dell_jockey
I wasn't sure if it should go there or not. Looks like it should because it moved here now.
Admin sure is quick.

Posted: Sun May 20, 2007 12:19 pm
by Dare
:D

Thinking outside the box!

Nice.

Posted: Sun May 20, 2007 6:25 pm
by rsts
Dare wrote::D

Thinking outside the box!

Nice.
Or at least 'sliding' things around inside. :)

cheers

Posted: Sun May 20, 2007 8:20 pm
by srod
Nice idea. :)

Thanks.