Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



Drawing shapes using the PolyPoints property

VFP9 brought a new property that allows us to draw all kinds of shapes, without the need of any external component, even a single Windoes API call.

According to the VFP9 Help, The PolyPoints property of the Shape control "specifies an array of coordinates for creating polygon shapes using the Shape control and polygon lines using the Line control. Read/write at design time and run time. For Shape controls, PolyPoints creates a polygon shape."

MVP Luis Maria Guayan from Argentina already did an amazing job using the polypoints property, in 2 articles.

Dibujando polígonos con VFP 9.0 - a simple article with some samples showing how we can draw a TRaiangle and an Ogtogon. The article is in spanish, but it is very simple to run the provided samples and reproduce the proposed result.

The 2nd one, Gráficas con objetos 100% VFP, is a real masterpiece, where he uses the polypoints property to create chart shapes, providing a very nice charting tool. Download the source code and play with the samples, amazing !

 

Using the PolyPoints property we can also draw rounded shapes, pie slices, circles and ellipses.

Create an empty form, size it the way you like, and paste the following code to the INIT() event, to reproduce the shape below:

Thisform.AddObject("Shape1", "Shape")
* Add a shape object to the current form
* and set some basic properties
LOCAL loShape
as Shape
loShape = Thisform
.Shape1
loShape.
Width = Thisform.
Width
loShape.Height = Thisform.
Height
loShape.Anchor = 15
&& Resize Width and Height
loShape.BackColor = RGB
(255,0,0)
loShape.
PolyPoints = "aPoly"
&& Array of points
loShape.Visible
= .T.
 
* Defining the PolyPoints array
* Change the values of lnStart and lnFinal to determine
* the angle of the pie slice
LOCAL
lnStart, lnFinal, lnSweep, n, lnRadius, lnAngle
lnStart = 0
lnFinal = 360

lnSweep = lnFinal - lnStart
lnRadius = 50

PUBLIC aPoly(lnSweep + 2, 2)
FOR n = 1 TO
lnSweep + 1
   lnAngle = lnStart + n - 1
   aPoly(n,1) = (lnRadius *
COS(DTOR
(lnAngle)) + lnRadius)
   aPoly(n,2) = (lnRadius *
SIN(DTOR
(lnAngle)) + lnRadius)
ENDFOR

IF lnSweep = 360 && Closed ellipse, so dont draw the center point
   aPoly(n,1) = aPoly(n-1,1)
   aPoly(n,2) = aPoly(n-1,2)
ELSE
   * Determine the Center point
   aPoly(n,1) = lnRadius
   aPoly(n,2) = lnRadius
ENDIF

 

To obtain pie slices, just change the values of the variables lnStart and lnFinal, to determine the starting and ending angle.

Here's the result if you use:

lnStart = 90
lnFinal = 210

 

The very cool feature of polypoints is that it generates vectorial pictures. You can resize the form the way you like, and you'll see your shape changing accordingly. All I did for that purpose was to setup the property Anchor to the value 15 (resize width and height).

 

Published Monday, July 06, 2009 5:14 AM by cesarchalom

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

What do you think?

(required) 
(optional)
(required)