#PB_EventType_MouseLeave buttons

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

#PB_EventType_MouseLeave buttons

Post 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).
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: #PB_EventType_MouseLeave buttons

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: #PB_EventType_MouseLeave buttons

Post 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)
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: #PB_EventType_MouseLeave buttons

Post 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
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: #PB_EventType_MouseLeave buttons

Post 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.
Post Reply