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).
No comments:
Post a Comment