Page 1 of 1

[not a bug ]canvas gadget

Posted: Sun May 29, 2016 10:36 pm
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

Re: canvas gadget

Posted: Mon May 30, 2016 4:28 am
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

Re: canvas gadget

Posted: Mon May 30, 2016 6:53 pm
by mestnyi
Can you give an example of where this is the way?

Re: canvas gadget

Posted: Mon May 30, 2016 10:11 pm
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).

Re: canvas gadget

Posted: Mon May 30, 2016 10:40 pm
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).

Re: canvas gadget

Posted: Tue May 31, 2016 1:13 am
by case
thanks for the explainations freak & netmaestro but it was not that clear at first .

Re: [not a bug ]canvas gadget

Posted: Tue May 31, 2016 6:24 am
by collectordave
Makes sense when you think it through.

Re: [not a bug ]canvas gadget

Posted: Tue May 31, 2016 8:43 am
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


Re: [not a bug ]canvas gadget

Posted: Tue May 31, 2016 7:18 pm
by case
thanks dobro ,)