• Coordinates
• Drawing with opacity or anti-aliasing
• Using the drawing functions
• Drawing in PHP
• Drawing in Browser code
WINDEV
WEBDEV
WINDEV Mobile
Others
Draws a polygon:
• in an Image control,
• in a variable of type Image.
This type of variable is not available.
• in a variable of type WDPic (on the background layer),
• in a variable of type picLayer.
Caution: A specific configuration is required to use this function in Linux. For more details, see The drawings.
// Initialize the drawing in an Image control
dStartDrawing(IMG_Drawing)
// Draw a 4-side polygon whose
// background is light yellow and whose border is light blue
dPolygon(4, 10, 20, 20, 50, 40, 60, 50, 10, LightYellow, LightBlue)
// Draw a 4-side polygon whose
// background is light yellow and whose border is light blue
dPolygon(IMG_Drawing, 4, 10, 20, 20, 50, 40, 60, 50, 10, LightYellow, LightBlue)
// Draw a polygon from an array of point coordinates
arrCoordinatesXY is array of 0 by 2 int = [[2, 3], [14, 100], [10,70], [50, 80]]
dPolygon(arrCoordinatesXY)
arrCoordinatesXY2 is array of 0 int = [2, 2, 140, 2, 150, 70, 0, 100, 200,100]
dPolygon(arrCoordinatesXY2)
arrCoordinatesXYC is array of 36 by 2 int
FOR I = 1 TO 36
// x
arrCoordinatesXYC[I][1] = 80 + Cos(I*10) * Radius
// y
arrCoordinatesXYC[I][2] = 60 + Sin(I*10) * Radius
END
dPolygon(arrCoordinatesXYC, LightGray, YellowToolhelp)
Syntax

Building a polygon point by point

dPolygon([<Image>, ] <Number of sides> , <X1> , <Y1> , <X2> , <Y2> [, <X3> , <Y3> [... [, <Xn> , <Yn>]]] [, <Background color> [, <Side color>]])
<Image>: Optional control name or optional Image, WDPic or picLayer variable
Image to use. The image can correspond to:
• the name of an Image control.
• the name of a variable of type Image.
• the name of a variable of type WDPic. Only the background layer will be handled.
• the name of a variable of type picLayer.
If this parameter is not specified, it is necessary to define the drawing destination with dStartDrawing.
<Number of sides>: Integer
Number of sides in the polygon (up to 23 sides). This parameter defines the number of <X>, <Y> pairs to specify in the function.
<X1>: Integer
X-coordinate of first point of the polygon. These coordinates are expressed in pixels.
<Y1>: Integer
Y-coordinate of first point of the polygon. These coordinates are expressed in pixels.
<X2>: Integer
X-coordinate of second point of the polygon. These coordinates are expressed in pixels.
<Y2>: Integer
Y-coordinate of second point of the polygon. These coordinates are expressed in pixels.
<X3>: Integer
X-coordinate of 3rd point of the polygon. These coordinates are expressed in pixels.
<Y3>: Integer
Y-coordinate of 3rd point of the polygon. These coordinates are expressed in pixels.
<Xn>: Optional integer
X-coordinate of nth point of the polygon. These coordinates are expressed in pixels.
<Yn>: Optional integer
Y-coordinate of nth point of the polygon. These coordinates are expressed in pixels.
<Background color>: Integer or constant (optional)
Polygon background color. This color can correspond to:
If this parameter is not specified, the background color:
• is Transparent if dBackground has not been used beforehand,
• corresponds to the color specified in the last call to dBackground.
<Side color>: Integer or constant (optional)
Color of polygon sides. This color can correspond to:
If this parameter is not specified, the line color:
• corresponds to the color specified in the last call to dPen,
• is the same as the background color if dPen has not been used.

Building a polygon via an array of X and Y-coordinates

dPolygon([<Image>, ] <Array of coordinates> [, <Background color> [, <Side color>]])
<Image>: Optional control name or optional Image, WDPic or picLayer variable
Image to use. The image can correspond to:
• the name of an Image control.
• the name of a variable of type Image.
• the name of a variable of type WDPic. Only the background layer will be handled.
• the name of a variable of type picLayer.
If this parameter is not specified, it is necessary to define the drawing destination with dStartDrawing.
<Array of coordinates>: Array of integers or array of points
• WLanguage array of integers containing the coordinates of polygon points. The even indices represent the X-coordinates while the odd indices represent the Y-coordinates of the points. These coordinates are expressed in pixels.
• WLanguage array of Point variables containing the coordinates of the polygon points. These coordinates are expressed in pixels.
<Background color>: Integer or constant (optional)
Polygon background color. This color can correspond to:
If this parameter is not specified, the background color:
• is Transparent if dBackground has not been used beforehand,
• corresponds to the color specified in the last call to dBackground.
<Side color>: Integer or constant (optional)
Color of polygon sides. This color can correspond to:
If this parameter is not specified, the line color:
• corresponds to the color specified in the last call to dPen,
• is the same as the background color if dPen has not been used.

