Page 1 of 1
How to know when the mousewheel has stoped?
Posted: Thu Sep 24, 2020 11:26 pm
by AMpos
Hi!
I have an image program.
Currently in my program, the MouseWheel draws a "zoom box", but I want to "expand" it as soon as the user stop "wheeling" (to avoid expanding after every wheel move)
Test program:
Code: Select all
OpenWindow(1,0,0,400,400,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(1,10,10,380,380)
Repeat
event=WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_MouseWheel
If GetGadgetAttribute(1,#PB_Canvas_WheelDelta)<>0
Debug "Wheeling "+Str(GetGadgetAttribute(1,#PB_Canvas_WheelDelta))
Else
Debug "Stoping!"
EndIf
EndSelect
EndSelect
Until event=#PB_Event_CloseWindow
Of course, it is not working as it is, as the "debug stop" is never reached.
To resume:
Debug "wheeling" while the user is moving the wheel and debug "Stop!" when the user stop wheeling the wheel
Re: How to know when the mousewheel has stoped?
Posted: Fri Sep 25, 2020 1:53 am
by RASHAD
I think there is much elegant solution than the next
Code: Select all
OpenWindow(1,0,0,400,400,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(1,10,10,380,380)
AddWindowTimer(1,125,1000)
Repeat
event=WaitWindowEvent()
Select event
Case #PB_Event_Timer
If eflag = 1
delta = GetGadgetAttribute(1,#PB_Canvas_WheelDelta)
If delta = 0 And wflag = 1
wflag = 0
Debug "Stoping!"
EndIf
EndIf
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_MouseEnter
eflag = 1
Case #PB_EventType_MouseLeave
eflag = 0
Case #PB_EventType_MouseWheel
delta = GetGadgetAttribute(1,#PB_Canvas_WheelDelta)
If delta = 1 Or delta = -1
Debug "Wheeling"
wflag = 1
EndIf
EndSelect
EndSelect
Until event=#PB_Event_CloseWindow
Re: How to know when the mousewheel has stoped?
Posted: Fri Sep 25, 2020 6:12 am
by Tawbie
Hi AMpos,
If I understand correctly, I think you're saying that the user draws a "rubber band" style zoom box on the area of the currently displayed image that they wish to expand and you want to know when they're done with the zooming 'frame' so that you can then compute and display the expanded region of the image.
If this is correct how about when they finish drawing the zoom box, they click the left mouse button. From a usability perspective that should provide better control for them and remove any guesswork for you.
cheers,
Tawbie
Re: How to know when the mousewheel has stoped?
Posted: Fri Sep 25, 2020 6:59 am
by collectordave
Hi
I do a similar thing with my images.
I do not use the mouse wheel to draw the zoom box.
I use the mouse down then while the mouse button is held down draw the zoom box.
Then when the mouse button is released I redraw the image zoomed to the box. No waiting for the mouse wheel to stop.
I do use the mouse wheel to provide a dynamic zoom so wheel up zooms in and wheel down zooms out.
Works very well with smaller images but gets clunky with large images as the mouse wheel generates loads of events.
My solution to the dynamic zoom was to add a flag to the redraw procedure so if it was drawing the image then any more calls were simply sent back.
I have quickly added some test code to your example just for the zoom and the stopped message is displayed?
Code: Select all
Global ZoomFactor.i = 1
Procedure.i DrawMyImage()
Static iLoop.i = #False
Define Count.i = 0
If iLoop = #True
ProcedureReturn #True
EndIf
iLoop = #True
;Redraw My Image
;Do some long process
;Waste some time
While Count < 10000000
count = count + 1
Wend
Debug "Image Drawn"
iLoop = #False
ProcedureReturn #False
EndProcedure
OpenWindow(1,0,0,400,400,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(1,10,10,380,380)
Repeat
event=WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_MouseWheel
If GetGadgetAttribute(1,#PB_Canvas_WheelDelta)<>0
ZoomFactor = ZoomFactor + GetGadgetAttribute(1,#PB_Canvas_WheelDelta)
If DrawMyImage() = #True
Debug "Wheeling " ;+Str(GetGadgetAttribute(1,#PB_Canvas_WheelDelta))
EndIf
Else
Debug ""
Debug "Stoping!"
Debug "Final Draw Image With Zoom Factor = " + Str(ZoomFactor)
EndIf
EndSelect
EndSelect
Until event=#PB_Event_CloseWindow
CD
Re: How to know when the mousewheel has stoped?
Posted: Fri Sep 25, 2020 11:53 am
by AMpos
Find a solution:
Code: Select all
OpenWindow(1,0,0,400,400,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(1,10,10,380,380)
Debug "Start"
Repeat
event=WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_MouseWheel
If GetGadgetAttribute(1,#PB_Canvas_WheelDelta)<>0
Debug "Wheeling "+Str(GetGadgetAttribute(1,#PB_Canvas_WheelDelta))
delay=100
EndIf
EndSelect
EndSelect
Select delay
Case 2 To 100
delay -1
Case 1
delay=0
Debug "Stop!"
EndSelect
Until event=#PB_Event_CloseWindow
Notice I have not really checked this, as I am at work using a pencil, and I have not a mousewheel
Thank Rashad (and the others) for the idea and help.
Re: How to know when the mousewheel has stoped?
Posted: Fri Sep 25, 2020 11:56 am
by AMpos
Tawbie wrote:Hi AMpos,
If I understand correctly, I think you're saying that the user draws a "rubber band" style zoom box on the area of the currently displayed image that they wish to expand and you want to know when they're done with the zooming 'frame' so that you can then compute and display the expanded region of the image.
If this is correct how about when they finish drawing the zoom box, they click the left mouse button. From a usability perspective that should provide better control for them and remove any guesswork for you.
cheers,
Tawbie
No, the user does not draw a box. The box is drawn always and only the size is changed when the mousewheel is wheeled
Re: How to know when the mousewheel has stoped?
Posted: Sat Sep 26, 2020 12:06 am
by Tawbie
My suggested approach is still valid. The user simply clicks the left mouse button after they finish rotating the mouse wheel to size the box.
From a usability point of view, the user is then in control of exactly when they're done. That's important.
The user might pause or rotate the wheel the other way as they think about what they want. You cannot always anticipate when they're done; and I think it would be irritating if they're not quite done and the image suddenly expands.
Personally, I have always found it better to give the user clear control. My view is that usability (in this case, predictable software behavior) is more important than smarter software.