Trackbar Gadget with two slider

Just starting out? Need help? Post your questions and find answers here.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Trackbar Gadget with two slider

Post by Lord »

Hi!

If I remember correct, I did see a code example for a TrackbarGadget
with two slider (based on CanvasGagdet?).
When a slider was moved, a Tooltip (moving with slider) showed the
actual value.
But I can't find this fine little code anymore in this Forum. Does anyone
else remember where I have to look?

Thanks in advance.
Image
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Trackbar Gadget with two slider

Post by davido »

@Lord,
Is this the one to which you refer?
http://www.purebasic.fr/english/viewtop ... 46#p365646

Or perhaps this one with a 'few' sliders. :)
DE AA EB
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Trackbar Gadget with two slider

Post by Lord »

Hi davido!

Thanks for answering.
davido wrote:...
Is this the one to which you refer?
http://www.purebasic.fr/english/viewtop ... 46#p365646
Sorry, no, it isn't.
davido wrote:...
Or perhaps this one with a 'few' sliders. :)
I don't understand?
Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Trackbar Gadget with two slider

Post by RSBasic »

Lord wrote:with two slider (based on CanvasGagdet?).
Do you mean this?:
Image
Lord wrote:When a slider was moved, a Tooltip (moving with slider) showed the actual value.
http://www.rsbasic.de/aktualisierung/wi ... nzeigen.pb :?:
Image
Image
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Trackbar Gadget with two slider

Post by Lord »

Hi RSBasic!
RSBasic wrote:...
Do you mean this?:
Image
...
Yes, this kind of TrackbarGadget...
RSBasic wrote:...
Lord wrote:When a slider was moved, a Tooltip (moving with slider) showed the actual value.
http://www.rsbasic.de/aktualisierung/wi ... nzeigen.pb
...with a Tooltip on each slider (when moved).
Image
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Trackbar Gadget with two slider

Post by Shardik »

In this thread c4s with the help of RASHAD demonstrated how to display a TrackbarGadget with a ToolTip showing the actual values.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Trackbar Gadget with two slider

Post by Lord »

Shardik wrote:In this thread c4s with the help of RASHAD demonstrated how to display a TrackbarGadget with a ToolTip showing the actual values.
Thank you shardik for posting your finding.
But this is not what I'm looking for.

The main goal for this type of TrackBar is the double slider,
so I can set a lower and an upper limit on one bar.
The tooltip would be an extra feature.

I know, I saw this somewhere and not so long ago here in
this (english or german) forum.
Image
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Trackbar Gadget with two slider

Post by Demivec »

You are probably referring to this creation of netmaestro.

Here is an update of his code for compiling with PureBasic v5.41:

Code: Select all

;=============================================================
; Library:            TrackSelectionGadget
; Author:             Lloyd Gallant (netmaestro)
; Date:               April 30, 2011
; Target compiler:    Purebasic 4.60 and later
; Update:             To PureBasic 5.41 LTS by Demivec on January 20, 2016
; Target OS:          Microsoft Windows all
; License:            Free, unrestricted, no warranty
;=============================================================
;
;  How to use the gadget:
; 
;  - Leftclick and drag the lower pointer to set the selection endpoint
;  - Leftclick and drag the upper pointer to set the selection startpoint
;  - Fine-tune the selections with the mousewheel while the mousepointer is over the appropriate pointer
;  - Move the selection endpoint one increment higher/lower with the Right/Left tArrow keys
;  - Move the selection startpoint one increment higher/lower with the Shift/Right and Shift/left arrow keys
;  - Leftclicks outside the thumbs affect the startpoint if the mousepointer is in the top half of the gadget,
;    and the endpoint if the mousepointer is in the bottom half.
;
;  - Note: keyboard control of fine-tuning is scrapped in favor of the mousewheel only.

