How to know when the mousewheel has stoped?

Just starting out? Need help? Post your questions and find answers here.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

How to know when the mousewheel has stoped?

Post 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 :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: How to know when the mousewheel has stoped?

Post 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
Egypt my love
Tawbie
User
User
Posts: 26
Joined: Fri Jul 10, 2020 2:36 am

Re: How to know when the mousewheel has stoped?

Post 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
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: How to know when the mousewheel has stoped?

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: How to know when the mousewheel has stoped?

Post 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.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: How to know when the mousewheel has stoped?

Post 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
Tawbie
User
User
Posts: 26
Joined: Fri Jul 10, 2020 2:36 am

Re: How to know when the mousewheel has stoped?

Post 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.
Post Reply