Boxes, Grids, & Snap to Objects

David Vaughan drvaughan55 at mac.com
Tue Feb 19 23:18:00 EST 2002


Roger

This is not comprehensive, in that I tackled only to the "else" 
statement, the drag, but I am sure you can have another go at move if 
need be.

I recognise also that you have not dealt with overlapping yet, but 
revise what you have in the light of comments and try to extend the 
approach. You are welcome back for more help of course.

Actual comments below.

regards
David

On Tuesday, February 19, 2002, at 11:06 , Roger.E.Eller at sealedair.com 
wrote:

>
> Hi,
>
> My latest programming adventure requires the following:
>
>      1 - A rectangle graphic that represents the boundery.  800 x 500
> pixels in size.
>
>      2 - Several (3-8) smaller rectangles (or buttons) that must be 
> moved
> using the browse tool.  Various Sizes, but must snap to a grid or other
> objects.
>
>      3 - The smaller rectangles should MOVE if clicked near the top left
> edge, but are not allowed outside the large rectangle.
>
>      4 - The smaller rectangles can be RESIZED if clicked near the 
> bottom
> right, but are not allowed outside the large rectangle.
>
>      5 - The smaller rectangles are not allowed to overlap each other.
>
> My script follows...  I have achieved some of the requirements, but I 
> would
> like some guidance from the experts (that's you).
>
> Thank you in advance for any suggestions.
> ~Roger Eller  <roger.e.eller at sealedair.com>
>
> ----------------------------------
>
> on mouseDown
>   set the cursor to plus
>   set the numberFormat to 0.0
-- not sure why
>   set the itemDelimiter to ","
-- It already is when you enter the script. Better to change it only 
when you need to.
>   put the Width of me into WidthOfBox
>   put the Height of me into HeightOfBox
-- You do not use these variables again, but they have a use...see below.
>
>   -- Determine the section of me that was clicked
>   if item 1 of the mouseloc <= (item 1 of the bottomRight of me)-((the
> width of me)/2) then
>
>     grab me -- Move me
>
>     put the rect of me into myNewRect -- Get the old size
-- Once you have newRect, it is very slightly quicker to use it rather 
than repeatedly getting the property, hence:
put item q of myNewRect into myLeft
-- etc
>     put item 1 of the rect of me into myLeft
>     put item 2 of the rect of me into myTop
>     put item 3 of the rect of me into myRight
>     put item 4 of the rect of me into myBottom
-- but why bother, if you never use them again anyway? Just handle 
myNewRect and
--  the box widths which you captured up the top. Read on.
>
-- The following can also be done by reference to the variable rather 
than repeated property gets.
-- However, better to do it outside mouseDown (e.g. on openCard or a 
preOpen) since you do not
--  indicate that it changes at any time, and this is being executed 
repeatedly on mouseStillDown.
>     put the rect of graphic "theBigBox" into myBigBox
>     put item 1 of the rect of graphic "theBigBox" into BigBoxLeft
>     put item 2 of the rect of graphic "theBigBox" into BigBoxTop
>     put item 3 of the rect of graphic "theBigBox" into BigBoxRight
>     put item 4 of the rect of graphic "theBigBox" into BigBoxBottom
>
>     if myLeft < (BigBoxLeft+5) then
>       put BigBoxLeft into item 1 of myNewRect
-- this and the corresponding next statement will change the size of the 
object because you are
--  changing only the top and left. Set the top and left as you do but 
then set the right and bottom by
--  adding WidthOfBox and HeightOfBox to items 1 and 2 of myNewRect to 
create items 3 and 4.
>     end if
>     if myTop < (BigBoxTop+5) then
>       put BigBoxTop into item 2 of myNewRect
>     end if
>
>     set the rect of me to myNewRect -- Set the new size

-- all yours for the next half... :-)
>
>   else -- Change the Size of me
>
>     put the rect of me into myNewRect -- Get the old size
>
>     put round((item 1 of the mouseLoc)/10) into myLeft
>     put round((item 2 of the mouseLoc)/10) into myTop
>
>     put myLeft*10 into myLeft
>     put myTop*10 into myTop
>
>     put myLeft into item 3 of myNewRect
>     put myTop into item 4 of myNewRect
>
>     set the rect of me to myNewRect -- Set the new size
>   end if
> end mouseDown
>
> on mouseStillDown
>   mouseDown
> end mouseStillDown
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list