Page 1 of 1

drag and drop a rectangle

Posted: Thu Aug 11, 2011 12:51 am
by admin12
I need to drag and drop a rectangle from one place and copy it to another. How can I do this?

Mike

Re: drag and drop a rectangle

Posted: Thu Aug 11, 2011 2:26 am
by dunbarx
This has got to have jittery behavior, and you may need to set the opaque property, but you can always:

Code: Select all

on mousedown
   clone me
end mousedown

on mousemove
   set the loc of the last graphic to the mouseLoc
end mousemove
Click and drag. I bet you get more than you bargained for.

Craig Newman

Re: drag and drop a rectangle

Posted: Thu Aug 11, 2011 2:42 am
by admin12
Craig,

Thanks. It works - kind of. I like the idea of placing multiple copies, but it has to be bounded to the track - namely, I cannot drop the rectangle outside the track (the rectangle is 80x40 and the track has a height of 45). I also need to implement snap to so that each rectangle snaps to the next one.

The current code lets me place a bazillion rectangles with no way to stop it except deleting them all. I need to place one copy at a time.

Any ideas?

Mike

Re: drag and drop a rectangle

Posted: Thu Aug 11, 2011 5:03 pm
by dunbarx
You have to promise to play around with these scripts, because that is the only way to learn. I am having more fun than you are; this has to change.

Make a rectangle, name it "R1". Make it opaque. Place this in its script:

Code: Select all

on mouseDown
   clone me
   set the script of the last grc to ""
   set the name of the last grc to ""
end mouseDown

on mouseMove
   if the short name of the last grc is not "r1"  then  set the loc of the last grc to the mouseLoc
end mouseMove

on mouserelease
     set the topLeft of the last grc to the botRight of me
end mouserelease
Why change the properties in the mouseDown handler? Why mouseRelease instead of mouseUp?

Craig Newman

Re: drag and drop a rectangle

Posted: Thu Aug 11, 2011 7:12 pm
by dunbarx
What sort of "track" are you working with? What is its shape" Is it that you want the user to be constrained within its boundaries as he drags? These are easy and fun to program.

Craig Newman

Re: drag and drop a rectangle

Posted: Thu Aug 11, 2011 7:30 pm
by admin12
Image

Don't know why the picture is cut off, but whatever - it shows enough.

The icons top and bottom are from the Aspen set - I will be making those a bit smaller because they are too large as is.

Note the track - note the line after the volume and pan sliders. The blox need to be dragged from the bin (the four colorful blox) to the track(s).

BTW, I also need help figuring out how to allow the area where you drag and drop the blox to scroll - I have had ZERO luck making groups scrollable.

I would prefer to scroll the entire track area instead of each individual track - such that you can see all the tracks when you horizontally and vertically scroll.

Mike

Re: drag and drop a rectangle

Posted: Thu Aug 11, 2011 8:18 pm
by dunbarx
You should be able to restrict the vertical loc of the newly formed rectangle within the limits of the track. Do you see several ways to do this? if not, write back.

Craig Newman

Re: drag and drop a rectangle

Posted: Thu Aug 11, 2011 9:21 pm
by admin12
Not sure. I have to study the loc command and see how I can use it.

The area where the block will be released is a data grid set to form - is that a good or poor decision? If it is a poor one, what should I use instead?

Mike

Re: drag and drop a rectangle

Posted: Fri Aug 12, 2011 4:18 am
by dunbarx
The mouseMove handler is having the loc of the graphic track the mouseLoc. Locs are formatted as two integers separated by a comma. For example, "100,200". The separate elements of that value are addressable, for example, "the top of button "yourButton" & "," & 200. Do you see? This particular loc is composed of a property of an object (its top) and an integer. Both elements are ultimately resolved to two integers. But the possibilities should be intriguing.

So if you think of the dragged rectangle tracking the mouseLoc, you can see that you could also have it track the X component of the mouseLoc and a fixed value. In this way it would be constrained vertically:

set the loc of the last graphic to item 1 of the mouseLoc & "," & the top of graphic "upperBound".

See? You simply have to play with real LC objects. And read up on everything the dictionary returns when you type "loc". Do you know what an "item" is? You need to put in the hours. Your sample stack looks very inviting; you have its construction down nicely. You need the guts. I work in precisely the opposite way.

Craig Newman