Grab (drag an object) only within specific area?

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

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 222
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK

Grab (drag an object) only within specific area?

Post by thatkeith » Mon Dec 18, 2017 10:34 pm

I'd like to have the user grab and drag a simple object across the card, but constrained to move in just one plane and also within a specific span. Specifically, a vertical line, dragged horizontally across an image, so the user can specify where North is in the image.

In SuperCard I'd probably use 'grab', as in

Code: Select all

grab me within the rect of cd grc "photo"
But of course LiveCode's 'grab' is slightly different. Can anyone point me towards the right way to achieve this here?

k
Senior Lecturer, LCC (University of the Arts London)
Technical Editor, MacUser (1996-2015)
President, IVRPA.org

bogs
Posts: 2068
Joined: Sat Feb 25, 2017 10:45 pm

Re: Grab (drag an object) only within specific area?

Post by bogs » Mon Dec 18, 2017 10:52 pm

Huh, without having actually tried it, that looks correct to me. If no one fills it, I'll test it later.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6103
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Grab (drag an object) only within specific area?

Post by FourthWorld » Mon Dec 18, 2017 11:27 pm

I don't believe LC has added a "within" clause, though Jacque has requested something along those lines:
http://quality.livecode.com/show_bug.cgi?id=4890
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2219
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Grab (drag an object) only within specific area?

Post by jmburnod » Mon Dec 18, 2017 11:40 pm

Hi thatkeith,
Here is a thread about this
http://forums.livecode.com/viewtopic.ph ... t&start=15
and a stack "stMoveControlInsideRect001" here:
http://forums.livecode.com/download/file.php?id=7938
Best regards
Jean-Marc

bogs
Posts: 2068
Joined: Sat Feb 25, 2017 10:45 pm

Re: Grab (drag an object) only within specific area?

Post by bogs » Mon Dec 18, 2017 11:55 pm

FourthWorld wrote:
Mon Dec 18, 2017 11:27 pm
I don't believe LC has added a "within" clause, though Jacque has requested something along those lines:
http://quality.livecode.com/show_bug.cgi?id=4890
Actually, there is a within clause Introduced: 1.0, however I think they work slightly differently - and a lot more -
Image
Lc Dictionary wrote:Summary:
Evaluates to true if a point is inside the specified rectangle, false if it is outside.
Examples:
"22,33" is within "22,17,150,200" -- evaluates to true
the mouseLoc is within the rect of this stack

Use the is within operator to determine whether a point is inside a rectangle.
And Jm came up with that quick, good thread.
Image

bogs
Posts: 2068
Joined: Sat Feb 25, 2017 10:45 pm

Re: Grab (drag an object) only within specific area?

Post by bogs » Wed Dec 20, 2017 3:43 am

You know, as I thought about this more, a much MUCH simpler solution came to me. Why not just set the picture into a group with its size locked, and a horizontal scroll bar? you could overlay the line on top of the group, moving the scrollbar automatically moves the picture, and it looks just as you described.
Image
Image

Post Reply

Return to “Talking LiveCode”