Reshape Graphic

Alejandro Tejada capellan2000 at yahoo.com
Sun Oct 24 18:36:24 EDT 2004


Hi Frank,

I have put code to reshape a polygon vector graphic
in the stack "Graphic Tools v01 beta"

<http://www.geocities.com/capellan2000/Graphic_Tools_v01beta.zip>

This long script is from the 
button "directSelectionScript"
at the bottom of the stack, and from
the stack script.

You can improve it at your own will. :-)

alejandro

local
vertexpoint,vfrtgb,mnbvc,twovertexpoints,pointxy,mqpz,apgd1,apgd2,ajdg1,ajdg2

on mouseUp
  set the cursor to 1085
  
  if the target <> word 1 to 3 of the selobj -- this
line to avoid a flicker in the selobj
  then
    if the target contains "graphic" and the style of
the target = "polygon"
    then
      if twovertexpoints is not empty -- and the
target contains "graphic" and the style of the target
= "polygon" ## @@@
      then
        if ((item 1 of apgd1 + item 1 of mqpz ),(item
2 of apgd1 + item 2 of mqpz)) <> "0,0"  -- this line
prevents that the polygon gets a new line at 0,0
        then
          #  -- beep 3
          put the points of the target into vfrtgb
          set the graphicPointsforUndo of btn "Undo"
to vfrtgb
          put ((item 1 of apgd1 + item 1 of mqpz
),(item 2 of apgd1 + item 2 of mqpz)) into line ajdg1
of vfrtgb
          put  ((item 1 of apgd2 + item 1 of mqpz
),(item 2 of apgd2 + item 2 of mqpz)) into line ajdg2
of vfrtgb
          
          set the points of the target to vfrtgb
        end if
      end if
      -- if I don't put empty into these locals the
vertexpoint "stick" to the mouse pointer
      put empty into mqpz
      put empty into apgd1
      put empty into apgd2
      put empty into ajdg1
      put empty into ajdg2
      put empty into vertexpoint
      put empty into vfrtgb
      put empty into mnbvc
      put empty into twovertexpoints
      put empty into pointxy
      set the markerfilled of the target to false
      set the markerDrawn of the target to the hilite
of btn "Show Markers"
    end if
    
  end if
  pass mouseUp
end mouseUp

on mousedown
  
  if the target <> word 1 to 3 of the selobj  --
prevent flickering
  then
    
    if the target contains "graphic" and the style of
the target = "polygon" and setOnlyonce <> 1
    then
      
      put 1 into setOnlyonce
      put the target into fld "editingGrafic"
      set the markercolor of the target to fld
"ColorMarker"
      set the markerdrawn of the target to true
      set the markerpoints of the target to "-2,-2 &
return & 2,-2 & return & 2,2 & return & -2,2 & return
& -2,-2" -- small square
      
      put the points of the target into vfrtgb
      put the clickloc into pointxy
      
      -- first check, if the clickloc is a vertex
point of the polygon graphic
      
      put nearpoints(pointxy) into oknhy -- nearpoints
is another handler
      
      repeat for each line i in oknhy
        
        if lineoffset(i,vfrtgb) = 0 -- vfrtgb contains
the list of points of the polygon graphic
        then
          next repeat
        else
          put lineoffset(i,vfrtgb) into mnbvc -- a
local variable with the line number of the clicked
point in the list of points, used by the mousemove
message
          if the target contains "graphic" and the
style of the target = "polygon" then set the
markerfilled of the target to true
          put line mnbvc of vfrtgb into vertexpoint --
a local variable with the clicked point, used by the
mousemove message
          exit repeat
        end if
        
      end repeat
      
      if vertexpoint is empty -- you clicked in a
segment of the polygon graphic, not in a vertexpoint
      then --    if the target contains "graphic" and
the style of the target = "polygon" then
        set the markerfilled of the target to true
        put the points of the target into vfrtgb1 --
the contents of vfrtgb1 will be used and deleted by
the following operations
        if last line of vfrtgb1 = first line of
vfrtgb1 then put the number of lines of vfrtgb1 - 1
into lgadCounter else put the number of lines of
vfrtgb1 into lgadCounter
        repeat lgadCounter -- the number of points of
the target - 1, this presume a closed target !!!!!
          put line 1 of vfrtgb1,line 2 of
vfrtgb1,pointxy into ckp
          put ((item 2 of ckp - item 6 of ckp)*(item 3
of ckp - item 1 of ckp) - (item 1 of ckp - item 5 of
ckp)*(item 4 of ckp - item 2 of ckp)) into zse
          put sqrt((item 3 of ckp - item 1 of ckp)^2 +
(item 4 of ckp - item 2 of ckp)^2)^2 into esz
          if esz <> 0 then put abs(zse/esz) & comma
after aqwsde
          -- put abs(zse/esz) & comma after aqwsde --
sometimes produce divide by zero error
          put line 1 of vfrtgb1 && " " && line 2 of
vfrtgb1 & return after aws
          delete line 1 of vfrtgb1
        end repeat
        put min(aqwsde) into mqh
        put itemoffset(mqh,aqwsde) into mbz
        put line mbz of aws into twovertexpoints
      end if
    else
      pass mousedown
    end if -- the target contains "graphic" and the
style of the target = "polygon" and setOnlyonce <> 1
  end if -- target is not the selobj
  pass mousedown
end mousedown



on mousemove mX,mY
  
  if the target <> word 1 to 3 of the selobj -- to
avoid flickering of the selectedobject
  then
    if vertexpoint is not empty and the target
contains "graphic" and the style of the target =
"polygon"
    then
      if (mnbvc = 1 or mnbvc = the number of lines of
vfrtgb) and line 1 of vfrtgb = last line of vfrtgb
      then
        set the graphicPointsforUndo of btn "Undo" to
vfrtgb
        put mX,mY into first line of vfrtgb
        put mX,mY into last line of vfrtgb
        set the points of the target to vfrtgb
      else
        set the graphicPointsforUndo of btn "Undo" to
vfrtgb
        put mX,mY into line mnbvc of vfrtgb
        set the points of the target to vfrtgb
      end if
      
    else -- vertexpoint is empty and the target
contains "graphic" and the style of the target =
"polygon"
      
      -- This part of the code lets you to drag two
vertexpoints
      if twovertexpoints is not empty -- and the
target contains "graphic" and the style of the target
= "polygon"
      then
        
        put word 1 of twovertexpoints into apgd1 -- a
coordinate point like 14,23
        put word 2 of twovertexpoints into apgd2 -- a
coordinate point like 42,12
        put lineoffset(apgd1,vfrtgb)into ajdg1 -- a
single number like 12
        put lineoffset(apgd2,vfrtgb)into ajdg2 -- a
single number like 21
        put pointxy into firstclick
        put mX,mY into seconclick
        
        switch
        case item 1 of firstclick > item 1 of
seconclick -- moving to the left
          if  item 2 of firstclick > item 2 of
seconclick then put (- (item 1 of firstclick - item 1
of seconclick)),(-(item 2 of firstclick - item 2 of
seconclick)) into mqpz
          if  item 2 of firstclick < item 2 of
seconclick then put (- (item 1 of firstclick - item 1
of seconclick)),(item 2 of seconclick - item 2 of
firstclick) into mqpz
          if  item 2 of firstclick = item 2 of
seconclick then put (- (item 1 of firstclick - item 1
of seconclick)),(item 2 of firstclick - item 2 of
seconclick) into mqpz
          break
        case item 1 of firstclick < item 1 of
seconclick -- moving to the right
          if  item 2 of firstclick > item 2 of
seconclick then put (item 1 of seconclick - item 1 of
firstclick ),(-(item 2 of firstclick - item 2 of
seconclick)) into mqpz
          if  item 2 of firstclick < item 2 of
seconclick then put (item 1 of seconclick - item 1 of
firstclick),(item 2 of seconclick - item 2 of
firstclick) into mqpz
          if  item 2 of firstclick = item 2 of
seconclick then put (- (item 1 of firstclick - item 1
of seconclick)),(item 2 of firstclick - item 2 of
seconclick) into mqpz
          break
        case item 1 of firstclick = item 1 of
seconclick -- moving in rect line
          if  item 2 of firstclick > item 2 of
seconclick then put (- (item 1 of firstclick - item 1
of seconclick)),-(item 2 of firstclick - item 2 of
seconclick) into mqpz
          if  item 2 of firstclick < item 2 of
seconclick then put (- (item 1 of firstclick - item 1
of seconclick)),(item 2 of firstclick - item 2 of
seconclick) into mqpz
          if  item 2 of firstclick = item 2 of
seconclick then put (- (item 1 of firstclick - item 1
of seconclick)),(item 2 of firstclick - item 2 of
seconclick) into mqpz
          break
        end switch
        
        # --  mqpz contains a coordinate point -- ej:
-45,-21 or 84,-56 or 22,47 or -61,31
        
      end if
      
    end if
    
  end if
  
  pass mousemove
end mousemove

Function Nearpoints pointxy -- is a coordinate point
like 34,56
  
  put item 1 of pointxy - 2 & comma & item 2 of
pointxy - 2 & return after oknhy
  put item 1 of pointxy - 2,item 2 of pointxy - 1 &
return after oknhy
  put item 1 of pointxy - 2,item 2 of pointxy & return
after oknhy
  put item 1 of pointxy - 2,item 2 of pointxy + 1 &
return after oknhy
  put item 1 of pointxy - 2,item 2 of pointxy + 2 &
return after oknhy
  
  put item 1 of pointxy - 1,item 2 of pointxy - 2 &
return after oknhy
  put item 1 of pointxy - 1,item 2 of pointxy - 1 &
return after oknhy
  put item 1 of pointxy - 1,item 2 of pointxy & return
after oknhy
  put item 1 of pointxy - 1,item 2 of pointxy + 1 &
return after oknhy
  put item 1 of pointxy - 1,item 2 of pointxy + 2 &
return after oknhy
  
  put item 1 of pointxy,item 2 of pointxy - 2 & return
after oknhy
  put item 1 of pointxy,item 2 of pointxy - 1 & return
after oknhy
  put item 1 of pointxy,item 2 of pointxy & return
after oknhy
  put item 1 of pointxy,item 2 of pointxy + 1 & return
after oknhy
  put item 1 of pointxy,item 2 of pointxy + 2 & return
after oknhy
  
  put item 1 of pointxy + 1,item 2 of pointxy - 2 &
return after oknhy
  put item 1 of pointxy + 1,item 2 of pointxy - 1 &
return after oknhy
  put item 1 of pointxy + 1,item 2 of pointxy & return
after oknhy
  put item 1 of pointxy + 1,item 2 of pointxy + 1 &
return after oknhy
  put item 1 of pointxy + 1,item 2 of pointxy + 2 &
return after oknhy
  
  put item 1 of pointxy + 2,item 2 of pointxy - 2 &
return after oknhy
  put item 1 of pointxy + 2,item 2 of pointxy - 1 &
return after oknhy
  put item 1 of pointxy + 2,item 2 of pointxy & return
after oknhy
  put item 1 of pointxy + 2,item 2 of pointxy + 1 &
return after oknhy
  put item 1 of pointxy + 2,item 2 of pointxy + 2
after oknhy
  
  return oknhy
end Nearpoints



=====
Visit my site:
http://www.geocities.com/capellan2000/


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


More information about the use-livecode mailing list