Changing TrackBarGadget behaviour

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Changing TrackBarGadget behaviour

Post by Lebostein »

Is it possible to change the TrackBarGadget behaviour for Windows in that way, that the position slider jumps exakt at the position I click on the bar? At the moment It seems the trackbar is splited in 5 to 7 "pages" and if I click on the bar the slider moves to the next "page" only in the direction of the mouse pointer. Very strange for some uses.

With Mac OS I hove not this problem. The slider jumps exactly to the mouse pointer if I click on the bar....
User avatar
Shardik
Addict
Addict
Posts: 1988
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Changing TrackBarGadget behaviour

Post by Shardik »

Have you already tried out hjbremer's example in the German forum?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Changing TrackBarGadget behaviour

Post by Dude »

Thanks for the link, Shardik. Saved for the future because I know I'll need it one day. :)
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Changing TrackBarGadget behaviour

Post by Lebostein »

Thanks, it works, but very laggy and unprecies. Are there other Gadgets from the API they can Do that? This page wise behaviour is useful for scrollbars, but not for trackbars in my eyes. Maybe IT could help to overwrite that huge page size value....
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4635
Joined: Sun Apr 12, 2009 6:27 am

Re: Changing TrackBarGadget behaviour

Post by RASHAD »

See if that of any help

Code: Select all

#TBS_TOOLTIPS = $100
  
  If OpenWindow(0, 0, 0, 320, 200, "TrackBarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget    (3, 10,  20, 250, 20,"TrackBar Standard", #PB_Text_Center)
    TrackBarGadget(0, 10,  40, 300,50, 0, 30,#PB_TrackBar_Ticks|#TBS_TOOLTIPS |#TBS_FIXEDLENGTH )
    SetGadgetState(0, 15)
    SendMessage_(GadgetID(0), #TBM_SETTHUMBLENGTH,25,0)
    SendMessage_(GadgetID(0), #TBM_SETPAGESIZE ,0,1)
    
 Repeat
    Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
        Quit = 1
        
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            If  GetAsyncKeyState_(#VK_LBUTTON)
              GetCursorPos_ (@p.POINT) 
              ScreenToClient_ (GadgetID(0), @p)
              SetGadgetState(0, (p\x-13)/9)   ; 9 = (GadgetWidth - 40)/Maximum State
            EndIf
        EndSelect
        
              

  EndSelect    
 Until Quit = 1
  EndIf
Edit : Copy & Paste bugs :)
Egypt my love
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Changing TrackBarGadget behaviour

Post by Lebostein »

Thanks! Works very well! :D

Here is the condensed version. Works with every GadgetWidth and any maximum value (minimum = 0):

Code: Select all

#Trackbar = 0
#dist_L = 12 ; measured on Windows 10
#dist_R = 13 ; measured on Windows 10

OpenWindow(0, 0, 0, 320, 200, "TrackBarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TrackBarGadget(#Trackbar, 10,  40, 300,50, 0, 255)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow: Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Trackbar
          ; -----> that is the trick
          GetCursorPos_(@click.POINT)
          ScreenToClient_(GadgetID(#Trackbar), @click)
          pos = Round((click\x - #dist_L) / (GadgetWidth(#Trackbar) - #dist_L - #dist_R) * GetGadgetAttribute(#Trackbar, #PB_TrackBar_Maximum), #PB_Round_Nearest)
          SetGadgetState(#Trackbar, pos)
          ; <----- end of trick
      EndSelect
  EndSelect   
ForEver
Post Reply