Structure TrackData
  p_region1.l
  p_region2.l
  baseimage.l
  baseimagetop.l
  baseimageleft.l
  bclientwidth.l
  baseimagewidth.l
  pointer1.l
  pointer2.l
  selection_start.l
  selection_end.l
  selection_max.l
  tickmin.l
  tickmax.l
  tickleftx.l
  tickrightx.l
  pointer1top.l
  pointer2top.l
  pointer1x.l
  pointer2x.l
  pointermin.l
  pointermax.l
  startchanged.l
  endchanged.l
  displayfont.l
EndStructure

Procedure CreatePointers()
  Protected ptr, i, j
  ptr = CreateImage(#PB_Any, 11,30,32,#PB_Image_Transparent)                 
  
  Protected Dim pcolors(4)
  pcolors(0) = RGBA(0,0,0,0)
  pcolors(1) = GetSysColor_(#COLOR_3DDKSHADOW) |$FFFFFFFFFF000000
  pcolors(2) = GetSysColor_(#COLOR_3DSHADOW)   |$FFFFFFFFFF000000
  pcolors(3) = GetSysColor_(#COLOR_3DFACE)     |$FFFFFFFFFF000000
  pcolors(4) = GetSysColor_(#COLOR_3DHIGHLIGHT)|$FFFFFFFFFF000000               
  
  StartDrawing(ImageOutput(ptr))
    DrawingMode(#PB_2DDrawing_AllChannels)
    Restore base   : For i=0 To 10  : Read.i index  : Plot(i,0,pcolors(index)) : Next
    For j=1 To 9   : Restore body   : For i=0 To 10 : Read.i index : Plot(i,j,pcolors(index)) : Next : Next
    Restore pdn    : For j=10 To 14 : For i=0 To 10 : Read.i index : Plot(i,j,pcolors(index)) : Next : Next
    Restore pup    : For j=15 To 19 : For i=0 To 10 : Read.i index : Plot(i,j,pcolors(index)) : Next : Next   
    For j=20 To 28 : Restore body   : For i=0 To 10 : Read.i index : Plot(i,j,pcolors(index)) : Next : Next   
    Restore base   : For i=0 To 10  : Read.i index  : Plot(i,29,pcolors(index)) : Next
  StopDrawing()
  
  ProcedureReturn ptr
  
  DataSection
    base: : Data.i 4,4,4,4,4,4,4,4,4,4,1
    body: : Data.i 4,3,3,3,3,3,3,3,3,2,1
    pdn: :  Data.i 0,4,3,3,3,3,3,3,2,1,0,0,0,4,3,3,3,3,2,1,0,0,0,0,0,4,3,3
    Data.i 2,1,0,0,0,0,0,0,0,4,2,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0
    pup: :  Data.i 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,4,2,1,0,0,0,0,0,0,0,4,3,3
    Data.i 2,1,0,0,0,0,0,4,3,3,3,3,2,1,0,0,0,4,3,3,3,3,3,3,2,1,0
  EndDataSection
  
EndProcedure

Procedure RedrawTrackSelectionGadget(gadget)
  *p.TrackData = GetGadgetData(gadget)
  StartDrawing(CanvasOutput(Gadget))
    Box(0,0,GadgetWidth(Gadget),GadgetHeight(Gadget),GetSysColor_(#COLOR_3DFACE))
    DrawImage(ImageID(*p\baseimage),*p\baseimageleft,*p\baseimagetop)
    Box(*p\tickleftx,*p\baseimagetop+2,*p\tickrightx-*p\tickleftx+1,11,GetSysColor_(#COLOR_MENUHILIGHT))
    DrawAlphaImage(ImageID(*p\pointer1),*p\pointer1x,*p\pointer1top)   
    DrawAlphaImage(ImageID(*p\pointer2),*p\pointer2x,*p\pointer2top)
    
    Box(*p\tickmin-17,*p\pointer1top-11,35,10, GetSysColor_(#COLOR_INFOBK))
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(*p\tickmin-17,*p\pointer1top-11,35,10,GetSysColor_(#COLOR_3DDKSHADOW))
    DrawingFont(*p\displayfont)
    DrawingMode(#PB_2DDrawing_Transparent)
    txt$ = Str(*p\selection_start)
    w = TextWidth(txt$)/2
    DrawText(*p\tickmin-w,*p\pointer1top-11,txt$,GetSysColor_(#COLOR_INFOTEXT))
    
    DrawingMode(#PB_2DDrawing_Default)
    Box(*p\tickmin-17,*p\pointer2top+16,35,10,GetSysColor_(#COLOR_INFOBK))
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(*p\tickmin-17,*p\pointer2top+16,35,10,GetSysColor_(#COLOR_3DDKSHADOW))
    DrawingFont(*p\displayfont)
    DrawingMode(#PB_2DDrawing_Transparent)
    txt$ = Str(*p\selection_end)
    w = TextWidth(txt$)/2
    DrawText(*p\tickmin-w,*p\pointer2top+16,txt$,GetSysColor_(#COLOR_INFOTEXT))   
    
  StopDrawing()
EndProcedure

ProcedureDLL TrackSelectGadget(gadgetnumber, x, y, width, min=0, max=100, drawfocus=0)
  tmp = CreatePointers()
  pointer1 = GrabImage(tmp, #PB_Any,0,0,11,15)
  pointer2 = GrabImage(tmp, #PB_Any,0,15,11,15)
  FreeImage(tmp)
  
  If drawfocus
    flags = #PB_Canvas_Keyboard|#PB_Canvas_ClipMouse|#PB_Canvas_DrawFocus
  Else
    flags = #PB_Canvas_Keyboard|#PB_Canvas_ClipMouse
  EndIf
  
  Protected height = 60
  If gadgetnumber = #PB_Any
    result = CanvasGadget(#PB_Any, x, y, width, height, flags)
    gadgetnumber = result
  Else
    result = CanvasGadget(gadgetnumber, x, y, width, height, flags)
  EndIf
  
  h1 = CreateRectRgn_(0,0,11,10)
  h2 = CreateRectRgn_(1,10,10,11)
  CombineRgn_(h1,h1,h2,#RGN_XOR)
  h2 = CreateRectRgn_(2,11,9,12)
  CombineRgn_(h1,h1,h2,#RGN_XOR)
  h2 = CreateRectRgn_(3,12,8,13)
  CombineRgn_(h1,h1,h2,#RGN_XOR)
  h2 = CreateRectRgn_(4,13,7,14)
  CombineRgn_(h1,h1,h2,#RGN_XOR)
  h2 = CreateRectRgn_(5,14,6,15)
  CombineRgn_(h1,h1,h2,#RGN_XOR)
  
  h3 = CreateRectRgn_(5,0,6,1)
  h4 = CreateRectRgn_(4,1,7,2)
  CombineRgn_(h3,h3,h4,#RGN_XOR)
  h4 = CreateRectRgn_(3,2,8,3)
  CombineRgn_(h3,h3,h4,#RGN_XOR)
  h4 = CreateRectRgn_(2,3,9,4)
  CombineRgn_(h3,h3,h4,#RGN_XOR)
  h4 = CreateRectRgn_(1,4,10,5)
  CombineRgn_(h3,h3,h4,#RGN_XOR)
  h4 = CreateRectRgn_(0,5,11,15)
  CombineRgn_(h3,h3,h4,#RGN_XOR)
  
  *gadgetdata.TrackData = AllocateMemory(SizeOf(TrackData))
  With *gadgetdata
    \p_region1       = h1
    \p_region2       = h3
    \baseimage       = baseimage
    \baseimagetop    = 23
    \baseimageleft   = 20
    \baseimagewidth  = width-36
    \bclientwidth    = \baseimagewidth-5
    \pointer1        = pointer1
    \pointer2        = pointer2
    \selection_start = 0
    \selection_end   = 0
    \selection_max   = max
    \tickmin         = 22
    \tickmax         = width-19
    \pointer1top     = 15
    \pointer2top     = 30
    \tickleftx       = 22
    \tickrightx      = 22
    \pointer1x       = 17
    \pointer2x       = 17
    \pointermin      = 17
    \pointermax      = width-24
    \displayfont     = LoadFont(0,"verdana", 6)
  EndWith
  
  SetGadgetData(gadgetnumber, *gadgetdata)
  *gadgetdata\baseimage = CreateImage(#PB_Any, *gadgetdata\baseimagewidth,15)
  
  StartDrawing(ImageOutput(*gadgetdata\baseimage))
    Box(0,0,*gadgetdata\baseimagewidth-1,1,GetSysColor_(#COLOR_3DSHADOW))
    Box(0,0,1,14,GetSysColor_(#COLOR_3DSHADOW))
    Box(1,1,1,12,GetSysColor_(#COLOR_3DDKSHADOW))
    Box(1,1,*gadgetdata\baseimagewidth-3,1,GetSysColor_(#COLOR_3DDKSHADOW))
    Box(2,2,*gadgetdata\baseimagewidth-4,11,GetSysColor_(#COLOR_3DHIGHLIGHT))
    Box(1,13,*gadgetdata\baseimagewidth-3,1,GetSysColor_(#COLOR_3DFACE))
    Box(0,14,*gadgetdata\baseimagewidth-1,1,GetSysColor_(#COLOR_3DHIGHLIGHT))
    Box(*gadgetdata\baseimagewidth-2,1,1,13,GetSysColor_(#COLOR_3DFACE))
    Box(*gadgetdata\baseimagewidth-1,0,1,15,GetSysColor_(#COLOR_3DHIGHLIGHT))
  StopDrawing()
  
  RedrawTrackSelectionGadget(gadgetnumber)
  ProcedureReturn result
EndProcedure

ProcedureDLL GetTrackSelectionStart(gadget)
  *p.TrackData = GetGadgetData(gadget)
  ProcedureReturn *p\selection_start
EndProcedure

ProcedureDLL GetTrackSelectionEnd(gadget)
  *p.TrackData = GetGadgetData(gadget)
  ProcedureReturn *p\selection_end
EndProcedure

ProcedureDLL CheckSelectionStartChanged(gadget)
  *p.TrackData = GetGadgetData(gadget)
  If *p\startchanged
    *p\startchanged=0
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

ProcedureDLL CheckSelectionEndChanged(gadget)
  *p.TrackData = GetGadgetData(gadget)
  If *p\endchanged
    *p\endchanged=0
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

ProcedureDLL HandleTrackEvents(EventGadget,EventType)
  Static hot1, hot2, xoffset
  *p.TrackData = GetGadgetData(EventGadget)
  mx = GetGadgetAttribute(EventGadget,#PB_Canvas_MouseX)
  my = GetGadgetAttribute(EventGadget,#PB_Canvas_MouseY)
  
  Select EventType
      ;       
    Case #PB_EventType_KeyDown
      key = GetGadgetAttribute(EventGadget, #PB_Canvas_Key)
      mods = GetGadgetAttribute(EventGadget, #PB_Canvas_Modifiers)
      Select key
        Case #PB_Shortcut_Right
          If mods & #PB_Canvas_Shift
            *p\pointer1x = *p\tickleftx-5
            If *P\tickleftx < *p\tickmax
              *p\tickleftx+1
              *p\pointer1x+1
              If *p\tickrightx < *p\tickleftx
                *p\tickrightx = *p\tickleftx
                *p\pointer2x = *p\tickrightx-5
              EndIf
            EndIf
            s.d = Round(((*p\tickleftx-*p\tickmin)/*p\bclientwidth)  * *p\selection_max, #PB_Round_Nearest)
            *p\selection_start = Int(s)
            *P\startchanged = 1
            If *p\selection_start > *p\selection_end
              *p\selection_end = *p\selection_start
              *p\endchanged = 1
            EndIf                 
            RedrawTrackSelectionGadget(EventGadget)
          Else
            *p\pointer2x = *p\tickrightx-5
            If *p\tickrightx < *p\tickmax
              *p\tickrightx+1
              *p\pointer2x+1
            EndIf
            e.d = Round(((*p\tickrightx-*p\tickmin)/*p\bclientwidth) * *p\selection_max, #PB_Round_Nearest)
            *p\selection_end = Int(e)
            *p\endchanged = 1
            RedrawTrackSelectionGadget(EventGadget)
          EndIf
          
        Case #PB_Shortcut_Left
          If mods & #PB_Canvas_Shift
            *p\pointer1x = *p\tickleftx-5
            If *p\tickleftx > *p\tickmin
              *p\tickleftx-1
              *p\pointer1x-1
            EndIf
            s.d = Round(((*p\tickleftx-*p\tickmin)/*p\bclientwidth)  * *p\selection_max, #PB_Round_Nearest)
            *p\selection_start = Int(s)
            *P\startchanged = 1
            RedrawTrackSelectionGadget(EventGadget)
          Else
            *p\pointer2x = *p\tickrightx-5
            If *p\tickrightx > *p\tickmin
              *p\tickrightx-1
              *p\pointer2x-1
              If *p\tickleftx > *p\tickrightx
                *p\tickleftx = *p\tickrightx
                *p\pointer1x = *p\tickleftx-5
              EndIf
            EndIf
            e.d = Round(((*p\tickrightx-*p\tickmin)/*p\bclientwidth) * *p\selection_max, #PB_Round_Nearest)
            *p\selection_end = Int(e)
            *p\endchanged = 1
            If *p\selection_end < *p\selection_start
              *p\selection_start = *p\selection_end
              *p\startchanged = 1
            EndIf                 
            RedrawTrackSelectionGadget(EventGadget)
          EndIf
          
      EndSelect
      
    Case #PB_EventType_LeftButtonDown
      
      If mx <= *p\tickrightx And mx >= *p\tickmin And (my <= 26)
        *p\pointer1x = mx-5
        If *p\pointer1x < *p\pointermin
          *p\pointer1x = *p\pointermin
        EndIf
        *p\tickleftx = *p\pointer1x+5
        s.d = Round(((*p\tickleftx-*p\tickmin)/*p\bclientwidth)  * *p\selection_max, #PB_Round_Nearest)
        *p\selection_start = Int(s)
        *P\startchanged = 1
        hot1 = #True : #hot2 = #False
        RedrawTrackSelectionGadget(EventGadget)
      ElseIf mx >= *p\tickleftx And mx <=*p\tickmax And (my >= 28)
        *p\pointer2x = mx-5
        If *p\pointer2x > *p\pointermax
          *p\pointer2x = *p\pointermax
        EndIf
        *p\tickrightx = *p\pointer2x+5
        e.d = Round(((*p\tickrightx-*p\tickmin)/*p\bclientwidth) * *p\selection_max, #PB_Round_Nearest)
        *p\selection_end = Int(e)
        *p\endchanged = 1
        hot2 = #True : hot1 = #False
        RedrawTrackSelectionGadget(EventGadget)
      EndIf
      
    Case #PB_EventType_MouseWheel
      delta = GetGadgetAttribute(EventGadget, #PB_Canvas_WheelDelta)
      If PtInRegion_(*p\p_region2, mx-*p\pointer2x, my-*p\pointer2top)
        If delta>0
          thisone = *p\selection_end
          e.d = Round(((*p\tickrightx+1-*p\tickmin)/*p\bclientwidth) * *p\selection_max, #PB_Round_Nearest)
          nextone = Int(e)
          testone = thisone+1
          *p\pointer2x = *p\tickrightx-5
          If testone<nextone
            If *p\selection_end < nextone And *p\selection_end < *p\selection_max
              *p\selection_end+1
              *p\endchanged = 1
              RedrawTrackSelectionGadget(EventGadget)
            EndIf
          EndIf
        ElseIf delta < 0
          If *p\pointer2x = *p\tickrightx-5
            thisone = *p\selection_end
            e.d = Round(((*p\tickrightx-1-*p\tickmin)/*p\bclientwidth) * *p\selection_max, #PB_Round_Nearest)
            nextone = Int(e)
            testone = thisone-1
            *p\pointer2x = *p\tickrightx-5
            If testone>nextone
              If *p\selection_end > nextone And *p\selection_end > *p\selection_start
                *p\selection_end-1
                *p\endchanged = 1
                RedrawTrackSelectionGadget(EventGadget)
              EndIf
            EndIf
          EndIf
        EndIf
      ElseIf PtInRegion_(*p\p_region1, mx-*p\pointer1x, my-*p\pointer1top)
        If delta > 0
          thisone = *p\selection_start
          s.d = Round(((*p\tickleftx+1-*p\tickmin)/*p\bclientwidth)  * *p\selection_max, #PB_Round_Nearest)
          nextone = Int(s)
          testone = thisone+1
          *p\pointer1x = *p\tickleftx-5
          If testone>0
            If testone<nextone
              If *p\selection_start < nextone And *p\selection_start < *p\selection_end
                *p\selection_start+1
                *P\startchanged = 1
                RedrawTrackSelectionGadget(EventGadget)
              EndIf
            EndIf
          EndIf
        ElseIf delta < 0
          thisone = *p\selection_start
          s.d = Round(((*p\tickleftx-1-*p\tickmin)/*p\bclientwidth)  * *p\selection_max, #PB_Round_Nearest)
          nextone = Int(s)
          testone = thisone-1
          *p\pointer1x = *p\tickleftx-5
          If testone>=0
            If testone>nextone
              If *p\selection_start > nextone And *p\selection_start > 0
                *p\selection_start-1
                *P\startchanged = 1
                RedrawTrackSelectionGadget(EventGadget)
              EndIf
            EndIf
          EndIf
        EndIf         
      EndIf
      
    Case #PB_EventType_LeftButtonUp
      hot1 = #False
      hot2 = #False
      
    Case #PB_EventType_MouseMove
      buttonstate = GetGadgetAttribute(EventGadget, #PB_Canvas_Buttons)
      lbutton = buttonstate & #PB_Canvas_LeftButton
      If lbutton
        If hot1
          *p\pointer1x = mx-xoffset
          If *p\pointer1x < *p\pointermin
            *p\pointer1x = *p\pointermin
          ElseIf *p\pointer1x > *p\pointermax
            *p\pointer1x = *p\pointermax
          EndIf
          *p\tickleftx = *p\pointer1x+5
          If *p\tickrightx < *p\tickleftx
            *p\tickrightx = *p\tickleftx
            *p\pointer2x = *p\tickrightx-5
          EndIf
          s.d = Round(((*p\tickleftx-*p\tickmin)/*p\bclientwidth)  * *p\selection_max, #PB_Round_Nearest)
          *p\selection_start = Int(s)
          *P\startchanged = 1
          If *p\selection_start > *p\selection_end
            *p\selection_end = *p\selection_start
            *p\endchanged = 1
          EndIf
          RedrawTrackSelectionGadget(EventGadget)
          
        ElseIf hot2
          *p\pointer2x = mx-xOffset
          If *p\pointer2x < *p\pointermin
            *p\pointer2x = *p\pointermin
          ElseIf *p\pointer2x > *p\pointermax
            *p\pointer2x = *p\pointermax
          EndIf         
          *p\tickrightx = *p\pointer2x+5
          If *p\tickleftx > *p\tickrightx
            *p\tickleftx = *p\tickrightx
            *p\pointer1x = *p\tickleftx-5
          EndIf
          e.d = Round(((*p\tickrightx-*p\tickmin)/*p\bclientwidth) * *p\selection_max, #PB_Round_Nearest)
          *p\selection_end   = Int(e)
          *p\endchanged = 1
          If *p\selection_end < *p\selection_start
            *p\selection_start = *p\selection_end
            *p\startchanged = 1
          EndIf
        EndIf
        RedrawTrackSelectionGadget(EventGadget)
      Else
        If PtInRegion_(*p\p_region1, mx-*p\pointer1x, my-*p\pointer1top)
          SetGadgetAttribute(EventGadget, #PB_Canvas_Cursor,#PB_Cursor_Hand)
          hot1 = #True : hot2 = #False
          xOffset = mx-*p\pointer1x
        ElseIf PtInRegion_(*p\p_region2, mx-*p\pointer2x, my-*p\pointer2top)
          SetGadgetAttribute(EventGadget, #PB_Canvas_Cursor,#PB_Cursor_Hand)
          hot2 = #True : hot1 = #False
          xOffset = mx-*p\pointer2x
        Else
          hot1=#False : hot2 = #False
          SetGadgetAttribute(EventGadget, #PB_Canvas_Cursor,#PB_Cursor_Default)
        EndIf
      EndIf
      
  EndSelect
  
EndProcedure

;========================================================
;                    End of Library Code
;========================================================

; Test program

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ButtonGadget(0,20,20,100,20,"Button")
TrackSelectGadget(1,20,360,600,0,20129,1)

Repeat
  ev = WaitWindowEvent()
  Select ev
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          HandleTrackEvents(EventGadget(), EventType())
      EndSelect
  EndSelect
Until ev = #PB_Event_CloseWindow
@Edit: Updated the CreateImage() call.
Last edited by Demivec on Thu Jan 21, 2016 1:51 am, edited 1 time in total.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Trackbar Gadget with two slider

Post by Lord »

Hi Hemivec!

Sorry, but this is not what I have in mind.
This TrackbarGadget has a fixed height and you can't
start with a value other than '0'. The parameter 'min'
in TrackSelectGadget() is never used.
Image
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Trackbar Gadget with two slider

Post by davido »

@Demivec,

On Windows 10 PureBasic 5.41LTS the code crashed on line 53.
I had to change it to:

Code: Select all

 ptr = CreateImage(#PB_Any, 11,30,32,#PB_Image_Transparent)
to get it to work.
Is this ok?

It is a shame it does not meet Lord's requirements. However, I think its excellent.
Thank you for sharing.
DE AA EB
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Trackbar Gadget with two slider

Post by Demivec »

Lord wrote:Hi Hemivec!

Sorry, but this is not what I have in mind.
@Hord: Sorry to hear that it doesn't match what you were looking for.

I know this next example doesn't quite meet your posted requirements but it is a viable option that may be of use to someone else . I am sharing a link to it just for completeness. It is by einander.
davido wrote:I had to change it to:
 

Code: Select all

ptr = CreateImage(#PB_Any, 11,30,32,#PB_Image_Transparent)
to get it to work.
Is this ok?
@davido: Yes, that is definitely OK. I had overlooked that needed correction because I didn't receive a syntax error. I copied your correction into the code I posted earlier.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Trackbar Gadget with two slider

Post by Lord »

Hello Demivec!

May I reply for "Hord"? :wink:

Your last recommended code by einander also has
some drawbacks und is still not that piece of code
that I have in mind.

Einanders trackbar doesn't also accept a starting value
of 1 ore more and the end slider leaves the bar.
Just try

Code: Select all

InitDSlid(0,100,100,iWi,300,2,32,0,#Red,8,24)
for example and drag the sliders to their outer sides.
Last edited by Lord on Fri Jan 22, 2016 9:27 am, edited 1 time in total.
Image
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Trackbar Gadget with two slider

Post by Demivec »

Lord wrote:Einanders trackbar doesn't also accept a starting value
of 1 ore more and the end slider leaves the bar.
Just try

Code: Select all

InitDSlid(0,100,100,iWi,300,2,32,0,#Red,8,24)
for example and drag the sliders to their outer sides.
@Lord: Those are indeed some notable drawbacks. The code seemed more robust at first glance. :oops:

I don't know of any other code references or examples that are related to your target. Hopefully some of the examples given may be close enough to rewrite to meet your particular needs.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Trackbar Gadget with two slider

Post by Lord »

Hi Demivec again!

Thank you for your effords to help.

I think, there is a chance for getting a code matching my needs.
Rashad issued a promising example for a double slider trackbar:
http://www.purebasic.fr/english/viewtop ... 12&t=64651

It still has some drawbacks, but I will have a closer look.

Thanks to all helping hands.

(But I'm still wondering, where I saw the Trackbar with two slider)
Image
Post Reply