Board index » delphi » Drawing variable-sized Polygons at runtime?

Drawing variable-sized Polygons at runtime?

Hello,

I want to draw large (hundreds or thousands vertices) polygons of which
the number of vertices is determined at run-time; (say the data is read
from a file containing e.g. country contours). Both PolyLine and PolyGon
methods of Canvas want an array of TPoint as paramater.

The problem is that each country contour has a different number of
contour points. So the size of the array can not be determined at
compile time.

On a web page of tips I  found some code simulating an array by doing
run time allocation and pointer stuff, but I could not make that work as
a parameter to the Polyxxx methods.

GDI seems to have a polygon call that wants -besides the area of
coordinates- a number indicating the number of vertices the polygon
should have. How can such a GDI call be called from Delphi ?

If you have a tip on drawing varying-sized polygons efficiently, please
let me know !

Thanks in advance,

-Henk

 

Re:Drawing variable-sized Polygons at runtime?


In article <Dt5yAI....@solair1.inter.NL.net>,
H.W. van Tijen <h...@phsoft.knoware.nl> wrote:

Quote

>Hello,

>I want to draw large (hundreds or thousands vertices) polygons of which
>the number of vertices is determined at run-time; (say the data is read
>from a file containing e.g. country contours). Both PolyLine and PolyGon
>methods of Canvas want an array of TPoint as paramater.

>The problem is that each country contour has a different number of
>contour points. So the size of the array can not be determined at
>compile time.

>On a web page of tips I  found some code simulating an array by doing
>run time allocation and pointer stuff, but I could not make that work as
>a parameter to the Polyxxx methods.

>GDI seems to have a polygon call that wants -besides the area of
>coordinates- a number indicating the number of vertices the polygon
>should have. How can such a GDI call be called from Delphi ?

Sounds very similar to the problem I'm working on.

I managed to get variable polygons drawn by calling winprocs.polygon
like this:

type
  TPolyPointArray = array[0..100] of TPoint;

var
  PolyPointArray : TPolyPointArray;
  FNpoints : integer;

{ allocate some data into the array - this bit could be reading from a file}

  PolyPointArray[0] := Point(0,0);
  PolypointArray[1] := Point(100,0);
  PolyPointArray[2] := Point(100,100);
  PolyPointArray[3] := Point(50,50);

  FNPoints := 4;

  { and now draw the polygon }
  canvas.brush := fbrush;
  canvas.pen := pen;
  WinProcs.polygon(canvas.handle,PolyPointArray,FNPoints);

{ obviously you'll need some other stuff around this, but it seems to
be the way of defining a variable number of vertices, if you were
worried about defining a 100 element array each time, you could do
some dynamic array allocation and pass the dynamic structure in place
of PolyPoints }

-- all I'm after now is a property editor for PolyPointArray, ideally
using on-screen drag, drop & insert of polygon vertices and I'll be a
happy man.

--
Dave Langstaff | d...@aber.ac.uk
Any views expressed are those of the author alone. | Phone:(01970)622838
After-life, After-shave, don't hold with any of it, bleugh!  - Sir Henry

Other Threads