CanvasGadget eventtypes

Mac OSX specific forum
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

CanvasGadget eventtypes

Post 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
Last edited by mestnyi on Sat Sep 22, 2018 11:31 am, edited 1 time in total.
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: CanvasGadget eventtypes

Post 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...
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CanvasGadget eventtypes

Post 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?
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: CanvasGadget eventtypes

Post 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.
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CanvasGadget eventtypes

Post 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.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CanvasGadget eventtypes

Post 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,
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: CanvasGadget eventtypes

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CanvasGadget eventtypes

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: CanvasGadget eventtypes

Post by mk-soft »

I have tested with standard buttons and you are right with the event click.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CanvasGadget eventtypes

Post by mestnyi »

Another mistake is if you often click on the canvas, the click event is lost. :cry:
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CanvasGadget eventtypes

Post by mestnyi »

This time another mistake with Left Down
LeftDown event shoots faster than focus. :oops:

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
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CanvasGadget eventtypes

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