Page 1 of 1
#PB_EventType_MouseLeave buttons
Posted: Thu Oct 24, 2019 5:01 am
by wombats
Could we please be able to detect which mouse buttons are pressed upon the #PB_EventType_MouseLeave and #PB_EventType_MouseEnter events? The following only work on macOS:
Code: Select all
If GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton
EndIf
Code: Select all
If GetGadgetAttribute(0, #PB_OpenGL_Buttons) & #PB_OpenGL_LeftButton
EndIf
I can do it through API on Windows, but I can't find a way at all to do it with the Qt subsystem. It would make life much easier to have this built-in and make these gadgets more functional (for example, when drag scrolling).
Re: #PB_EventType_MouseLeave buttons
Posted: Thu Oct 24, 2019 6:40 am
by STARGÅTE
If you press a button (left, right, middle) the #PB_EventType_MouseLeave event will only received if you leave the canvas
and release the button. Logically, GetGadgetAttribute(0, #PB_Canvas_Buttons) is always 0.
Code: Select all
Enumeration
#Window
#Gadget
EndEnumeration
OpenWindow(#Window, 0, 0, 800, 450, "Vector Canvas Gadget", #PB_Window_MaximizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(#Gadget, 100, 100, WindowWidth(#Window)-200, WindowHeight(#Window)-100, #PB_Canvas_Keyboard)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #Gadget
Select EventType()
Case #PB_EventType_MouseEnter
Debug GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons)
Case #PB_EventType_MouseLeave
Debug GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons)
EndSelect
EndSelect
EndSelect
ForEver
End
Re: #PB_EventType_MouseLeave buttons
Posted: Thu Oct 24, 2019 7:26 am
by #NULL
With Qt on linux you don't get enter/leave events after you click and hold in the canvas and move the mouse out and in. With gtk2 and gtk3 you do get enter/leave events while the button is pressed (but only if it was pressed on the canvas first and not outside).
Code: Select all
Case #PB_EventType_MouseEnter
Debug "enter : " +
" " + Str(GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton) +
", " + Str(GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons) & #PB_Canvas_MiddleButton) +
", " + Str(GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons) & #PB_Canvas_RightButton)
Case #PB_EventType_MouseLeave
Debug "leave : " +
" " + Str(GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton) +
", " + Str(GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons) & #PB_Canvas_MiddleButton) +
", " + Str(GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons) & #PB_Canvas_RightButton)
Re: #PB_EventType_MouseLeave buttons
Posted: Fri Oct 25, 2019 10:43 am
by Justin
In linux you can do it like this, you have to remove the grab when the button is pressed.
Code: Select all
EnableExplicit
ImportC ""
gdk_device_get_seat_(dv.i) As "gdk_device_get_seat"
gdk_seat_ungrab_(st.i) As "gdk_seat_ungrab"
EndImport
Structure _GdkEvent Align #PB_Structure_AlignC
StructureUnion
type.l
any.GdkEventAny
expose.GdkEventExpose
no_expose.GdkEventNoExpose
visibility.GdkEventVisibility
motion.GdkEventMotion
button.GdkEventButton
scroll.GdkEventScroll
key.GdkEventKey
crossing.GdkEventCrossing
focus_change.GdkEventFocus
configure.GdkEventConfigure
property.GdkEventProperty
selection.GdkEventSelection
proximity.GdkEventProximity
client.GdkEventClient
dnd.GdkEventDND
window_state.GdkEventWindowState
setting.GdkEventSetting
EndStructureUnion
EndStructure
Enumeration
#Window
#Gadget
EndEnumeration
ProcedureC winEventHandler(*event._GdkEvent, dat.i)
Define.GdkEventButton *evBtn
Select *event\type
Case #GDK_BUTTON_PRESS
;remove grab
*evBtn = *event
gdk_seat_ungrab_(gdk_device_get_seat_(*evBtn\device))
EndSelect
gtk_main_do_event_(*event)
EndProcedure
OpenWindow(#Window, 0, 0, 800, 450, "Vector Canvas Gadget", #PB_Window_MaximizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
gdk_event_handler_set_(@winEventHandler(), 0, 0)
CanvasGadget(#Gadget, 100, 100, WindowWidth(#Window)-200, WindowHeight(#Window)-100, #PB_Canvas_Keyboard)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #Gadget
Select EventType()
Case #PB_EventType_MouseEnter
Debug GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons)
Case #PB_EventType_MouseLeave
Debug GetGadgetAttribute(#Gadget, #PB_Canvas_Buttons)
EndSelect
EndSelect
EndSelect
ForEver
Re: #PB_EventType_MouseLeave buttons
Posted: Fri Oct 25, 2019 11:21 am
by wombats
Thanks, but I have to use the Qt subsystem due to a crash with the OpenGLGadget on GTK.

I don’t think QtScript gives us that kind of access.