Is a selection rectangle possible?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

M-A Kuttner
Posts: 50
Joined: Mon Apr 03, 2017 3:55 pm

Is a selection rectangle possible?

Post by M-A Kuttner » Thu Nov 17, 2022 7:04 pm

I'm curious to know if anyone's been able to simulate a selection rectangle where multiple objects can be selected as long as they're within or touching the selection bounds, even if they've never been touched by the mouseLoc. I know about selectionMode with the pointer tool, but I'm wondering about something that would work in browse mode.
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 7:31 pm

Hi.

Maybe something like:

Code: Select all

on mouseUp
   ask "Select rectangle"
   
   --repeat with y = 1 to the number of controls
    --  if the left of control y >= item 1 of it and the right of control y <= item 3 of it and\
            --the top of control y >= item 2 of it and the bottom  of control y <= item 4 of it then put y & return after accum
  -- end repeat
  
  --repeat with y = 1 to the number of lines of accum
  --select each control from that list
   
   choose pointer tool
   drag from item 1 to 2 of it to item 3 to 4 of it

end mouseUp
Craig
Last edited by dunbarx on Thu Nov 17, 2022 7:40 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 7:34 pm

I first though of collecting the several controls that fall within the bounds of the chosen rect, and selecting them all in turn.That is what is going on in that repeat loop.

But it seems like only the last one on such a list actually remains selected. So the best method is to change tools and simulate a drag over the chosen bounds. You only need to:

Code: Select all

on mouseUp
   ask "Select rectangle"
   choose pointer tool
   drag from item 1 to 2 of it to item 3 to 4 of it
end mouseUp
Craig
Last edited by dunbarx on Thu Nov 17, 2022 7:39 pm, edited 4 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 7:36 pm

Did you want to actually "see" a selection rectangle? That is simple as well, but only lagniappe.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Is a selection rectangle possible?

Post by FourthWorld » Thu Nov 17, 2022 7:44 pm

Your can emulate the built-in Pointer tool, and I've had to do it on occasion. But it always feels like I'm cheating myself to spend time emulating a built-in feature.

Are you in a position to describe what you're working on and how the emulated Pointer tool fits in?

Sometimes there's a way to use the Pointer tool directly, without emulating it, and still keep all the advantages of the Browse tool where that different mode is needed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Is a selection rectangle possible?

Post by Klaus » Thu Nov 17, 2022 7:50 pm

dunbarx wrote:
Thu Nov 17, 2022 7:36 pm
... but only lagniappe.
What on earth does that mean? My Mac contextmenu (translate) tells me it does not support Norwegian. :shock:

Or is it something like covfefe? :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 7:59 pm

@Richard.
Your can emulate the built-in Pointer tool,
Like I did? :wink:

@ M-A Kuttner

I assume you know that the ask dialog expects four integers separated by commas, and that they make sense in terms of a real rect.

Another thing, that touches on Richard's post, is to have that pointer tool actually drag at a rate that is visible to the user. In that way the selection rectangle that it natively shows when done by hand would, er, show. With my handler, it all happens so fast that you cannot see it. I am not sure how to do this just now, since the drag command has no rate parameter similar to, say, the move command.

To further kludge this, assuming you need it, is to create, say, a transparent graphic with a dashed border. You can resize it from the topRight to the bottomLeft at any rate you like, and you already have the data needed to select the controls within.

What do you think?

Craig
Last edited by dunbarx on Thu Nov 17, 2022 8:04 pm, edited 2 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 8:03 pm

Klaus.

Norwegian???

I means something added as a bonus, but not really important to the thing in question.

This is mainly heard in New Orleans, where it might be literally eaten as icing on a Beignet.

How are you with Beignet? :D :D

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Is a selection rectangle possible?

Post by Klaus » Thu Nov 17, 2022 8:10 pm

Yep, Norwegian, see screenshot...
OK, thanks! :-)
"Beignet" is a pastry, right?
Bildschirmfoto 2022-11-17 um 20.09.39.png

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 8:12 pm

I just remembered the property "dragSpeed" Watch this space...

Craig
Last edited by dunbarx on Thu Nov 17, 2022 8:16 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 8:14 pm

HA!

Code: Select all

on mouseUp
   ask "Select rectangle" with "100,100,300,300"
   choose pointer tool
   set the dragSpeed to 400
   drag from item 1 to 2 of it to item 3 to 4 of it
end mouseUp
HA!!

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Is a selection rectangle possible?

Post by dunbarx » Thu Nov 17, 2022 8:20 pm

Klaus.
"Beignet" is a pastry, right?
Sort of.

It is very similar to an Italian "Zeppole". In the US, such a thing (fried dough, really) is best with confectioners sugar ALL over it. You know, lagniappe.

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Is a selection rectangle possible?

Post by Klaus » Thu Nov 17, 2022 8:30 pm

dunbarx wrote:
Thu Nov 17, 2022 8:20 pm
...You know, lagniappe.
Yes, I know! :D

M-A Kuttner
Posts: 50
Joined: Mon Apr 03, 2017 3:55 pm

Re: Is a selection rectangle possible?

Post by M-A Kuttner » Thu Nov 17, 2022 9:12 pm

Thanks guys! The project is that I have a large field of small rectangle graphics butted up against one another, and I want to select any subset of them within the larger field so as to access the names of each. However, I don't want to reposition any of them.

As for Beignets, I got a chance to have some in New Orleans one evening when I visited, along with that great coffee. Mmmm...
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Is a selection rectangle possible?

Post by FourthWorld » Thu Nov 17, 2022 9:13 pm

dunbarx wrote:
Thu Nov 17, 2022 7:59 pm
@Richard.
Your can emulate the built-in Pointer tool,
Like I did? :wink:
Maybe I misread that, but it looked like you used the built-in Pointer tool, emulating the user's gesture to drag the selection.

I had the impression that the OP was looking to provide an interactive experience similar to the pointer tool, but using the Browse tool. I may have misunderstood his request. I look forward to his return to clarify.

If the goal is to demonstrate a user-like behavior using the built-in tools, your method is a good one. But if the goal is to select objects, one can just set the selected property of objects within the loop directly, using whatever logical or spatial criteria is needed.

Providing interactive Pointer tool behavior with the Browse tool is doable, but complicated. One of the many godsends of tools like SuperCard and LiveCode is that we have a Pointer tool at the ready. Emulating it requires making and managing some form of selection bounds indicator, tracking mouseMove to check intersection of objects, and creating some form of indicator for each object to reflect the selected state. I've had to do that before, as have Ken Ray and others, but it was a lot of work for the engine team to build in, and is a lot of work for a scripter to reproduce.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply