It is currently Wed Oct 21, 2020 2:38 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How to know when the mousewheel has stoped?
PostPosted: Thu Sep 24, 2020 11:26 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Jun 05, 2020 12:47 am
Posts: 119
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:
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 :)


Top
 Profile  
Reply with quote  
 Post subject: Re: How to know when the mousewheel has stoped?
PostPosted: Fri Sep 25, 2020 1:53 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3703
I think there is much elegant solution than the next
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How to know when the mousewheel has stoped?
PostPosted: Fri Sep 25, 2020 6:12 am 
Offline
New User
New User

Joined: Fri Jul 10, 2020 2:36 am
Posts: 8
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How to know when the mousewheel has stoped?
PostPosted: Fri Sep 25, 2020 6:59 am 
Offline
Addict
Addict

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

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to know when the mousewheel has stoped?
PostPosted: Fri Sep 25, 2020 11:53 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jun 05, 2020 12:47 am
Posts: 119
Find a solution:

Code:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to know when the mousewheel has stoped?
PostPosted: Fri Sep 25, 2020 11:56 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jun 05, 2020 12:47 am
Posts: 119
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How to know when the mousewheel has stoped?
PostPosted: Sat Sep 26, 2020 12:06 am 
Offline
New User
New User

Joined: Fri Jul 10, 2020 2:36 am
Posts: 8
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye