how to make a whole group into a target

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

how to make a whole group into a target

Post by kaveh1000 » Thu Jan 10, 2019 12:02 am

I have a group with several different controls. I want to make the whole rectangle into a target, so clicking anywhere will send a message to the group. I can't find a way of doing that except to put a button as a backdrop. But that has other complications.

Any way of ensuring the whole area of a group is clickable?
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to make a whole group into a target

Post by dunbarx » Thu Jan 10, 2019 4:11 am

Hi.

I suspect there is a more straightForward way to do what you want, but you can always use native LiveCode behavior. In the card script:

Code: Select all

on mouseUp
  if the clickLoc is within the rect of grp "yourRecalcitrantGroup" then answer random(99)
end mouseUp
Craig Newman

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: how to make a whole group into a target

Post by trevordevore » Thu Jan 10, 2019 5:18 am

@Kaveh - A group won't receive mouse event messages. You would need to add a transparent button or graphic in order for clicks to to send message like mouseUp. While not ideal, this approach does allow you to put your mouseUp/mouseDown/whatever message in the group script.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: how to make a whole group into a target

Post by kaveh1000 » Thu Jan 10, 2019 8:00 am

Thanks Craig and Trevor

I ended up putting a transparent button behind the other controls. That way mouse messages can be sent directly to each control in the field, but then trapped by the back button if not caught by others.

What would the advantage be to having the transparent button in front?
Kaveh

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

Re: how to make a whole group into a target

Post by Klaus » Thu Jan 10, 2019 10:43 am

kaveh1000 wrote:
Thu Jan 10, 2019 8:00 am
What would the advantage be to having the transparent button in front?
That would eat up ALL mouse-events, and gladly noone proposed this so far! 8)

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: how to make a whole group into a target

Post by kaveh1000 » Thu Jan 10, 2019 10:48 am

Ah, I should read posts more carefully. I thought Trevor was suggesting a button on top. My error and my confusion. Thanks all. :-)
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to make a whole group into a target

Post by dunbarx » Thu Jan 10, 2019 9:01 pm

Many ways to do this. Know that if you move the group you also have to move the button, unless you have placed that button within the group itself. It was not clear to me that you had done so.

There was a thread a while back wondering if the empty space within the rect of a group might be allowed to react to a mouse click. This is exactly what you are talking about here.

Craig

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: how to make a whole group into a target

Post by kaveh1000 » Thu Jan 10, 2019 9:09 pm

Hi Craig

Indeed I put the button inside the group. I am hiding and showing different elements of the group so the size changes. I have put several sizes in the custom properties of the button, so just call those as needed. Looking ok.

I think an option to have a "backdrop" to a group would make logical sense.

Regards
Kaveh
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to make a whole group into a target

Post by dunbarx » Thu Jan 10, 2019 9:22 pm

What would the advantage be to having the transparent button in front?
What Klaus said.

The kluge to fix that, since such a button would indeed intercept all messages, would be to:

Code: Select all

on mouseUp
  send "mouseUp" to grp "yourUnderLyingGroup"
But we want to minimize kluges if possible, though sometimes they allow us to have it our way.

Do you like that way better than the card script handler I proposed? I only ask because they are both kluges. In one, the card reacts to a mouse click, and checks the rect of the group, and in the other, the button reacts; they both, you might say, underlie the group, and trap those messages that pass right through.

I think a group, which is natively invisible (apart from its child controls), ought to be able to be merely transparent.

Craig

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: how to make a whole group into a target

Post by kaveh1000 » Fri Jan 11, 2019 9:29 am

Hi Craig. It's great there are so many ways to fix things in LiveCode. I do like your method. For the moment the "backdrop" seems to be working ok...
Kaveh

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: how to make a whole group into a target

Post by Fermin » Thu Apr 01, 2021 5:43 pm

I don't know if it has to do exactly with this topic but:
In an app I'm making to create calendars I have a group containing 42 boxes (graphic objects). In the script of the group:

on mouseup
answer me & cr & the target
end mouseup
---
The result when clicking anywhere in the group is:

group "esp_b01GrupoParri"
graphic "cas_b01f24"

The name of the graphic depends on which box I have clicked on.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to make a whole group into a target

Post by dunbarx » Thu Apr 01, 2021 7:14 pm

Hi.

Not exactly sure what the question is, but when you ask for "me" you are asking for the contents of a control, This could be the text of a field, or even a button. But a graphic is not a container, and you will not get much asking for what it, er, contains.

With that line of code, when you click on a graphic, you will get its owner and its name. If the graphic was not owned by a group, you would get the card and its name.

So the question is this: what do you really want LC to send back to you when you click on a graphic?

Craig

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: how to make a whole group into a target

Post by Fermin » Thu Apr 01, 2021 8:09 pm

Well, it wasn't really a question. What happened is that I had read above:
A group won't receive mouse event messages. You would need to add a transparent button, etc...

and I only meant to comment that, in my experience, a group can receive messages... But I guess the subject of the post is a bit more complex and I didn't quite understand it. Anyway thanks, Craig, for your explanation. :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to make a whole group into a target

Post by dunbarx » Thu Apr 01, 2021 8:42 pm

OK, I see.

It is important to know, I guess, that a group is only a group on paper; it is not an object in its own right. That is, empty space in a group is just that, empty space.

This is slightly odd because a group has an "opaque" property, and you can color that empty space as you like. But any colored empty area still does not quite seem to exist.

But even a load of empty space still has a rect. So I still think that the idea of checking to see if the clickLoc is within that rect is a nice kludge.

Craig

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

Re: how to make a whole group into a target

Post by jacque » Fri Apr 02, 2021 5:58 pm

dunbarx wrote:
Thu Apr 01, 2021 7:14 pm
when you ask for "me" you are asking for the contents of a control, This could be the text of a field, or even a button.
Almost. "Me " refers to the control whose script is referring to "me". It doesn't deal with the contents of that control, just its identity.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Talking LiveCode”