Boxes, Grids, & Snap to Objects

Ian Summerfield iansummerfield at btconnect.com
Tue Feb 19 04:21:01 EST 2002


I don't like the grab command,  it seems to me program flow doesn't stop,
i.e.

Grab me
Beep

Will beep immediately even though you're still dragging the thing around the
screen.  This means you'll need to use a mouseup handler to do the new
location stuff instead.

I find it much better to hide the cursor, and set loc of the object needing
dragging to the mouseloc,  this is done in a "repeat while the mouse is
down" loop and lets me do clever things,  I can check if the mouseloc is
within the bounds of another object, and if so hilite that object, etc.
It's much more flexible.

I can send you an example of a system I've just written to drag flags onto a
scale representing the time,  it's a bit like dragging tab stops onto a
ruler,  as you hit the ruler/scale the flags snap on and slide left/right,
if you pull them too far out of the bounds it will break them free again
leaving you to drag them all over the screen.  You can also drag flags back
off the scale to get rid of them.

-i-


On 19/2/02 12:06 am, "Roger.E.Eller at sealedair.com"
<Roger.E.Eller at sealedair.com> scribed:

> 
> 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
> set the itemDelimiter to ","
> put the Width of me into WidthOfBox
> put the Height of me into HeightOfBox
> 
> -- 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
>   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
> 
>   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
>   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
> 
> 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

----------------------------------
Ian Summerfield
Macintosh Consultant - Hastings UK
ICQ: 4378866
----------------------------------

     This E-mail is from Ian Summerfield's home system.
     
     The contents and any attachments to it include information that is
     private and confidential and should only be read by those persons to
     whom they are addressed. Ian accepts no liability for any loss
     or damage suffered by any person arising from the use of this e-mail.
     Ian does not accept any responsibility for viruses and it is your
     responsibility to check the email and attachments (if any).

     If you have received this e-mail in error, please destroy and delete
     the message from your computer.
  





More information about the Use-livecode mailing list