It is currently Sat Mar 06, 2021 6:53 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 12:52 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Aug 28, 2019 1:01 pm
Posts: 120
Hi all,

I added the track bar gadget to my program, and noticed that it doesn't appear to send #pb_eventType_change, so I'm curious what's the best way to go about checking for changes?
I could always store the previous result of GetGadgetStatus and compare it in the loop, but there must be a better way?

Code:
EnableExplicit
OpenWindow(0, #PB_IGNORE, #PB_IGNORE, #PB_IGNORE, #PB_IGNORE, "test", #PB_Window_ScreenCentered|#PB_Window_Maximize)
TrackBarGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0, 100, #PB_TrackBar_Vertical)
;SpinGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0, 100, #PB_Spin_Numeric)

Repeat
Define e=WaitWindowEvent()
If e=#PB_Event_Gadget And EventType()=#PB_EventType_Change
SetWindowTitle(0, ""+GetGadgetState(0))
EndIf
Until e=#PB_Event_CloseWindow


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 1:04 pm 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1333
nsstudios wrote:
I could always store the previous result of GetGadgetStatus and compare it in the loop

That's the only way at the moment. I don't use TrackBars much, so I'm surprised that #PB_EventType_Change can't be used with them. You should post this in the Wishlist section of the forum.


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 1:12 pm 
Offline
User
User

Joined: Sun Nov 26, 2017 3:13 pm
Posts: 39
Code:
If e=#PB_Event_Gadget And EventType()=#PB_EventType_LeftClick


Peter


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 1:34 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3884
Hi
There is no such EventType() for the TrackBarGadget()
Read the manual please
Code:
OpenWindow(0, 0,0,800,600, "test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TrackBarGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0, 100, #PB_TrackBar_Vertical)
;SpinGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0, 100, #PB_Spin_Numeric)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          SetWindowTitle(0, "Thump at : "+GetGadgetState(0))
      EndSelect
  EndSelect
Until Quit = 1

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 1:42 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2439
Location: Singapore
nsstudios wrote:
...added the track bar gadget to my program, and noticed that it doesn't appear to send #pb_eventType_change, so I'm curious what's the best way to go about checking for changes? ...

Try something like this:
Code:
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 600, 400, "TrackBar 1 = 0", wFlags)
TrackBarGadget(0, 0, 0, 50, 400, 0, 100, #PB_TrackBar_Vertical)
TrackBarGadget(1, 60, 0, 50, 400, 0, 100, #PB_TrackBar_Vertical)
TextGadget(2, 120, 10, 460, 50, "TrackBar 2 = 0", #PB_Text_Right)

Repeat
 
  Select WaitWindowEvent()
     
    Case #PB_Event_CloseWindow
      appQuit = #True
     
    Case #PB_Event_Gadget       
      Select EventGadget()
         
        Case 0
          SetWindowTitle(0, "TrackBar 1 = " + GetGadgetState(0))
         
        Case 1
          SetGadgetText(2, "TrackBar 2 = " + GetGadgetState(1))
         
      EndSelect
     
  EndSelect
 
Until appQuit

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 2:43 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Aug 28, 2019 1:01 pm
Posts: 120
Wow, thank you all for the help.
I totally forgot to try and see what I get when catching any event at all.
It's interesting that it fires left click instead of change,and even more so that it fires it twice for every change.


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 2:50 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3884
You are checking if Change just happened
There is a hack using CanvasGadget() by Danilo
Search the forum for it if you like more options
No need for LeftClick twice
Try the next
Code:
OpenWindow(0, 0,0,800,600, "test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TrackBarGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0, 100, #PB_TrackBar_Vertical)
;SpinGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0, 100, #PB_Spin_Numeric)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
       
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          pos = DesktopMouseY()
          SetWindowTitle(0, "Thump at : "+GetGadgetState(0))
          Delay(10)
          If DesktopMouseY() <> pos
            Debug  "Position changed from :"+ pos +" to "+DesktopMouseY()
          EndIf

      EndSelect
  EndSelect
Until Quit = 1

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 3:35 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Aug 28, 2019 1:01 pm
Posts: 120
Perhaps I was unclear.
When I change the track bar gadget once (one press of up/down arrow), it fires the left click event twice, which isn't a problem for the situation I need it for in my program, but could maybe be problematic in other cases.

Code:
EnableExplicit
OpenWindow(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, "test", #PB_Window_ScreenCentered|#PB_Window_Maximize)
TrackBarGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0, 100, #PB_TrackBar_Vertical)
Define count=0

Repeat
Define e=WaitWindowEvent()
If e=#PB_Event_Gadget And EventGadget()=0 And EventType()=#PB_EventType_LeftClick
count+1
SetWindowTitle(0, "("+count+")"+GetGadgetState(0))
EndIf
Until e=#PB_Event_CloseWindow


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 5:03 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2887
Location: Germany
Save last position in gadget data...
Code:

Procedure DoEventTrackBar()
  Protected gadget = EventGadget()
  Protected position = GetGadgetState(gadget)
  Select EventType()
    Case #PB_EventType_LeftClick
      If position <> GetGadgetData(gadget)
        SetGadgetData(gadget, position)
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), gadget, #PB_EventType_Change, position)
      EndIf
  EndSelect
EndProcedure


wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 600, 400, "TrackBar 1 = 0", wFlags)
TrackBarGadget(0, 0, 0, 50, 400, 0, 100, #PB_TrackBar_Vertical)
TrackBarGadget(1, 60, 0, 50, 400, 0, 100, #PB_TrackBar_Vertical)
TextGadget(2, 120, 10, 460, 50, "TrackBar 2 = 0", #PB_Text_Right)

BindGadgetEvent(0, @DoEventTrackBar())
BindGadgetEvent(1, @DoEventTrackBar())


Repeat
 
  Select WaitWindowEvent()
     
    Case #PB_Event_CloseWindow
      appQuit = #True
     
    Case #PB_Event_Gadget       
      Select EventGadget()
         
        Case 0
          Select EventType()
            Case #PB_EventType_Change
              SetWindowTitle(0, "TrackBar 1 = " + GetGadgetState(0))
          EndSelect
         
        Case 1
          Select EventType()
            Case #PB_EventType_Change
              SetGadgetText(2, "TrackBar 2 = " + EventData())
          EndSelect
         
      EndSelect
     
  EndSelect
 
Until appQuit

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 5:43 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8149
Location: Fort Nelson, BC, Canada
Mon coup de pied au chat:
Code:
Macro HIWORD(val)
  val>>16
EndMacro

Macro LOWORD(val)
  val&$FFFF
EndMacro

#PB_Event_TrackbarChanged = #PB_Event_FirstCustomValue

Procedure TrackbarHandler0()
  Static oldstate.i=0
  If EventType() = #PB_EventType_LeftClick
    newstate=GetGadgetState(0)
    If Not newstate=oldstate
      statevalues.l = oldstate<<16|newstate
      PostEvent(#PB_Event_TrackbarChanged, #PB_Ignore, #PB_Ignore, #PB_Ignore, statevalues)
      oldstate=newstate
    EndIf
  EndIf
EndProcedure

Procedure TrackChangeHandler0()
  statevalues = EventData()
  oldstate = HIWORD(statevalues)
  newstate = LOWORD(statevalues)
  SetGadgetText(1, "Trackbar Old: "+oldstate)
  SetGadgetText(2, "Trackbar New: "+newstate)
EndProcedure

OpenWindow(0,0,0,320,240,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(1,10,10,120,20,"Trackbar Old: 0")
TextGadget(2,140,10,120,20,"Trackbar New: 0")
TrackBarGadget(0, 0,215,320,20,0,1000)
BindGadgetEvent(0, @TrackbarHandler0())
BindEvent(#PB_Event_TrackbarChanged, @TrackChangeHandler0())
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

_________________
BERISHEET


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sat Mar 21, 2020 8:10 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Aug 28, 2019 1:01 pm
Posts: 120
Thanks so much for the help everyone.


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sun Mar 22, 2020 1:31 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1333
I posted this in the Wishlist section for you (and I) -> viewtopic.php?f=3&t=74922


Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Sun Mar 22, 2020 7:31 pm 
Offline
User
User

Joined: Fri Jan 31, 2020 6:48 pm
Posts: 12
Here is code to do what you want I believe

Code:
;Demo program to display value of TrackBar
;I used help file on TrackBarGadget for lines 4 to 13
;Note for a scroll bar if you want to display its value while scolling
;you need To Bindevent because there are no events while scolling

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, 250, 20, 0, 10000)
  SetGadgetState(0, 5000)
  TextGadget    (4, 10, 100, 250, 20, "TrackBar Ticks", #PB_Text_Center)
  TrackBarGadget(1, 10, 120, 250, 20, 0, 5, #PB_TrackBar_Ticks)
  SetGadgetState(1, 3)
  TextGadget    (5,  90, 180, 200, 20, "TrackBar Vertical", #PB_Text_Right)
  TrackBarGadget(2, 270, 10, 20, 170, 0, 10000, #PB_TrackBar_Vertical)
  SetGadgetState(2, 8000)
  Repeat
    Event = WaitWindowEvent()                                 
    If Event = #PB_Event_CloseWindow
      End
    EndIf
    If event = #PB_Event_Gadget
      Select EventGadget()
        Case 1         ;add more for other gadgets as needed
          NewValue=GetGadgetState(1)             
          If NewValue<>OldValue
            Debug NewValue
            NewValueFlag=#True
            OldValue=NewValue
          Else
            NewValueFlag=#False
          EndIf
      EndSelect
    EndIf
  ForEver
EndIf
End



Top
 Profile  
Reply with quote  
 Post subject: Re: track bar gadget not working with #pb_eventType_change
PostPosted: Mon Mar 23, 2020 7:47 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Aug 28, 2019 1:01 pm
Posts: 120
Thanks.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Kwai chang caine and 42 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye