It is currently Sat Oct 31, 2020 8:47 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: DisableGadget() ImageGadget()
PostPosted: Sun Apr 12, 2020 10:28 am 
Offline
User
User

Joined: Thu Aug 30, 2018 11:34 am
Posts: 32
Hi

This code works as expected on Windows 10 but not on Catalina.

On macOS Catalina 10.15.4 using PB572, left and right mouse clicks are sometimes detected on a disabled image gadget. No mouse clicks detected on Windows 10.


Code:

  OpenWindow(0, 0, 0, 200, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  TextGadget(0, 10, 1, 180, 20, "", #PB_Text_Center)

  BoxSize=40
 
  CreateImage(0, BoxSize, BoxSize)
  StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(0,255,0))
  StopDrawing()
 
  CreateImage(1, BoxSize, BoxSize)
  StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(255,0,0))
  StopDrawing()
 
  ImageGadget(1, 40, 40, BoxSize, BoxSize, ImageID(0))
  ImageGadget(2,120, 40, BoxSize, BoxSize, ImageID(0))

  Global LClicks = 0
  Global RClicks = 0
  Global BIG = 0
  Global EVT = 0

  Procedure OffOn()
    If BIG = 1
      DisableGadget(1, 1)
      DisableGadget(2, 0)
      SetGadgetState(1, ImageID(1))
      SetGadgetState(2, ImageID(0))
    Else
      DisableGadget(1, 0)
      DisableGadget(2, 1)
      SetGadgetState(1, ImageID(0))
      SetGadgetState(2, ImageID(1))
    EndIf
    SetGadgetText(0, "BIG " + Str(BIG) + "  L " + Str(LClicks) + "  R " + Str(RClicks))   
  EndProcedure
 
 
  Repeat
    Event = WaitWindowEvent(100)
       
    If Event = #PB_Event_Gadget
     
      BIG = EventGadget()
      EVT = EventType()

      If EVT = #PB_EventType_LeftClick
        LClicks = LClicks + 1
        OffOn()
      EndIf
     
      If EVT = #PB_EventType_RightClick
        RClicks = RClicks + 1
        OffOn()
      EndIf         
     
    EndIf
   
  Until Event = #PB_Event_CloseWindow
   
  End
   




Using GetGadgetState() instead of DisableGadget() as a workaround.


Top
 Profile  
Reply with quote  
 Post subject: Re: DisableGadget() ImageGadget()
PostPosted: Sun Apr 12, 2020 11:33 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2689
Location: Germany
Must be a bug in macOS.

Although the object NSImageView (NSControl) is locked "isEnabled = 0" the events are processed differently.

Solution: Query isEnabled
Code:
Procedure IsEnabled(Gadget)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn #True ; TODO
    CompilerCase #PB_OS_Linux
      ProcedureReturn #True ; TODO
    CompilerCase #PB_OS_MacOS
      ProcedureReturn CocoaMessage(0, GadgetID(Gadget), "isEnabled")
    CompilerEndSelect
EndProcedure

OpenWindow(0, 0, 0, 200, 120, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  TextGadget(0, 10, 1, 180, 20, "", #PB_Text_Center)

  BoxSize=40
 
  CreateImage(0, BoxSize, BoxSize)
  StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(0,255,0))
  StopDrawing()
 
  CreateImage(1, BoxSize, BoxSize)
  StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,BoxSize,BoxSize,RGB(255,0,0))
  StopDrawing()
 
  ImageGadget(1, 40, 40, BoxSize, BoxSize, ImageID(0))
  ImageGadget(2,120, 40, BoxSize, BoxSize, ImageID(0))
 
  DisableGadget(2, 1)
  ;CocoaMessage(0, GadgetID(2), "setEnabled:", #False)
 
  Debug CocoaMessage(0, GadgetID(2), "isEnabled")
 
 
  Debug DumpObjectMethods(GadgetID(1), 1)
 
  Repeat
    Event = WaitWindowEvent()
       
    If Event = #PB_Event_Gadget
     
      Select EventType()
        Case #PB_EventType_LeftClick
         
          If IsEnabled(EventGadget())
            Debug "Left " + EventGadget()
          EndIf
         
        Case #PB_EventType_RightClick
          If IsEnabled(EventGadget())
            Debug "Right " + EventGadget()
          EndIf
         
      EndSelect         
     
    EndIf
   
  Until Event = #PB_Event_CloseWindow
   
  End

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: DisableGadget() ImageGadget()
PostPosted: Sun Apr 12, 2020 2:12 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 523
The problem ist if you click to fast it will be detected as double or triple click.

This seams logical to me.

Code:
  Repeat
    Event = WaitWindowEvent(100)
       
    If Event = #PB_Event_Gadget
     
      BIG = EventGadget()
      EVT = EventType()

      If EVT = #PB_EventType_LeftClick Or EVT = #PB_EventType_LeftDoubleClick
        LClicks = LClicks + 1
        OffOn()
      EndIf
     
      If EVT = #PB_EventType_RightClick Or EVT = #PB_EventType_RightDoubleClick
        RClicks = RClicks + 1
        OffOn()
      EndIf         
     
    EndIf
   
  Until Event = #PB_Event_CloseWindow


Top
 Profile  
Reply with quote  
 Post subject: Re: DisableGadget() ImageGadget()
PostPosted: Sun Apr 12, 2020 2:23 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2689
Location: Germany
Disable ImageGadget on macOS not work...

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye