Page 1 of 1
CanvasGadget eventtypes
Posted: Sat Sep 22, 2018 6:58 am
by mestnyi
Two errors
1) if the mouse button is pressed beyond the canvas, and the cursor enters the canvas, the event "mouse enter" does not occurs.
2) if the mouse button is pressed inside the canvas, and the cursor leaves the canvas, the event "muse leave" occurs.
Code: Select all
Procedure ButtonHandler()
Select EventType()
Case #PB_EventType_MouseEnter
Debug "MouseEnter"
Case #PB_EventType_MouseLeave
Debug "MouseLeave"
Case #PB_EventType_LeftButtonUp
Debug "LeftButtonUp"
Case #PB_EventType_LeftClick
Debug "LeftClick"
EndSelect
EndProcedure
OpenWindow(0, 100, 100, 200, 90, "Mouse events bug", #PB_Window_SystemMenu)
CanvasGadget(0, 10, 10, 180, 30)
BindGadgetEvent(0, @ButtonHandler())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
PureBasic 562 mac os high sierra
Re: CanvasGadget eventtypes
Posted: Sat Sep 22, 2018 10:12 am
by Bisonte
Its the same on Windows. All Gadgets (also in Programs, they not made with PB) have this behaviour....
I think, it's not a bug...
Re: CanvasGadget eventtypes
Posted: Sat Sep 22, 2018 11:40 am
by mestnyi
Its the same on Windows
In the sense of?
For example. Do not the "mouse leave" event occur in the windows after the "left up" event?
Re: CanvasGadget eventtypes
Posted: Sat Sep 22, 2018 7:54 pm
by Bisonte
If you click on a canvas and hold the left button down, move the mouse out of the canvas and release the button.
Then the events mouse_leave and left_up will be fired immediatly.
Re: CanvasGadget eventtypes
Posted: Sun Sep 23, 2018 4:25 am
by mestnyi
Bisonte wrote:If you click on a canvas and hold the left button down, move the mouse out of the canvas and release the button.
Then the events mouse_leave and left_up will be fired immediatly.
The first question is, in what sequence is this happening?
The second question is the same whether on mac os and windows you have?
On my Windows with the beginning there is an event "leftup" and only then event "leave". And it is right.
But on my mac os with the beginning there is an event "leave" and only then the event "leftup". And this is not right.
Re: CanvasGadget eventtypes
Posted: Fri Sep 28, 2018 3:43 pm
by mestnyi
one more error in mac os, the left button is pressed, then we start moving the mouse, then release the button there is no "click" event,
Re: CanvasGadget eventtypes
Posted: Fri Sep 28, 2018 4:52 pm
by mk-soft
mestnyi wrote:one more error in mac os, the left button is pressed, then we start moving the mouse, then release the button there is no "click" event,
Actually it is an error under Windows and Linux that an Event MouseClick comes after a movement of the mouse...
Workaround
Code: Select all
Procedure ButtonHandler()
Select EventType()
Case #PB_EventType_MouseEnter
Debug "MouseEnter"
Case #PB_EventType_MouseLeave
Debug "MouseLeave"
Case #PB_EventType_LeftButtonDown
Debug "LeftButtonDown"
Case #PB_EventType_LeftButtonUp
Debug "LeftButtonUp"
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
PostEvent(#PB_Event_Gadget, EventWindow(), EventGadget(), #PB_EventType_LeftClick)
CompilerEndIf
Case #PB_EventType_LeftClick
Debug "LeftClick"
EndSelect
EndProcedure
[/size]
P.S. Show CheckCanvasMouse
http://www.purebasic.fr/english/viewtop ... 12&t=66856
Re: CanvasGadget eventtypes
Posted: Fri Sep 28, 2018 7:36 pm
by mestnyi
mk-soft wrote:Actually it is an error under Windows and Linux that an Event MouseClick comes after a movement of the mouse...
I do not agree that it is more correct.
In fact, the "Click" should occur when the mouse button is released on the same control on which it was clicked after the event "Up".
Workaround
Thank you, I did, but as I said, if you go beyond the gadget, there should not be a click event. Here, the problems associated with the first two errors on the first post begin.
Re: CanvasGadget eventtypes
Posted: Sat Sep 29, 2018 9:48 am
by mk-soft
I have tested with standard buttons and you are right with the event click.
Re: CanvasGadget eventtypes
Posted: Sun Oct 07, 2018 8:08 am
by mestnyi
Another mistake is if you often click on the canvas, the click event is lost.
Re: CanvasGadget eventtypes
Posted: Tue Oct 09, 2018 12:38 pm
by mestnyi
This time another mistake with Left Down
LeftDown event shoots faster than focus.
Code: Select all
Procedure ButtonHandler()
Select EventType()
Case #PB_EventType_LeftButtonDown
Debug "LeftButtonDown "+ GetActiveGadget()
Case #PB_EventType_LostFocus
Debug "LostFocus "+ GetActiveGadget()
Case #PB_EventType_Focus
Debug "Focus "+ GetActiveGadget()
EndSelect
EndProcedure
OpenWindow(0, 100, 100, 200, 90, "Mouse events bug", #PB_Window_SystemMenu)
CanvasGadget(1, 10, 10, 180, 30, #PB_Canvas_Keyboard)
CanvasGadget(2, 10, 50, 180, 30, #PB_Canvas_Keyboard)
If StartDrawing(CanvasOutput(1))
DrawText(85, 10, "1", 0,$FFFFFF)
StopDrawing()
EndIf
If StartDrawing(CanvasOutput(2))
DrawText(85, 10, "2", 0,$FFFFFF)
StopDrawing()
EndIf
BindGadgetEvent(1, @ButtonHandler())
BindGadgetEvent(2, @ButtonHandler())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Re: CanvasGadget eventtypes
Posted: Thu Oct 11, 2018 7:49 pm
by mestnyi
The following code corrects all errors except one.
That is, if you click on one gadget and move the cursor to another gadget and release after all the events of the first gadget, there should have been an input event for the second gadget.
Code: Select all
Procedure Events(EventType.i)
Protected EventGadget.i = EventGadget()
Select EventType
Case #PB_EventType_Focus : Debug "Focus eg "+ EventGadget +" ag "+ GetActiveGadget()
Case #PB_EventType_LostFocus : Debug "LostFocus eg "+ EventGadget +" ag "+ GetActiveGadget()
Case #PB_EventType_MouseEnter : Debug "MouseEnter eg "+ EventGadget +" ag "+ GetActiveGadget()
Case #PB_EventType_MouseLeave : Debug "MouseLeave eg "+ EventGadget +" ag "+ GetActiveGadget()
Case #PB_EventType_LeftButtonDown : Debug "LeftButtonDown eg "+ EventGadget +" ag "+ GetActiveGadget()
Case #PB_EventType_LeftButtonUp : Debug "LeftButtonUp eg "+ EventGadget +" ag "+ GetActiveGadget()
Case #PB_EventType_LeftClick : Debug "LeftClick eg "+ EventGadget +" ag "+ GetActiveGadget()
EndSelect
EndProcedure
Procedure ButtonHandler()
Static MouseLeave, LeftClick
Protected EventType = EventType()
; Это из за ошибки в мак ос
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Select EventType
Case #PB_EventType_MouseLeave
If GetGadgetAttribute(EventGadget(), #PB_Canvas_Buttons)
EventType = #PB_EventType_MouseMove
MouseLeave = 1
EndIf
Case #PB_EventType_LeftButtonDown
If GetActiveGadget()<>EventGadget()
SetActiveGadget(EventGadget())
EndIf
Case #PB_EventType_LeftButtonUp
If MouseLeave : MouseLeave = 0
Events(#PB_EventType_LeftButtonUp)
EventType = #PB_EventType_MouseLeave
Else
Events(#PB_EventType_LeftButtonUp)
EventType = #PB_EventType_LeftClick
EndIf
Case #PB_EventType_LeftClick : ProcedureReturn 0
EndSelect
CompilerEndIf
Events(EventType)
EndProcedure
OpenWindow(0, 100, 100, 200, 90, "Mouse events bug", #PB_Window_SystemMenu)
CanvasGadget(2, 10, 10, 180, 30, #PB_Canvas_Keyboard)
CanvasGadget(3, 10, 50, 180, 30, #PB_Canvas_Keyboard)
If StartDrawing(CanvasOutput(2))
DrawText(85, 10, "2", 0,$FFFFFF)
StopDrawing()
EndIf
If StartDrawing(CanvasOutput(3))
DrawText(85, 10, "3", 0,$FFFFFF)
StopDrawing()
EndIf
BindGadgetEvent(2, @ButtonHandler())
BindGadgetEvent(3, @ButtonHandler())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow