trash bin like feature

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

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

Re: trash bin like feature

Post by dunbarx » Sun Mar 10, 2013 6:07 pm

This is a good question, Newbie, and one that calls for experimentation.

"is within" is an operator, and pertains to a point in relation to a rect
"within" is a function, and pertains to a point in relation to an object. That said, it is the rect of the object that ultimately matters, and so you might consider them very similar, likely calling the same internal code.
"intersect" pertains to object rects as a whole, where one portion of a rect may overlie any portion of another. It can be viewed as "if even one point of one object is within the rect of another object".

Craig Newman

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: trash bin like feature

Post by jacque » Sun Mar 10, 2013 8:51 pm

Newbie4 wrote:Does it matter if you use the "intersect" function, "is within" or the "within" function for testing if the object is in the trashcan?
It doesn't matter really, the main thing is to avoid repeat loops in this kind of situation. Here is how I would do it:

Decide on a way to determine if an object is draggable. It can be a naming convention, a custom property, using a particular button type, or anything else. Put generic mouseDown and mouseUp handlers in the card. The handlers check to see if the object is draggable and handle the action if they are.

This is the cleanest way to do it because there are no repeat loops. Rule of thumb is to always use engine messages whenever possible. Here's a generic skeleton. These handlers assume that every draggable object is a button whose name begins with "drag-", but you can use any kind of test to see if the object is something that can be moved.

Code: Select all

on mouseDown
  if the short name of the target begins with "drag-" then
    grab the target
  end if
end mouseDown

on mouseUp
  if the short name of the target begins with "drag-" and \
      the mouseloc is within the rect of btn "trash" then
    -- do trash things
  end if
end mouseUp
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply