Splitter Gadget as Slider Example

Share your advanced PureBasic knowledge/code with the community.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Splitter Gadget as Slider Example

Post 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
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Works as advertised, verynice idea. Thank you for posting this code.
Shouldn't an admin move this to 'tips & Tricks' ?
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post 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.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

:D

Thinking outside the box!

Nice.
Dare2 cut down to size
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Dare wrote::D

Thinking outside the box!

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

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Nice idea. :)

Thanks.
I may look like a mule, but I'm not a complete ass.
Post Reply