lock objects from being dragged out of the screen
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
lock objects from being dragged out of the screen
hi!
i have an app in which the user can move object around. what will be the most efficient way of preventing them from dragging the object out of the screen?
tnx
tomer
i have an app in which the user can move object around. what will be the most efficient way of preventing them from dragging the object out of the screen?
tnx
tomer
-
- VIP Livecode Opensource Backer
- Posts: 9665
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: lock objects from being dragged out of the screen
Hi.
How are you moving the objects around?
In any case, the "mouseMove" message is sent whether in edit or run mode, so you could (pseudo):
Silly, eh? But can you take it from there? To check either the mouseLoc in relation to the edges of the card, or, if you want to get fancy (and I always recommend fancifulness) check the edges of the object in relation to the edges of the card. The "target" is your friend here.
Write back with your fancies.
Craig Newman
How are you moving the objects around?
In any case, the "mouseMove" message is sent whether in edit or run mode, so you could (pseudo):
Code: Select all
on mouseMove
put the target
if the mouseLoc is beyond the borders of this card then do not allow this to happen
end mouseMove
Write back with your fancies.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: lock objects from being dragged out of the screen
Hi,
You may define a rect and test if all points of your control is within this rect at mousemove
Best regards
Jean-Marc
You may define a rect and test if all points of your control is within this rect at mousemove
Best regards
Jean-Marc
https://alternatic.ch
Re: lock objects from being dragged out of the screen
Learning to do this yourself is the best idea, but Animation Engine includes some very nice features including constraints to location.
Re: lock objects from being dragged out of the screen
i am moving the object with:
where should i put this code that u wrote? in the card script?
Code: Select all
grab me
Code: Select all
on mouseMove
put the target
if the mouseLoc is beyond the borders of this card then do not allow this to happen
end mouseMove
-
- VIP Livecode Opensource Backer
- Posts: 153
- Joined: Thu Jun 29, 2006 4:16 pm
Re: lock objects from being dragged out of the screen
Try something like this in the script of the object you’re moving:
local tStartLoc
on mouseDown
put the loc of target into tStartLoc
grab me
end mouseDown
on mouseUp
if the loc of target is not within the rect of this card then
move target to tStartLoc
end if
end mouseUp
local tStartLoc
on mouseDown
put the loc of target into tStartLoc
grab me
end mouseDown
on mouseUp
if the loc of target is not within the rect of this card then
move target to tStartLoc
end if
end mouseUp
Re: lock objects from being dragged out of the screen
Hi Tomerp,
what Randy wrote!
Important hint:
Best
Klaus
what Randy wrote!
Important hint:
PSEUDO in this case means, this is what it should do, but is really NOT the actual script!.. so you could (pseudo):
Best
Klaus
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: lock objects from being dragged out of the screen
I did it DIFFERENTLY . . . .
Stack removed as updated, improved version uploaded.
Last edited by richmond62 on Fri May 12, 2017 7:24 pm, edited 1 time in total.
Re: lock objects from being dragged out of the screen
You ALWAYS do it differently!
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: lock objects from being dragged out of the screen
This version allows one to resize the stack . . . .
-
- VIP Livecode Opensource Backer
- Posts: 327
- Joined: Sun Apr 15, 2012 1:17 am
- Location: USA
- Contact:
Re: lock objects from being dragged out of the screen
...and if you want it to work for any size card, you can generalize the tests for right and bottom. (other than an 800x600 sized card in Richmond's example)
give the card a name (e.g. "main") and modify the code to check for instead of just .
and the instead of 600.
give the card a name (e.g. "main") and modify the code to check for
Code: Select all
... > the right of card "main"
Code: Select all
... > 800
and the
Code: Select all
... > the bottom of card "main"
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
- VIP Livecode Opensource Backer
- Posts: 327
- Joined: Sun Apr 15, 2012 1:17 am
- Location: USA
- Contact:
Re: lock objects from being dragged out of the screen
RATS,
I tried to get there with a more universal solution before you did (Richmond). But I went back to edit it and while I was editing it, you uploaded your new stack. So your time stamp was earlier than mine.
I like your idea of using variables for the right and bottom locations. It makes the code simpler reading.
Good job, nice example
I tried to get there with a more universal solution before you did (Richmond). But I went back to edit it and while I was editing it, you uploaded your new stack. So your time stamp was earlier than mine.
I like your idea of using variables for the right and bottom locations. It makes the code simpler reading.
Good job, nice example
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: lock objects from being dragged out of the screen
That's because I really don't understand complex code.It makes the code simpler reading.
-
- VIP Livecode Opensource Backer
- Posts: 327
- Joined: Sun Apr 15, 2012 1:17 am
- Location: USA
- Contact:
Re: lock objects from being dragged out of the screen
Yes, I do too but sometimes when teaching newbies, you have to step through the process in logical steps (as you help them think thru it) Some people can not make the jump to the better code in one step.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: lock objects from being dragged out of the screen
To understand what happens when the stack is resized, and so that
the TROLL doesn't "get lost" when it is resized, you need to look at
the stackScript:
the TROLL doesn't "get lost" when it is resized, you need to look at
the stackScript: