geometry-challenged
Thomas Bähler
toeloop at swissonline.ch
Sun Jan 25 13:13:53 EST 2004
My solution a bit refined is fast enough to draw the line while moving
the button (Mac G4, 400MHz).
Well, this is rather due to the speed of Revolution than to my
scripting skills :-)
To test it just:
- create two buttons
- name them "Button 1" and "Button 2".
- create a line and name it "ConnectingLine"
- copy the script below into one or both buttons
Cheers
Thomas
-- Script for connecting two buttons with a line that starts just
outside the button-area
------------------------------------------------------------------------
-----------------------------------------
on mouseDown
set the uAllowDrag of me to true
end mouseDown
on mouseMove x,y
if the uAllowDrag of me is false then exit mouseMove
set the loc of me to x,y
DrawLineBetween (the loc of button "Button 1"),(the loc of button
"Button 2")
end mouseMove
on mouseUp
set the uAllowDrag of me to false
end mouseUp
on mouseRelease
mouseUp
end mouseRelease
on DrawLineBetween Loc1,Loc2
put Loc1 into PunktA
put Loc2 into PunktB
put (item 1 of PunktB) - (item 1 of PunktA) into DistX
put (item 2 of PunktB) - (item 2 of PunktA) into DistY
put round((DistX^2+DistY^2)^0.5) into LLength
put DistX/LLength into XStep
put DistY/LLength into YStep
put 0 into i
repeat LLength times
put i + 1 into i
-- Find startpoint
put (item 1 of PunktA) + round(XStep*i) & comma & (item 2 of
PunktA) + round(YStep*i) into Punkti
if (within(button "Button 1",Punkti) is false) and (PunktA = Loc1)
then
put Punkti into PunktA
end if
--find endpoint
put (item 1 of PunktA) + round(XStep*(LLength-i)) & comma & (item 2
of PunktA) + round(YStep*(LLength-i)) into Punkti
if (within(button "Button 2",Punkti)is false) and (PunktB = Loc2)
then
put Punkti into PunktB
end if
if (PunktA <> Loc1) and (PunktB <> Loc2) then exit repeat
end repeat
put PunktA & comma & PunktB into Punkte
set the points of graphic "ConnectingLine" to Punkte
end DrawLineBetween
More information about the use-livecode
mailing list