resize in browse mode

Lynch, Jonathan BNZ2 at CDC.GOV
Wed Dec 29 11:12:56 EST 2004


I reworked the earlier script I posted to include Ken Ray's approach to
adjusting the rect of the field, rather than adjusting the size and then
the position. His approach is smoother and more efficient. (Thanks Ken)

So... the following script still does these things...


1) if you right-click on the main part of the field, it lets you drag
around the location of the field

2) if you right-click on one of the corners of the field, it lets you
resize the field from that corner

3) if the mouse is over one of the corners of the field, it changes to a
cross, to let you know you are over one of the corner handlers.


It just does them a bit smoother. It also works for an image, but moving
the image is still not as smooth as moving the image with the pointer
tool.


(apologies for the fact that I type lines out very far to the right,
making them look funny upon being word wrapped - if you paste it into a
script, it should look the way it is supposed to)
==============

local allowDrag
local allowResizeTL
local allowResizeTR
local allowResizeBL
local allowREsizeBR
local CHS

on mouseDown theButton
  if theButton = 3 then
    put 5 into CHS
    if ((mouseH()-(the left of me)) < CHS) and ((mouseV()-(the top of
me)) < CHS) then
      put (mouseH()-(the left of me)) & "," & (mouseV()-(the top of me))
& "," & (The right of me) & "," & (the bottom of me) into allowResizeTL
    else if ((the right of me)-(mouseH()) < CHS) and ((mouseV()-(the top
of me)) < CHS) then
      put ((the right of me)-(mouseH())) & "," & (mouseV()-(the top of
me)) & "," & (The left of me) & "," & (the bottom of me) into
allowResizeTR
    else if ((mouseH()-(the left of me)) < CHS) and (((the bottom of
me))-MouseV() < CHS) then
      put (mouseH()-(the left of me)) & "," & ((the bottom of
me)-mouseV()) & "," & (The right of me) & "," & (the top of me) into
allowResizeBL
    else if ((the right of me)-(mouseH()) < CHS) and (((the bottom of
me))-MouseV() < CHS) then
      put ((the right of me)-(mouseH())) & "," & ((the bottom of
me)-mouseV()) & "," & (The left of me) & "," & (the top of me) into
allowResizeBR
    else
      put (mouseH()-(the left of me)) & "," & (mouseV()-(the top of me))
into allowDrag
      set the cursor to cross
      lock cursor
    end if
  end if
end mouseDown

on mouseMove x,y
  put 5 into CHS
  put the rect of me into RCT
  if allowDrag <> empty then 
    set the topleft of me to (X-(item 1 of allowDrag) & "," & Y-(item 2
of allowdrag))
    
  else if allowResizeTL <> empty then
    if ((item 3 of allowResizeTL)-X) > CHS*2 then
      put X-(item 1 of allowResizeTL) into item 1 of RCT
      set the rect of me to RCT
    else
      put ((item 3 of allowResizeTL)-CHS*2) into item 1 of RCT
      set the rect of me to RCT
    end if
    if ((item 4 of allowResizeTL)-Y) > CHS*2 then
      put Y-(item 2 of allowResizeTL) into item 2 of RCT
      set the rect of me to RCT
    else
      put ((item 4 of allowResizeTL)-CHS*2) into item 2 of RCT
      set the rect of me to RCT
    end if
    
  else if allowResizeTR <> empty then
    if (X-(item 3 of allowResizeTR)) > CHS*2 then
      put (X+(item 1 of allowResizeTR)) into item 3 of RCT
      set the rect of me to RCT
    else
      put ((item 3 of allowResizeTR)+CHS*2) into item 3 of RCT
      set the rect of me to RCT
    end if
    if ((item 4 of allowResizeTR)-Y) > CHS*2 then
      put Y-(item 2 of allowResizeTR) into item 2 of RCT
      set the rect of me to RCT
    else
      put ((item 4 of allowResizeTR)-CHS*2) into item 2 of RCT
      set the rect of me to RCT
    end if
    
  else if allowResizeBL <> empty then
    if ((item 3 of allowResizeBL)-X) > CHS*2 then
      put X-(item 1 of allowResizeBL) into item 1 of RCT
      set the rect of me to RCT
    else
      put ((item 3 of allowResizeBL)-CHS*2) into item 1 of RCT
      set the rect of me to RCT
    end if
    if (Y-(item 4 of allowResizeBL)) > CHS*2 then
      put (Y+(item 2 of allowResizeBL)) into item 4 of RCT
      set the rect of me to RCT
    else
      put ((item 4 of allowResizeBL)+CHS*2) into item 4 of RCT
      set the rect of me to RCT
    end if

  else if allowResizeBR <> empty then
    if (X-(item 3 of allowResizeBR)) > CHS*2 then
      put (X+(item 1 of allowResizeTR)) into item 3 of RCT
      set the rect of me to RCT
    else
      put ((item 3 of allowResizeBR)+CHS*2) into item 3 of RCT
      set the rect of me to RCT
    end if
    if (Y-(item 4 of allowResizeBR)) > CHS*2 then
      put (Y+(item 2 of allowResizeBR)) into item 4 of RCT
      set the rect of me to RCT
    else
      put ((item 4 of allowResizeBR)+CHS*2) into item 4 of RCT
      set the rect of me to RCT
    end if
    
  else
    if (((mouseH()-(the left of me)) < CHS) and ((mouseV()-(the top of
me)) < CHS)) or (((the right of me)-(mouseH()) < CHS) and
((mouseV()-(the top of me)) < CHS)) or (((mouseH()-(the left of me)) <
CHS) and (((the bottom of me))-MouseV() < CHS)) or (((the right of
me)-(mouseH()) < CHS) and (((the bottom of me))-MouseV() < CHS)) then
     set the cursor to cross
     set the lockcursor to true
    else
    unlock cursor
      exit MouseMove
    end if
  end if
end mouseMove

on mouseLeave
  unlock cursor
end mouseLeave

on mouseUp
  put empty into allowDrag
  put empty into allowResizeTL
  put empty into allowResizeTR
  put empty into allowResizeBL
  put empty into allowResizeBR
  unlock cursor
end mouseUp

on mouseRelease
  mouseUp
end mouseRelease



More information about the use-livecode mailing list