Boxes, Grids, & Snap to Objects

Roger.E.Eller at sealedair.com Roger.E.Eller at sealedair.com
Mon Feb 18 19:09:01 EST 2002


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





More information about the use-livecode mailing list