Building a polygon from a variable of type Polygon

dPolygon([<Image>, ] <Polygon> [, <Background color> [, <Side color>]])
<Image>: Optional control name or optional Image, WDPic or picLayer variable
Image to use. The image can correspond to:
• the name of an Image control.
• the name of a variable of type Image.
• the name of a variable of type WDPic. Only the background layer will be handled.
• the name of a variable of type picLayer.
If this parameter is not specified, it is necessary to define the drawing destination with dStartDrawing.
<Polygon>: Polygon variable
Name of the Polygon variable that describes the different points of the polygon.
<Background color>: Integer or constant (optional)
Polygon background color. This color can correspond to:
If this parameter is not specified, the background color:
• is Transparent if dBackground has not been used beforehand,
• corresponds to the color specified in the last call to dBackground.
<Side color>: Integer or constant (optional)
Color of polygon sides. This color can correspond to:
If this parameter is not specified, the line color:
• corresponds to the color specified in the last call to dPen,
• is the same as the background color if dPen has not been used.
Remarks

Coordinates

Drawing a polygon:
dPolygon(5, 80, 10, 10, 150, 100, 200, 160, 80, 140, 40)
Coordinates are given with respect to the upper-left corner of the image (coordinates: (0.0)).
Important: There is no need to close the polygon (the coordinates of last point do not have to be equal to the coordinates of first point). The polygon is automatically "closed".
Limits: a polygon can contain up to 100 000 points in WINDEV, WEBDEV and Java, and up to 1000 points in Windows CE.

Drawing with opacity or anti-aliasing

For a drawing with opacity (dStartDrawing with the dWithOpacity constant) or anti-aliasing (dChangeMode with the drawAntiAliasing constant), the outline is drawn inside the polygon: therefore, the line is partly combined with the inside of the polygon. If the line is very thick, it will be displayed in two colors.

Using the drawing functions

The drawing functions can be used according to 2 methods:
• Method 1: Using dStartDrawing
• dStartDrawing must be called before any other drawing function. dStartDrawing is used to define the element (Image control or variable) to which the drawing functions will be applied.
• When drawing on an Image control:
• The drawing functions operate on a copy ("bitmap") of the image. You can use the drawing functions of Windows (via API or CallDLL32) but these functions must use the DC (Device Context) returned by dStartDrawing.
• dEndDrawing and dStartDrawing must not be called in the same process.
The drawing will not be displayed if dEndDrawing and dStartDrawing are called in the same process: it will be automatically erased.
• Method 2: indicating the drawing target directly in the syntax (via a parameter)
The <Image> parameter is used to specify directly the target of the drawing. dStartDrawing becomes useless. This function must be deleted.

Drawing in PHP

In PHP, the drawing functions are based on the graphic library GD. This library is commonly used by the PHP hosting companies and therefore it is always enabled. The version of the GD library must be version 2.0.28 (or later). This library can be downloaded from the PHP site.
To enable (if necessary) this library locally, the following elements are required:
• PHP installed.
• the PHP.INI file found in the Windows directory must contain the following line: "extension=php_gd2.dll" (instead of ";extension=php_gd2.dll").
• the php_gd2.dll file must exist in the directory of PHP extensions. This directory is defined in the PHP.INI file by the "extension_dir" variable.

Drawing in Browser code

Some drawing functions are available in Browser code. The drawing functions in Browser code are based on the HTML 5 standard. More specifically, these functions are based on the "canvas" tag of HTML 5.
The drawing features in browser code are available for the recent browsers only (supporting the HTML 5 standard). To find out whether the drawing features are proposed by your browser, use DrawingAvailable.
Caution: To use the drawing functions with Internet Explorer 9, the project must include the reference to the DTD file. To do so, the HTML mode must be "HTML 4.01 Transitional + DTD". This option is available in the "Advanced" tab of the project description window.
Reminder: To open the project description window, go to the "Project" tab, "Project" group and click "Description".
Special case: Drawing in the browser of an Android phone: The browser drawing functions are only available starting with version 3 of Android.
Related Examples:
 Unit examples (WINDEV): The drawing functions [ + ] Using the main drawing functions of WINDEV to:- Initialize an Image control for drawing- Draw simple shapes- Write a text into a drawing- Change the color in a drawing
Business / UI classification: Neutral code
Component: wd280pnt.dll
Minimum version required
• Version 9