Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!ba0k+ From: ba0k+@andrew.cmu.edu (Brian Patrick Arnold) Newsgroups: comp.sys.mac.hypercard Subject: Re: arrowheads at the end of lines. Message-ID: Date: 6 Dec 89 22:32:30 GMT References: Organization: Mechanical Engineering, Carnegie Mellon, Pittsburgh, PA Lines: 93 In-Reply-To: Hello there, I've spent some time developing influence diagrams to represent variable dependencies of math eqns in HyperCard. The key to drawing arrow heads at any angle is to use the regular polygon tool with polySides set to 3. Redrawing links presents a bit of a speed problem. We have a solution for redrawing links when nodes are moved, but we are not satisfied with the performance and plan to write a MacApp-based compiled version. Here is an example of how we draw a directed link between two buttons. You need to have the following paint globals set: set pattern to 12 -- color arrow head black set filled to true -- for a solid arrow head set polysides to 3 -- arrow heads have 3 sides You should set these globals in a handler that saves the old values so that a complementary handler can restore the old values when through - you also need to "choose browse tool" when through. You should write SetDrawMode and RestoreDrawMode handlers as your needs require. -------------------------------------------- ON DoDrawLink fromLinkName, toLinkName -- example for two buttons named fromLinkName and toLinkName SetDrawMode DrawALink the loc of cd btn fromLinkName, the loc of cd btn toLinkName, the width of cd btn toLinkName && the height of cd btn toLinkName RestoreDrawMode END DoDrawLink ON DrawALink fromLoc,toLoc,toSize -- -- Draw a line from fromLoc to an arrow head flush with the rectangle -- toSize located at toLoc. Side effect: leaves you with line tool. -- -- fromLoc starting point -- toLoc end point -- toSize "width && height" of a rectangle located at toLoc set cursor to busy -- feedback when redrawing -- compute angle of the line to be drawn put (item 1 of toLoc - item 1 of fromLoc) into delx put (item 2 of toLoc - item 2 of fromLoc) into dely put atan(dely/delx) into myAngle -- fudge a little ??? am I computing something incorrectly? IF delx < 0 THEN add pi to myAngle -- scale endpoint (toLoc) to account for toSize rectangle overlap IF abs(dely/delx) < ((word 2 of toSize / word 1 of toSize)) THEN put (1-(abs(delx)-(word 1 of toSize)/2)/abs(delx)) into factor ELSE put (1-(abs(dely)-(word 2 of toSize)/2)/abs(dely)) into factor subtract round(delx*factor) from item 1 of toLoc subtract round(dely*factor) from item 2 of toLoc -- generate inset point for arrow head, "5" is arbitrary put toLoc into arrowLoc add round(5*cos(myAngle+pi)) to item 1 of arrowLoc add round(5*sin(myAngle+pi)) to item 2 of arrowLoc -- do the drawing choose regular polygon tool drag from arrowLoc to toLoc -- should draw a triangle (arrowhead) choose line tool drag from fromLoc to arrowLoc -- should draw a line END DrawALink ------------------------------------------------ We have tried to replace the trig (above) with more straightforward calculations to speed up this algorithm, but this actually slowed things down a bit. The first "choose regular polygon tool" call takes a whole 1/2 second, but subsequent choose paint tool calls take almost no time. When undrawing or erasing links, we use the same algorithm with pattern set to 1 (white). Then we use the select tool and select the arrow space (from fromLoc to toLoc), and DoMenu "Transparent" to turn white pixels into transparent pixels. This may have unfavorable side effects. If this is of any help, please let me know. I also want to hear more about anyone's work on directed graphs in HyperCard. Brian Arnold Research Programmer Department of Engineering and Public Policy Carnegie Mellon University