Page 1 of 1

Posted: Fri Jun 21, 2002 6:46 pm
by BackupUser
Restored from previous forum. Originally posted by ebs.

What is the proper use of the SpinGadget? It looks like EventType() returns -/+ 1, depending on whether you click the up or down arrow. I assume that the gadget state and text have to be set by my code, right? If so, how should the Minumum and Maximum values be used?

Here's my code:

#Spin1 = 15
Declare Spin1_Click(SpinValue.l)
:
:
:
SpinGadget(#Spin1, 230, 400, 40, 20, 0, 100)
SetGadgetState(#Spin1, 0)
SetGadgetText(#Spin1, "0")
:
:
:
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case #Button1
If EventType() = #PB_EventType_LeftClick
Button1_Click()
EndIf
Case #Button2
If EventType() = #PB_EventType_LeftClick
Button2_Click()
EndIf
Case #Spin1
Spin1_Click(EventType())
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
:
:
:
Procedure Spin1_Click(SpinValue.l)
NewValue.l = GetGadgetState(#Spin1) - SpinValue
SetGadgetState(#Spin1, NewValue)
SetGadgetText(#Spin1, Str(NewValue))
EndProcedure

When I run this and click once, the value increments continuously up to 101. It seems like I keep generating window events each time I call SetGadgetState() or SetGadgetText(). What am I doing wrong?

Thanks to everybody for all your help!

Regards,
Eric

Posted: Fri Jun 21, 2002 7:32 pm
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Code: Select all

Procedure Spin1_Click(SpinValue.l)
  NewValue.l = GetGadgetState(#Spin1) - SpinValue
  SetGadgetState(#Spin1, NewValue)
  SetGadgetText(#Spin1, Str(NewValue))


  While WindowEvent():Wend


EndProcedure
Does this work for you ??

Better (and right) is to check the
EventType for the SpinGadget:

Code: Select all

Case #Spin1
If EventType() = #PB_EventType_LeftClick
   Spin1_Click(EventType())
Endif
[...]
So the Procedure runs not every time
a Message comes in, but when a message
comes in and the MouseButton is pressed.

cya,
...Danilo

(registered PureBasic user)

Posted: Fri Jun 21, 2002 8:02 pm
by BackupUser
Restored from previous forum. Originally posted by ebs.

Danilo,

I tried that, but the EventType() value for the SpinGadget isn't #PB_EventType_LeftClick. As I said, it seems to be +/- 1, depending on which arrow button you click. There must be two different values so you can distinguish between the two arrow buttons.

Using the "While/Wend" loop eliminates the continuous increment, but the value in the SpinGadget still doesn't track correctly.

FRED - if you're listening, please give me an example of the RIGHT way to use this!

Thanks,
Eric

Code: Select all

Procedure Spin1_Click(SpinValue.l)
  NewValue.l = GetGadgetState(#Spin1) - SpinValue
  SetGadgetState(#Spin1, NewValue)
  SetGadgetText(#Spin1, Str(NewValue))


  While WindowEvent():Wend


EndProcedure
Does this work for you ??

Better (and right) is to check the
EventType for the SpinGadget:

Code: Select all

Case #Spin1
If EventType() = #PB_EventType_LeftClick
   Spin1_Click(EventType())
Endif
[...]
So the Procedure runs not every time
a Message comes in, but when a message
comes in and the MouseButton is pressed.

cya,
...Danilo

(registered PureBasic user)

Posted: Fri Jun 21, 2002 8:48 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> What is the proper use of the SpinGadget?

You use it like this:

Code: Select all

If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  SpinGadget(1,20,20,100,20,1,10)
  SetGadgetState(1,5) : SetGadgetText(1,"5") ; Set initial value.
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_EventGadget
      SetGadgetText(1,Str(GetGadgetState(1)))
      WindowEvent() ; To stop looping events due to text change.
    EndIf
  Until ev=#PB_EventCloseWindow
EndIf

PB - Registered PureBasic Coder

Posted: Fri Jun 21, 2002 9:39 pm
by BackupUser
Restored from previous forum. Originally posted by ebs.

PB,

Thank you! How do you know all this stuff - is there some secret documentation I can get my hands on???

One last question: Doesn't it seem backwards for the down arrow to increment the control value? Wouldn't it make more sense the other way around? I get around it by swapping the Maximum and Minimum values, but it still seems backwards.

I continue to be amazed at the amount of knowledge here, and that I can take advantage of it simply by asking!

Thanks again,
Eric

> What is the proper use of the SpinGadget?

You use it like this:

Code: Select all

If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  SpinGadget(1,20,20,100,20,1,10)
  SetGadgetState(1,5) : SetGadgetText(1,"5") ; Set initial value.
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_EventGadget
      SetGadgetText(1,Str(GetGadgetState(1)))
      WindowEvent() ; To stop looping events due to text change.
    EndIf
  Until ev=#PB_EventCloseWindow
EndIf

PB - Registered PureBasic Coder

Posted: Fri Jun 21, 2002 10:17 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> How do you know all this stuff

Lots of years of programming!

> is there some secret documentation I can get my hands on???

Not directly for PureBasic, but any web documentation on the Win32 API can be
used by PureBasic, although it's not really easy for beginners to learn.

> One last question: Doesn't it seem backwards for the down arrow to increment
> the control value? Wouldn't it make more sense the other way around?

Yes, by default it should increase on the up-arrow just like other Windows apps.
Fred, you reading?

PB - Registered PureBasic Coder

Posted: Sat Jun 22, 2002 10:44 am
by BackupUser
Restored from previous forum. Originally posted by fred.

You're right . BTW, I will fix this SetSpinGadget() stuff. The EVentType() is +1/-1 but it's the numlber of increase, very useful. If you let the button pushed a long time, it will increase from +1/-1 to +5/-5.

Fred - AlphaSND