Page 1 of 1

Constraining a dropped object

Posted: Sun Sep 11, 2016 1:12 pm
by ThomasPaine
Hi all, I'm new to LiveCode and was hoping you may be able to point me in the right direction.

I'm trying to make a simple desktop app where the user can drag items from a palate onto a window but the dragged item would need to be a child (contained within) an existing object in the window. For example, the user may drag an image or button on to a rectangle on a calendar (representing a day of the week) but the dropped object should be constrained within the rectangle.

I have been able to get the drag and drop portion working but am unsure how to get the dropped object to stay in the rectangle.

Another issue I'm having is that I will need to iterate through the child objects for any given date but I don't know how I would reference the relationship.

I have looked for examples but have not found anything that would establish a parent/child relationship between the objects.

Any help or example stacks I may have missed would be appreciated.

Re: Constraining a dropped object

Posted: Sun Sep 11, 2016 2:42 pm
by dunbarx
Hi,

Try this to see if it can be of use: On a new card make two fields and THEN a button. Make each field a little larger than the default size.Separate all the controls. In the card script:

Code: Select all

local tControlMoved

on mouseMove
   put the target into tControlMoved
   if the mouse is down then set the loc of tControlMoved to the mouseLoc
end mouseMove

on mouseUp
   repeat with y = 1 to the number of controls
      if the loc of tControlMoved is within the rect of control y then
         set the loc of tControlMoved to the loc of control y
      end if
   end repeat
end mouseUp
Not sure how you are currently dragging stuff from your palette, but for this experiment, click and hold on the button and drag it to the interior of a field. Release the mouse.

This surely needs a bit of refinement, perhaps lo limit the action to the last control created, or whatever, or to lock out such mobility to certain other controls. But that is the fun part.


Craig Newman

Re: Constraining a dropped object

Posted: Sun Sep 11, 2016 3:43 pm
by ThomasPaine
Great, thanks Craig, I'll give that a shot.

I also just found the Sodoku game in the sample stacks witch has the basic functionality I'm looking through that code as well.

Thanks again for your help

Re: Constraining a dropped object

Posted: Sun Sep 11, 2016 7:06 pm
by dunbarx
Something to play with.

What would happen if you made two buttons instead of one, and did not rename either?

Craig