#PB_Event_MouseWheel

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

#PB_Event_MouseWheel

Post by Dude »

Can we please get a native #PB_Event_MouseWheel event for WaitWindowEvent(), and also a flag to indicate the direction (back/forward) when such an event is triggered? Thank you. :)

Currently I'm checking for #WM_MOUSEWHEEL and then using "dir=-(EventwParam()>>16)/#WHEEL_DELTA" to get the direction (-1 for back and 1 for forward), but this is not future-proof because the manual says NOT to use EventwParam() anymore.

Thanks for considering.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: #PB_Event_MouseWheel

Post by RSBasic »

+1
Image
Image
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: #PB_Event_MouseWheel

Post by walbus »

+1
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: #PB_Event_MouseWheel

Post by mestnyi »

+1
Also needed left and right for horizontal
Last edited by mestnyi on Tue Dec 04, 2018 8:23 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: #PB_Event_MouseWheel

Post by mk-soft »

+1

The event only arrives at the window if no gadget has the focus
It's like this on Windows.

Code: Select all

;-TOP
Enumeration EventCustomValue #PB_Event_FirstCustomValue
EndEnumeration

Enumeration EventCustomValue
  #PB_Event_MouseWheel
EndEnumeration
  
Procedure WinCB(hWnd, uMsg, wParam, lParam)
  Protected r1 = #PB_ProcessPureBasicEvents
  Protected gadget, wheel
  If uMsg = #WM_MOUSEWHEEL
    wheel = wParam >> 16 / 120
    PostEvent(#PB_Event_MouseWheel, GetActiveWindow(), GetActiveGadget(), Wheel)
  EndIf
  ProcedureReturn r1
EndProcedure

SetWindowCallback(@WinCB())

;-Test

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration Window
    #Main
  EndEnumeration
  
  Enumeration Gadget
    #Editor
    #Container
    #ButtonB0
    #ButtonB1
    #ButtonB2
  EndEnumeration
  
  Procedure OpenMain(x = 10, y = 10, width = 550, height = 400)
    OpenWindow(#Main, x, y, width + MenuHeight(), height + MenuHeight(), "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
    EditorGadget(#Editor, 10, 10, 530, 310)
    ContainerGadget(#Container, 10, 330, 530, 60)
    ButtonGadget(#ButtonB0, 10, 5, 160, 40, "Button 0")
    ButtonGadget(#ButtonB1, 180, 5, 170, 40, "Button 1")
    ButtonGadget(#ButtonB2, 360, 5, 160, 40, "Button 2")
    CloseGadgetList()
  EndProcedure
  
  OpenMain()
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_MouseWheel
        Debug EventType()
    EndSelect
  ForEver
  
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: #PB_Event_MouseWheel

Post by davido »

+1
DE AA EB
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: #PB_Event_MouseWheel

Post by Dude »

mk-soft wrote:The event only arrives at the window if no gadget has the focus
It's like this on Windows.
Mousewheel events can certainly occur if a gadget has the focus -- just not the way you coded it. ;)

Here's how I code it, but it's not "official" due to #WM_MOUSEWHEEL (and EventwParam(), which isn't shown here):

Code: Select all

OpenWindow(0,200,200,200,90,"test",#PB_Window_SystemMenu)

EditorGadget(0,10,10,180,30)
ButtonGadget(1,10,50,180,30,"button")

SetActiveGadget(0)

Repeat
  ev=WaitWindowEvent()
  If ev=#WM_MOUSEWHEEL
    Debug "wheel"
  EndIf
Until ev=#PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: #PB_Event_MouseWheel

Post by mk-soft »

Ok, not all gadgets...
Editor and Lists used the mousewheel...

You need alway SetWindowCallback for Window Events. Another way is not safe...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: #PB_Event_MouseWheel

Post by Dude »

mk-soft wrote:not all gadgets
First time I've heard that. I can click any gadget in the official gadget example and the mousewheel event still fires (see below).

Anyway, this is all moot because the request is for an official way without using Callbacks. :)

Code: Select all

#WindowWidth  = 390
#WindowHeight = 350

If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration", #PB_Window_MinimizeGadget)
    
  Top = 10
  GadgetHeight = 24

  FrameGadget(#PB_Any, 10, Top, 370, 290, "Player...") : Top+20

  StringGadget(0,  20, Top, 200, GadgetHeight, "")
  ButtonGadget(1, 223, Top,  72, GadgetHeight, "Play")
  ButtonGadget(2, 295, Top,  72, GadgetHeight, "Stop")  : Top+35
  DisableGadget(2,1)
  
  GadgetToolTip(1,"Play the current song")
  
  PanelGadget(3, 20, Top, #WindowWidth-50, #WindowHeight-Top-60)
    AddGadgetItem(3, 0, "MP3 PlayList")
      ListViewGadget(4, 6, 10, 230, 148)

      For k=0 To 30
        AddGadgetItem(4, -1, "Music Song n° "+Str(k))
      Next

      ButtonGadget(5,  250, 10, 80, GadgetHeight, "Add")
      ButtonGadget(6,  250, 38, 80, GadgetHeight, "Remove")
      ButtonGadget(7,  250, 66, 80, GadgetHeight, "Select")
      GadgetToolTip(7, "Select the current song")
      
      TrackBarGadget(17, 10, 168, 310, 25, 0, 100)

    AddGadgetItem(3, 1, "Options")
      Top = 10
      CheckBoxGadget(10, 10, Top, 250, GadgetHeight, "Enable low-pass filter") : Top+30
      CheckBoxGadget(11, 10, Top, 250, GadgetHeight, "Enable visual plug-in")  : Top+30
      ComboBoxGadget(12, 10, Top, 250, 21) : Top+30
        AddGadgetItem(12, -1, "FireWorks")
        AddGadgetItem(12, -1, "OpenGL spectrum")
        AddGadgetItem(12, -1, "Bump bass")
      SetGadgetState(12,0)
      DisableGadget(12,1)
      
      OptionGadget(13, 10, Top, 80, GadgetHeight, "640*480") : Top+20
      OptionGadget(14, 10, Top, 80, GadgetHeight, "800*600") : Top+20
      OptionGadget(15, 10, Top, 80, GadgetHeight, "1024*768")
      SetGadgetState(13, 1)
      
      ButtonGadget(16, 150, Top, 80, GadgetHeight, "Info")
  CloseGadgetList()

  TextGadget  (9, 10, #WindowHeight-30, 250, 24, "PureBasic - Gadget demonstration")
  ButtonGadget(8, #WindowWidth-100, #WindowHeight-36, 80, 24, "Quit")

  SetGadgetState(3, 0)

  Repeat
  
    Event = WaitWindowEvent()
    
    If Event = #WM_MOUSEWHEEL
    
      wheel+1
      Debug wheel
    
    ElseIf Event = #PB_Event_Gadget

      Select EventGadget()
        Case 0
          If EventType() = #PB_EventType_ReturnKey
            MessageRequester("Info", "Return key pressed", 0)
            SetActiveGadget(0)
          EndIf
          
        Case 1 ; Play
          DisableGadget(2,0)  ; Enable the 'Stop' gadget
          DisableGadget(1,1)  ; Disable the 'Play' Gadget
      
        Case 2 ; Stop
          DisableGadget(1,0)  ; Enable the 'Play' gadget
          DisableGadget(2,1)  ; Disable the 'Stop' Gadget
        
        Case 4
          If EventType() = 2
            SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
          EndIf

        Case 5 ; Add
          AddGadgetItem(4, -1, "New Item Added...")

        Case 6 ; Remove
          RemoveGadgetItem(4, GetGadgetState(4)) ; Remove the current element of the ListView

        Case 7 ; Select
          SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
  
        Case 8 ; Quit...
          Event = #PB_Event_CloseWindow

        Case 11 ; Enable PlugIn..
          DisableGadget(12, 1-GetGadgetState(11))
          
        Case 16 ;
          If GetGadgetState(13) : Result$ = GetGadgetText(13) : EndIf
          If GetGadgetState(14) : Result$ = GetGadgetText(14) : EndIf
          If GetGadgetState(15) : Result$ = GetGadgetText(15) : EndIf
         
        Case 17
          SetGadgetText(0, Str(GetGadgetState(17)))
          
      EndSelect

    EndIf

  Until Event = #PB_Event_CloseWindow

EndIf
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: #PB_Event_MouseWheel

Post by Mistrel »

As of Windows XP, if you want to monitor the mouse wheel outside of a window's message queue, the correct API to use is RegisterRawInputDevices() and GetRawInputData().

It's also possible to do this with SetWindowsHookEx() by injecting a global mouse hook but this a legacy API (as far back as Windows 3.1) and is highly discouraged as it is synchronous with all mouse related input events and will cause lag.

Of course, this is only an option for Windows.
User avatar
marcoagpinto
Addict
Addict
Posts: 940
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: #PB_Event_MouseWheel

Post by marcoagpinto »

+1
Post Reply