SpinGadget

Just starting out? Need help? Post your questions and find answers here.
Realizimo
User
User
Posts: 74
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

SpinGadget

Post by Realizimo »

hello!
Is it possible to only visit the routine "test()" once for each click instead of twice.
And is it possible to make the blue background behind the numbers to disappear.

Code: Select all

OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#spin=1
SpinGadget     (#spin, 20, 20, 100, 25, 0, 1000, #PB_Spin_Numeric)
SetGadgetState (#spin, 555) 

Procedure test()
  Debug GetGadgetState(#spin)
EndProcedure

BindGadgetEvent(#spin, @test())

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: SpinGadget

Post by RASHAD »

Hi

Code: Select all

OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#spin=1
SpinGadget     (#spin, 20, 20, 100, 25, 0, 1000, #PB_Spin_Numeric)
SetGadgetState (#spin, 555) 

Procedure test()
  Debug GetGadgetState(#spin)
  SetActiveGadget(-1)
EndProcedure

BindGadgetEvent(#spin, @test(),#PB_EventType_Change)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Egypt my love
Realizimo
User
User
Posts: 74
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: SpinGadget

Post by Realizimo »

wonderfully
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SpinGadget

Post by ChrisR »

Same as Rashad, while maintaining focus when entering the number

Code: Select all

OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
#spin=1
SpinGadget     (#spin, 20, 20, 100, 25, 0, 1000, #PB_Spin_Numeric)
SetGadgetState (#spin, 555) 

Procedure test()
  If EventType() = #PB_EventType_Change
    Debug GetGadgetState(#spin)
  Else
    SetActiveGadget(-1)
  EndIf
EndProcedure

BindGadgetEvent(#spin, @test())

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Realizimo
User
User
Posts: 74
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: SpinGadget

Post by Realizimo »

Is this the best way if I want to use the arrow keys?

Code: Select all

#win=1
#spin1=1
#spin2=2
OpenWindow(#win, 0, 0, 140, 120, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

SpinGadget     (#spin1, 20, 20, 100, 25, 0, 1000,#PB_Spin_Numeric)
SpinGadget     (#spin2, 20, 60, 100, 25, 0, 1000,#PB_Spin_Numeric)
SetGadgetState (#spin1, 555)
SetGadgetState (#spin2, 555) 
AddKeyboardShortcut(#win,#PB_Shortcut_Down,1)
AddKeyboardShortcut(#win,#PB_Shortcut_Up,3)

Global prevgad=1
Procedure test()
  If EventType() = #PB_EventType_Change
    prevgad=EventGadget()
    Debug GetGadgetState(prevgad)
  Else : SetActiveGadget(-1)
  EndIf
EndProcedure

Procedure key()
  If GetActiveGadget()>-1:prevgad=GetActiveGadget():EndIf
  SetGadgetState(prevgad, GetGadgetState(prevgad)+EventMenu()-2)
  PostEvent(#PB_Event_Gadget,#win,prevgad,#PB_EventType_Change)
EndProcedure

BindGadgetEvent(#spin1, @test())
BindGadgetEvent(#spin2, @test())
BindEvent(#PB_Event_Menu, @key(),#win,1)
BindEvent(#PB_Event_Menu, @key(),#win,3)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 486
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: SpinGadget

Post by Mindphazer »

I'd say yes, but :
This is much simpler

Code: Select all

#win=1
#spin1=1
#spin2=2
OpenWindow(#win, 0, 0, 140, 120, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

SpinGadget     (#spin1, 20, 20, 100, 25, 0, 1000,#PB_Spin_Numeric)
SpinGadget     (#spin2, 20, 60, 100, 25, 0, 1000,#PB_Spin_Numeric)
SetGadgetState (#spin1, 555)
SetGadgetState (#spin2, 555) 
AddKeyboardShortcut(#win,#PB_Shortcut_Down,1)
AddKeyboardShortcut(#win,#PB_Shortcut_Up,3)


Procedure key()

  Gadget = GetActiveGadget()
  If Gadget <> -1
    Select EventMenu()
      Case 1
        SetGadgetState(Gadget, GetGadgetState(Gadget) - 1)
      Case 3
        SetGadgetState(Gadget, GetGadgetState(Gadget) + 1)
    EndSelect
    
  EndIf
  
EndProcedure

BindEvent(#PB_Event_Menu, @key(),#win,1)
BindEvent(#PB_Event_Menu, @key(),#win,3)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
And only the gadget which has the focus is modified
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply