It is currently Sun Jan 24, 2021 3:49 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Progressive MacOS Style MouseWheel for all OS
PostPosted: Thu Dec 24, 2020 6:58 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 422
Location: Pandora
Progressive MacOS Style MouseWheel for all OS

A small but very useful code which emulates exactly, but more flexible,
the progressive MouseWheel as it is realized in MacOS, for all OS at the same.

Once you've used it, you won't want it any other way. :wink:

Code:
EnableExplicit
; Progressive speed MouseWheel - Adjustable - DPI aware - by Saki
Define window_ID=OpenWindow(#PB_Any, 0, 0, 300, 650, "Move the MouseWheel", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If window_ID
  Define canvas_ID=CanvasGadget(#PB_Any, 10, 10, WindowWidth(window_ID)-20, WindowHeight(window_ID)-20)
  If canvas_ID
    Define win_event, get_wheel, step_result, stepwidth.f, time.q, DR.f=DesktopResolutionX()
    Define timeout=400       ; Here you can adjust the progression
    Define max_step_width=50 ; Here you can adjust the max step width
    Define pos_y=GadgetHeight(canvas_ID)/2*DR
    max_step_width*DR
    SetGadgetColor(canvas_ID, #PB_Gadget_BackColor, #Black)
    If StartDrawing(CanvasOutput(canvas_ID))
      Box(0, GadgetHeight(canvas_ID)/2*DR, GadgetWidth(canvas_ID)*DR, 20*DR, #White)
      Box(20*DR, pos_y, (GadgetWidth(canvas_ID)-40)*DR, 20*DR, #Red)
      StopDrawing()
    EndIf
    Repeat
      win_event=WaitWindowEvent()
      If ElapsedMilliseconds()>time+timeout : stepwidth=1 : EndIf
      If win_event=#PB_Event_Gadget And EventGadget()=canvas_ID
        If EventType()=#PB_EventType_MouseWheel
          time=ElapsedMilliseconds()
          get_wheel=GetGadgetAttribute(canvas_ID, #PB_Canvas_WheelDelta)
          If get_wheel>0 : step_result=-stepwidth
          ElseIf get_wheel<0
            step_result=stepwidth
          EndIf
          stepwidth+DR
          If stepwidth>max_step_width
            stepwidth=max_step_width
          ElseIf stepwidth<-max_step_width
            stepwidth=-max_step_width
          EndIf
          pos_y+step_result
          If StartDrawing(CanvasOutput(canvas_ID))
            Box(0, 0, GadgetWidth(canvas_ID)*DR, GadgetHeight(canvas_ID)*DR, #Black)
            Box(0, GadgetHeight(canvas_ID)/2*DR, GadgetWidth(canvas_ID)*DR, 20*DR, #White)
            Box(20*DR, pos_y, (GadgetWidth(canvas_ID)-40)*DR, 20*DR, #Red)
            StopDrawing()
          EndIf
        EndIf
      EndIf     
    Until win_event=#PB_Event_CloseWindow
  EndIf
EndIf

_________________
地球上の平和


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 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