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