[not a bug ]canvas gadget

Just starting out? Need help? Post your questions and find answers here.
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

[not a bug ]canvas gadget

Post by case »

Case #PB_EventType_MouseLeave not working when a mouse button is down

Code: Select all

 OpenWindow(0, 0, 0, 480, 380, "Canvas mouse test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0, 40, 40, 400, 300)

Repeat
 
  Event = WaitWindowEvent()
 
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_MouseLeave
              Debug "Mouse Leave, Pos = " + Str(GetGadgetAttribute(0, #PB_Canvas_MouseX)) + "/" + Str(GetGadgetAttribute(0, #PB_Canvas_MouseY))
            Case #PB_EventType_MouseEnter
              Debug "Mouse Enter, Pos = " + Str(GetGadgetAttribute(0, #PB_Canvas_MouseX)) + "/" + Str(GetGadgetAttribute(0, #PB_Canvas_MouseY))
            Case #PB_EventType_MouseMove
              Debug "Mouse Move, Pos = " + Str(GetGadgetAttribute(0, #PB_Canvas_MouseX)) + "/" + Str(GetGadgetAttribute(0, #PB_Canvas_MouseY))
          EndSelect
         
      EndSelect
     
    Case #PB_Event_CloseWindow
      Exit = #True
  EndSelect
 
Until Exit
Last edited by case on Tue May 31, 2016 1:16 am, edited 1 time in total.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: canvas gadget

Post by collectordave »

Bit weird.

If you press the mouse button outside the canvas then move into the canvas area mouse enter and leave are reported with mouse down, If you press the mouse button when on the canvas mouse leave is not reported untill you release the mouse button!

PB5.42 windows 7.0
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: canvas gadget

Post by mestnyi »

Can you give an example of where this is the way?
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: canvas gadget

Post by freak »

collectordave wrote:If you press the mouse button outside the canvas then move into the canvas area mouse enter and leave are reported with mouse down, If you press the mouse button when on the canvas mouse leave is not reported untill you release the mouse button!
This is by design. It simplifies writing mouse tracking code.

If you press & hold the mouse button inside the gadget, you receive mouse move events even from outside of the own gadget until the button is released (the mouse is "captured"). You can think of it as the gadget having infinite size while you hold the mouse button. This allows implementing dragging/scrolling in an intuitive way. So in a sense, the mouse does not "leave" the gadget until the button is released. This is why the release event is delayed as well to have a logical order of events independent of where the button is released (inside or outside of the gadget).
quidquid Latine dictum sit altum videtur
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: canvas gadget

Post by netmaestro »

That's correct behavior imho. Anything else would be counterintuitive and pretty much nonstandard for an OS control (which this isn't but one of its best uses is to make custom controls).
BERESHEIT
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

Re: canvas gadget

Post by case »

thanks for the explainations freak & netmaestro but it was not that clear at first .
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: [not a bug ]canvas gadget

Post by collectordave »

Makes sense when you think it through.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: [not a bug ]canvas gadget

Post by dobro »

maybe :

Code: Select all


Declare  mywindowcallback(windowid, message, wparam, lparam)

Enumeration
	#canvas
	#win
EndEnumeration
#x=40
#y=40
#larg=400
#haut=300

OpenWindow(#win, 0, 0, 480, 380, "Canvas mouse test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(#canvas, #x, #y, #larg, #haut)


Repeat
	
	Event = WaitWindowEvent()
	x_mouse=GetGadgetAttribute(#canvas, #PB_Canvas_MouseX)
	y_mouse=GetGadgetAttribute(#canvas, #PB_Canvas_MouseY)
	Select Event
		Case #PB_Event_Gadget
		Select EventGadget()
			Case 0
			Select EventType()
				
				Case #PB_EventType_MouseLeave
				if (x_mouse>=#x and x_mouse<=#larg) and (y_mouse>=#y and y_mouse<=#Haut)
					Debug "Mouse Leave, Pos = " + Str(x_mouse) + "/" + Str(y_mouse)
				Endif
				Case #PB_EventType_MouseEnter
				if (x_mouse>=#x and x_mouse<=#larg) and (y_mouse>=#y and y_mouse<=#Haut)
					Debug "Mouse Enter, Pos = " + Str(x_mouse) + "/" + Str(y_mouse)
				Endif
				Case #PB_EventType_MouseMove
				if (x_mouse>=#x and x_mouse<=#larg) and (y_mouse>=#y and y_mouse<=#Haut)
					Debug "Mouse Move, Pos = " + Str(x_mouse) + "/" + Str(y_mouse)
				Endif
			EndSelect
			
		EndSelect
		
		Case #PB_Event_CloseWindow
		Exit = #True
	EndSelect
	
Until Exit

; Epb

Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

Re: [not a bug ]canvas gadget

Post by case »

thanks dobro ,)
Post Reply