Stop 'grab me' when object gets outside of another object

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

Post Reply
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Stop 'grab me' when object gets outside of another object

Post by croivo » Fri Feb 06, 2015 6:24 pm

I have a button inside big graphic rectangle. Button has 'grab me' command so when user click on it, he can move the button. But what I want to do is when that button reaches the outside of that rectangle, the grab command stops (so user can't move the button any further from the borders of that rectangle graphic).

I figured out how I can see when the button is outside of the border, but I have no idea how to stop that 'grab me' command when it's outside. Any ideas?

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

Re: Stop 'grab me' when object gets outside of another objec

Post by Klaus » Fri Feb 06, 2015 7:31 pm

Hi croivo,

the trick is to NOT use "grab me" :D

Check Scotts website for a wonderful demo stack:
http://www.tactilemedia.com
Topright click -> Software
Topright click -> See all tutorials >>
Scroll down to -> Drag sampler

And the rest of the stacks aren't too shabby, too! :D


Best

Klaus

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Stop 'grab me' when object gets outside of another objec

Post by croivo » Fri Feb 06, 2015 8:26 pm

Exactly what I'm looking for! Thanks!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10102
Joined: Fri Feb 19, 2010 10:17 am

Re: Stop 'grab me' when object gets outside of another objec

Post by richmond62 » Fri Feb 06, 2015 8:33 pm

Certainly with GRAB you are going to have some problems.

If you try to drag the red blob in my example, you will
be able to drag it outwith the circle. If you mouseUp while any of it
is touching any of the blue border it will be subsequently immovable.
draggy.livecode.zip
(890 Bytes) Downloaded 257 times
Last edited by richmond62 on Sat Feb 07, 2015 2:10 pm, edited 1 time in total.

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Stop 'grab me' when object gets outside of another objec

Post by croivo » Sat Feb 07, 2015 2:06 am

Got it, thanks richmond62!

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Stop 'grab me' when object gets outside of another objec

Post by croivo » Sat Feb 07, 2015 2:11 am

Let me ask another question in this topic... So when user is dragging the button, I want buttons to snap to the 2 graphic lines if the button is 30px far from that line.
Here is sketch:
Capture.PNG
Capture.PNG (4.55 KiB) Viewed 4354 times
I used this code:

Code: Select all

put the mouseloc into mouseLocation
   if (item 1 of mouseLocation < the left of graphic "vLine" + 40) and (item 1 of mouseLocation > the left of graphic "vLine" - 40) then
      put the width of me into myWidth
      divide myWidth by 2
      set the left of me to (the left of graphic "vLine" - myWidth)
   else if (item 2 of mouseLocation < the top of graphic "hLine" + 40) and (item 2 of mouseLocation > the top of graphic "hLine" - 40) then
      put the height of me into myHeight
      divide myHeight by 2
      set the top of me to (the top of graphic "hLine" - myHeight)
   else
   end if
However, that doesn't looks like best solution... It's all laggy :(

Post Reply