Page 1 of 1

Snap Objects to Each Other

Posted: Sat Jan 25, 2014 2:45 pm
by endernafi
Hi folks,

This is not a question, rather an answer; well kinda 8)
Peter asked in the list for a solution to snap objects which are moved and/or resized.
Since, I don't use dropbox or any other file sharing service;
I found suitable to post the stack here.

Also, some of you may find my code useful.

It's not without drawbacks, actually there are many.
But it's a quick attempt, please feel free to change it in anyway or improve and use it.
snapButton.zip
(3.51 KiB) Downloaded 335 times
Best,

~ Ender Nafi

Re: Snap Objects to Each Other

Posted: Sat Jan 25, 2014 9:58 pm
by Peter Bogdanoff
Ender,

This is great. Thanks!!!!

I made modifications to the script (stack attached) for my particular application (I'm working with rows of buttons):

1. buttonActive snaps to buttonListener--buttonListener never moves
2. Once snapping has occurred, buttonListener still doesn't move
3. I've removed the snapping to tops and bottoms--I don't want that for what I'm doing

Now, can there be multiple listening buttons? I'm thinking that while the active button is being dragged, it periodically checks a list of possible listening buttons to see if any one of them has met the close enough criteria--then designates that one as the listener.

Peter

Re: Snap Objects to Each Other

Posted: Sat Jan 25, 2014 10:53 pm
by bn
Hi Ender,

this is a beautiful stack, thank you. Lots of good stuff in it.

Kind regards
Bernd

Re: Snap Objects to Each Other

Posted: Sun Jan 26, 2014 9:08 am
by endernafi
Bernd,
That's very kind of you, thanks.
I know it's a bulky code but that's me learning day by day.

Peter et al.,

I added functionality for multiple listeners.
It wasn't an easy task, at least for me; but it's fun to deal with it 8)

There are still many issues, feel free to dive in to pinpoint and hopefully fix them.
Check the comments for those which I've noticed.
Btw, I've changed the stack's name to a cooler one ;-)

This is for general use:
magnetObjects.zip
(7.36 KiB) Downloaded 347 times
And this is for Peter, adjusted for that 3 items above:
snapButton_multipleListeners_forPeter.zip
(7.05 KiB) Downloaded 302 times
This is just a stripped out and a bit altered version of magnetObjects.

Peter,
I wouldn't use that code as it is.
Since it's an alteration of the above stack, it has more issues.
Try creating a dedicated script for your needs using my script's concept.
That is if you find it useful 8)


Hope it helps some of you...

Best,

~ Ender Nafi

Re: Snap Objects to Each Other

Posted: Sun Jan 26, 2014 10:21 pm
by jmburnod
Hi Ender,
Simple, elegant... Epicurian

Congratulation

kind regards

Jean-Marc

Re: Snap Objects to Each Other

Posted: Mon Jan 27, 2014 5:23 am
by endernafi
Epicurean?
That made my day, thank you 8)

The problem is, Jean-Marc,
that I never was able to get things done in 100%.
Even in my school years, my grades were 85 ~ 95 {that's B+ in US system, I guess}.
No less, no more.

This stack isn't different in these manners.
Making something absolutely perfect requires just too much effort and IQ ;-)


~ Ender

Re: Snap Objects to Each Other

Posted: Thu Jan 30, 2014 6:54 pm
by jmburnod
Hi Ender,
that I never was able to get things done in 100%.
It is often difficult to decide when the application is finished
I suspect it is also accept that it is not perfect yet
You may see an example about wide checkbox in this thread
http://forums.runrev.com/phpBB2/viewtop ... 49&t=14346

Best regards
Jean-Marc