Canvas Button States delayed?

Just starting out? Need help? Post your questions and find answers here.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Canvas Button States delayed?

Post by #NULL »

If i press and hold the left mouse button then i get the left down event, but the button attribute is not set yet. Then keeping the button pressed and moving the mouse to get another event shows the attribute to be set correctly. The same happens with the up event/state, i get the left up and left click events but the button attribute is only updated on later events.

I using Linux, Ubuntu 16.04 and PB 5.61 x64.
Does anyone spot something wrong with my code and what is the result on Windows?

Code: Select all

EnableExplicit

Define ww, wh, win, style
ww=800
wh=600
style | #PB_Window_ScreenCentered
style | #PB_Window_SystemMenu
style | #PB_Window_MinimizeGadget

win = OpenWindow(#PB_Any, 50,100, ww,wh, "", style)
AddKeyboardShortcut(win, #PB_Shortcut_Escape, 10)
Define canvas = CanvasGadget(#PB_Any, 0, 0, ww, wh)

Define event, em, eg, et, quit
Define canvasLeftButtonDown, canvasRightButtonDown

Repeat
  
  ; ...
  
  Repeat
    event = WindowEvent()
    em = EventMenu()
    eg = EventGadget()
    et = EventType()
    Select event
      Case #PB_Event_CloseWindow
        quit = #True
      Case #PB_Event_Menu
        Select em
        Case 10
          quit = #True
        EndSelect
      Case #PB_Event_Gadget
        
        Debug "gadget event"
        
        If et = #PB_EventType_LeftButtonDown
          Debug " left down"
        EndIf
        If et = #PB_EventType_LeftButtonUp
          Debug " left up"
        EndIf
        If et = #PB_EventType_LeftClick
          Debug " left click"
        EndIf
        
        canvasLeftButtonDown  = GetGadgetAttribute(canvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton
        Debug " down: " + canvasLeftButtonDown

    EndSelect
  Until Not event
  
  ; ...
  
Until quit
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Canvas Button States delayed?

Post by davido »

@NULL,
I ran your code on Windows 10 x64 with PureBasic 5.61 x64

On holding the left button down I get:

gadget event
left down
down: 1


If I move the mouse, whilst keeping the button down, the above is continually repeated until button up.
DE AA EB
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Canvas Button States delayed?

Post by #NULL »

Seems to work ok then. It looks like this on my system:

Code: Select all

gadget event
 left down
 down: 0
gadget event
 down: 1
gadget event
 down: 1
gadget event
 left up
 down: 1
gadget event
 left click
 down: 1
gadget event
 down: 0
gadget event
 down: 0
gadget event
 down: 0
Post Reply