Page 1 of 1
Wrapping SpinGadget with optional text.
Posted: Mon Jan 19, 2009 2:45 am
by einander
Code: Select all
;by einander
;january 19-2009
;PB 4.30
Procedure SpinWrap(SG,EvTyp, ARRAY Arr.s(1))
Static Value
Select EvTyp
Case 1
If Value=GetGadgetAttribute(SG,#PB_Spin_Maximum)
SetGadgetState(SG,GetGadgetAttribute(SG,#PB_Spin_Minimum))
EndIf
Case -1
If Value = GetGadgetAttribute(SG,#PB_Spin_Minimum)
SetGadgetState(SG,GetGadgetAttribute(SG,#PB_Spin_Maximum))
EndIf
EndSelect
If ArraySize(Arr())
SetGadgetText(SG, Arr(GetGadgetState(SG)))
Else
SetGadgetText(SG, Str(GetGadgetState(SG)))
EndIf
Value=GetGadgetState(SG)
EndProcedure
;<<<<<<<<<<<<<<<<<<<
; test it
If OpenWindow(0, 200,200,300,100, "SpinWrap", #PB_Window_SystemMenu | 1 )
StickyWindow(0,1)
SG=SpinGadget(#PB_Any, 40, 10, 100, 25, 0, 4)
SetGadgetState (SG, 2)
;==============
; To wrap numbers (without text), Dim SpinArr.s(0)
Dim SpinArr.s(4)
SpinArr(0)="Zero"
SpinArr(1)="One"
SpinArr(2)="Two"
SpinArr(3)="Three"
SpinArr(4)="Four"
SetGadgetText(SG,SpinArr(GetGadgetState(SG)))
;=============
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = SG
SpinWrap(SG,EventType(),SpinArr() )
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Cheers
Posted: Mon Jan 19, 2009 11:41 am
by Kwai chang caine
Cool and funny this idea
Thanks for sharing

Posted: Mon Jan 19, 2009 12:18 pm
by Psychophanta
Useful when there are lots of states, and it is also portable!
Salut! Roberto. Still waiting to see your newest versions of midi keyboard...

Posted: Tue Jan 20, 2009 7:14 pm
by einander
Thanks and salut!
I Can't found the old MidiKeyboard on my disks; probably is buried under a pile of CDs, so I've download it from the Forum.
I'm making a revamp, and I'll upload it soon.
Posted: Tue Jan 20, 2009 9:05 pm
by akj
@einander:
I think there is a bugette in your Procedure SpinWrap() in that
should be
Posted: Wed Jan 21, 2009 12:09 am
by einander
Thanks AKJ.
I've forgot to check the return value for the new PB command ArraySize() when i've replaced my custom ArraySize(), that returns the number of elements.
Now the code is updated.
Here is a better variant with a structure, to use more than one SpinGadget simultaneously.
Code: Select all
#nElements1=5
Structure SpinWrap
SpinNum.i
nElements.l
Arr.s[#nElements1]
Value.i
EndStructure
Procedure SpinWrap(*SP.SpinWrap)
With *SP
Select EventType()
Case 1
If \Value=GetGadgetAttribute(\SpinNum,#PB_Spin_Maximum)
SetGadgetState(\SpinNum,GetGadgetAttribute(\SpinNum,#PB_Spin_Minimum))
EndIf
Case -1
If \Value = GetGadgetAttribute(\SpinNum,#PB_Spin_Minimum)
SetGadgetState(\SpinNum,GetGadgetAttribute(\SpinNum,#PB_Spin_Maximum))
EndIf
EndSelect
If \nElements : SetGadgetText(\SpinNum, \Arr[GetGadgetState(\SpinNum)])
Else : SetGadgetText(\SpinNum, Str(GetGadgetState(\SpinNum)))
EndIf
\Value=GetGadgetState(\SpinNum)
EndWith
EndProcedure
;<<<<<<<<<<<<<<<<<<<
; test it
If OpenWindow(0, 200,200,300,300, "SpinWrap", #PB_Window_SystemMenu | 1 )
StickyWindow(0,1)
SW1.SpinWrap
SW1\SpinNum=SpinGadget(#PB_Any, 40, 10, 100, 25, 0, 4)
SW1\nElements=#nElements1
SetGadgetState (SW1\SpinNum, 2) ; initial value
SW1\Arr[0]="Zero"
SW1\Arr[1]="One"
SW1\Arr[2]="Two"
SW1\Arr[3]="Three"
SW1\Arr[4]="Four"
SetGadgetText(SW1\SpinNum,SW1\Arr[GetGadgetState(SW1\SpinNum)])
;------------
SW2.SpinWrap ; ignore the array to wrap only numbers
SW2\SpinNum=SpinGadget(#PB_Any, 40, 50, 50, 25, 1,10)
SetGadgetState (SW2\SpinNum, 8) ; initial Value
SetGadgetText(SW2\SpinNum,Str(GetGadgetState(SW2\SpinNum)))
;
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case SW1\SpinNum : SpinWrap(SW1 )
Case SW2\SpinNum : SpinWrap(SW2 )
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf