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: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 189
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: 5892
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: 947
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 - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 189
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: 10809
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: 189
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: 5892
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: 189
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: 5892
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: 189
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

Post Reply

Return to “Talking LiveCode”