From: "Jason Smithwick" To: Subject: ComputerLab Feedback Date: Wed, 20 Jun 2001 14:29:52 +0100 Dear Earl, I have been working on a Plotting Prgram for graphs etc. and found most of the Newsgroups posted solutions for Dotted/Dashed lines types for a line thickness>1 in Delphi unsatisfactory. I was wondering if you would like my solution to the problem. This works for 2 to N Point Lines. Basically define the Pen for your canvas first (e.g. Pen.Width=6, Pen.Style:=psDot etc.) and then pass the Canvas, TPoint array, and number of points to the following procedure: Best regards, Jason ---------------------------------------------------------------------------- ------- Const MaxNumPlotData=500; type PlotPointArray = Array [1..MaxNumPlotData] of TPoint; procedure DrawPolyLine(Canvas : TCanvas; PP : PlotPointArray; numpts : integer); var dist,m,r,dx,dy,xa,ya : real; i,pl,numps : integer; space : boolean; LP : TPoint; ps : array[1..6] of integer; tempps : TPenStyle; DashDist,SpaceDist,DotDist : integer; begin DashDist:=15; DotDist:=5; SpaceDist:=5; tempps:=Canvas.Pen.Style; Case Canvas.Pen.Style of psSolid : begin Canvas.PolyLine(Slice(PP,numpts)); exit; end; psDash : begin numps:=2; ps[1]:=DashDist; ps[2]:=-SpaceDist end; psDot : begin numps:=2; ps[1]:=DotDist; ps[2]:=-SpaceDist; end; psDashDot : begin numps:=4; ps[1]:=DashDist; ps[2]:=-SpaceDist; ps[3]:=DotDist; ps[4]:=-SpaceDist; end; psDashDotDot : begin numps:=6; ps[1]:=DashDist; ps[2]:=-SpaceDist; ps[3]:=DotDist; ps[4]:=-SpaceDist; ps[5]:=DotDist; ps[6]:=-spacedist; end; psClear : exit; end; Canvas.Pen.Style:=psSolid; dist:=0; space:=false; if numpts>=1 then begin Canvas.MoveTo(PP[1].X,PP[1].Y); LP.X:=PP[1].X; LP.Y:=PP[1].Y; end; i:=1; pl:=1; while i0 then begin m:=dy/dx; if dx>=0 then xa:=LP.X+sqrt(r*r/(1+m*m)) else xa:=LP.X-sqrt(r*r/(1+m*m)); ya:=LP.Y+m*(xa-LP.X); end else begin xa:=LP.X; if dy>0 then ya:=LP.Y-r else ya:=LP.Y-r; end; LP.X:=round(xa); LP.Y:=round(ya); if Space then Canvas.MoveTo(LP.X,LP.Y) else Canvas.LineTo(LP.X,LP.Y); pl:=pl+1; if pl>numps then pl:=1; dist:=0; space:=ps[pl]<0; end; end; Canvas.Pen.Style:=tempps; end; ********************************************* Dr Jason Smithwick Wolfson Unit M.T.I.A. University of Southampton Southampton, SO17 1BJ, U.K. ********************************************* Tel: +44 (0)23 8058 5044 Fax: +44 (0)23 8067 1532 e-mail: jets@soton.ac.uk URL: www.soton.ac.uk/~wumtia *********************************************