drag and drop a rectangle
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
drag and drop a rectangle
I need to drag and drop a rectangle from one place and copy it to another. How can I do this?
Mike
Mike
Re: drag and drop a rectangle
This has got to have jittery behavior, and you may need to set the opaque property, but you can always:
Click and drag. I bet you get more than you bargained for.
Craig Newman
Code: Select all
on mousedown
clone me
end mousedown
on mousemove
set the loc of the last graphic to the mouseLoc
end mousemove
Craig Newman
Re: drag and drop a rectangle
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
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
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:
Why change the properties in the mouseDown handler? Why mouseRelease instead of mouseUp?
Craig Newman
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
Craig Newman
Re: drag and drop a rectangle
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
Craig Newman
Re: drag and drop a rectangle

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
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
Craig Newman
Re: drag and drop a rectangle
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
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
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
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