It is currently Mon Oct 15, 2018 11:24 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: #PB_Event_MouseWheel
PostPosted: Wed May 16, 2018 1:29 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1564
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Thu May 17, 2018 8:27 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 659
Location: Berlin and Ibiza
+1

_________________
ImageImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Thu May 17, 2018 9:12 am 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
+1

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Thu May 17, 2018 1:33 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 691
+1


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Fri May 18, 2018 5:48 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1411
Location: Germany
+1

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

Code:
;-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 OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer /
PB v3.30 / v5.60 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Fri May 18, 2018 6:46 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1592
Location: Uttoxeter, UK
+1

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Sat May 19, 2018 1:01 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1564
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Sat May 19, 2018 1:16 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1411
Location: Germany
Ok, not all gadgets...
Editor and Lists used the mousewheel...

You need alway SetWindowCallback for Window Events. Another way is not safe...

_________________
My Projects OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer /
PB v3.30 / v5.60 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Sat May 19, 2018 1:32 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1564
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:
#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


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Wed Jun 27, 2018 5:47 am 
Offline
Addict
Addict
User avatar

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3224
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.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: #PB_Event_MouseWheel
PostPosted: Fri Jun 29, 2018 9:18 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Mar 10, 2013 3:01 pm
Posts: 561
Location: Portugal
+1


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

All times are UTC + 1 hour


Who is online

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