How to block passthrough click with popup

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

How to block passthrough click with popup

Post by mrcoollion » Wed Mar 29, 2023 10:23 am

Hi LC friends,

I have the following challenge.
I made a popup field that removes itself after a few seconds without user intervention.
However, I also want to prevent the user from clicking on any of the buttons during the presentation of the popup field.
I thought to solve this by creating a graphical layer below the popup field but this does not block a user's click on a button below.
What solution can I use to prevent users to click on buttons during the presentation of the popup field?
Here is the test code I made.

Code: Select all

//====================================================================================
// Show PopUp Message (by creating a temporary field and removing it)
//====================================================================================
command MessagePopUp tMessage, tShowTime, tBackgroundcolor, tTextColor
   --- Checks ---
   if tMessage = "" then put "No message!" into tMessage
   if tShowTime = "" then put 3 into tShowTime
   if tBackgroundcolor = "" then put "White" into tBackgroundcolor
   if tTextColor = "" then put "White" into tTextColor
   ---
   //lock screen
   put "AutoPopUp" into tFieldName
   if exists (field tFieldName) // Just to make sure it does not exist due to testing .
   then
      delete field tFieldName
   end if
   if exists (graphic tFieldName) // Just to make sure it does not exist due to testing .
   then
      delete graphic tFieldName
   end if
   ----
   create field tFieldName
   create graphic tFieldName
   set the visible of field tFieldName to false
   ---- Set Graphic criteria
   set the rect of graphic tFieldName to the rect of this stack
   set the opaque of graphic tFieldName to true
   set blendLevel  of graphic tFieldName to 50
   set ink  of graphic tFieldName to "blendSrcOver"
   set the antialiased of graphic tFieldName to true
   set the layer of graphic tFieldName to top
   set the disabled of graphic tFieldName to true
   ---- Set Field criteria
   put cr&tMessage&cr into field tFieldName
   set the lockText of field tFieldName to true
   set the opaque of field tFieldName to true
   set borderwidth of field tFieldName to 2
   set traversalon of field tFieldName to false
   set showfocusborder of field tFieldName to true
   set autotab of field tFieldName to false
   set threeD of field tFieldName to true
   set showborder of field tFieldName to true
   set autohilite of field tFieldName to true
   set listBehavior of field tFieldName to false
   set multipleHilites of field tFieldName to false
   set nonContiguousHilites of field tFieldName to false
   set toggleHilites of field tFieldName to false
   set the layer of field tFieldName to top
   set the loc of field tFieldName to the loc of this card
   set the backgroundColor of field tFieldName to tBackgroundcolor
   set the foregroundColor of field tFieldName to tTextColor
   //set textstyle of field tFieldName to "Bold" // Messesup the formattedWidth command
   set the height of field tFieldName to the formattedHeight of field tFieldName
   set the Width of field tFieldName to the formattedWidth of field tFieldName
   -- Activate graphic and show field (PopUp)
   //unlock screen
   set the visible of graphic tFieldName to true
   set the visible of field tFieldName to true
   --
   wait tShowTime seconds
   set the visible of field tFieldName to false
   --
   delete field tFieldName
   delete graphic tFieldName
   --
end MessagePopUp
//====================================================================================


SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: How to block passthrough click with popup

Post by SWEdeAndy » Wed Mar 29, 2023 10:39 am

Try changing

Code: Select all

set the rect of graphic tFieldName to the rect of this stack
to

Code: Select all

set the rect of graphic tFieldName to the rect of this card
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9251
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: How to block passthrough click with popup

Post by richmond62 » Wed Mar 29, 2023 10:45 am

This is crude, but:
-
SShot 2023-03-29 at 12.42.59.png
-

script of button "RANDOM BUTTON":

Code: Select all

on mouseUp
   if the vis of fld "ff" is false then
      set the textColor of me to red
      wait 3 seconds
      set the textColor of me to blue
   end if
end mouseUp
HOWEVER, I have a feeling that IF one clicks on a button during the time the field is visible
the mouseUp is somehow stored and activates after the field become invisible . . . not sure to be honest.
Attachments
Mary Poppins.livecode.zip
Stack.
(1.1 KiB) Downloaded 49 times

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: How to block passthrough click with popup

Post by mrcoollion » Wed Mar 29, 2023 10:58 am

HOWEVER, I have a feeling that IF one clicks on a button during the time the field is visible
the mouseUp is somehow stored and activates after the field become invisible . . . not sure to be honest.
This is exactly the problem!
Does not matter if I use a Graphic or a Button. The MOUSE CLICK is stored and activated after the graphic and field are deleted.

PS. Thanks for the Tip Andy (changed code from stack to card. It now blocks the complete area).

Additional: I cannot block the complete message path because in the background I have a process running.

Regards,

Paul

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9251
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: How to block passthrough click with popup

Post by richmond62 » Wed Mar 29, 2023 11:04 am

HOWEVER, I have a feeling that IF one clicks on a button during the time the field is visible
the mouseUp is somehow stored and activates after the field become invisible . . . not sure to be honest.
Erm . . . how about making all the buttons invisible while your field is visible?

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to block passthrough click with popup

Post by Klaus » Wed Mar 29, 2023 11:16 am

Add this at the end of your handler:

Code: Select all

...
   --
   delete field tFieldName
   delete graphic tFieldName
   --
   get flushevents("all")
   ## Or maybe just:
   ## get flushevents("mouseup")
end MessagePopUp
That should do the job.

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: How to block passthrough click with popup

Post by mrcoollion » Wed Mar 29, 2023 11:34 am

Hi Klaus,

This does work however I set it as below because only a MouseUp gave some strange results.
Also it does prevent the mouse from clicking however when i click at any place in the card (that is not an object) it activates the last clicked button :shock: .

Code: Select all

   
   put flushEvents("mouseUp") into temp1
   put flushEvents("mouseDown") into temp2
  
Thanks for learning me some more LC Klaus! Really appreciate you taking the time.

Regards from the Netherlands,

Paul

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to block passthrough click with popup

Post by Klaus » Wed Mar 29, 2023 11:48 am

Graag gedaan, Paul! :-)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to block passthrough click with popup

Post by jacque » Wed Mar 29, 2023 6:15 pm

The simplest fix is probably to add a mouseUp blocking handler to the graphic.

Code: Select all

on mouseUp
end mouseUp 
If you don't want the user to click on the field either, then layer the graphic at the top of the card and set its blendlevel to 99. It will still catch and block mouse actions but will be virtually invisible to the user.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: How to block passthrough click with popup

Post by RCozens » Wed Mar 29, 2023 6:28 pm

mrcoollion wrote:
Wed Mar 29, 2023 10:23 am
What solution can I use to prevent users to click on buttons during the presentation of the popup field?
[\quote]
Hi,

How about setting the cursor to none when the popup opens and resetting it to arrow when it closes?

Rob
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

stam
Posts: 2600
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to block passthrough click with popup

Post by stam » Wed Mar 29, 2023 11:40 pm

mrcoollion wrote:
Wed Mar 29, 2023 10:23 am
What solution can I use to prevent users to click on buttons during the presentation of the popup field?
Hi Paul,
I'm afraid I'm rather sleep-deprived and haven't read the responses in depth. I can think of 2 approaches: one is the graphic element approach which think is already mentioned.
The other is that your popup field sits in a substack which you present as modal or sheet. This will block everything outside the substack until the substack is dismissed - not sure what feeds your needs best, but the modal substack approach may be simpler than coding a graphic to intercept mouse events...

S.

Post Reply

Return to “Talking LiveCode”