SET_POLY_MODE

Syntax

short Escape(hDC, SET_POLY_MODE, sizeof(int),lpMode, NULL)

This escape sets the poly mode for the device driver. The poly mode is a state variable indicating how to interpret calls to the GDI Polygon and Polyline functions.

The SET_POLY_MODE escape enables a device driver to draw shapes (such as Bezier curves) not supported directly by GDI. This permits applications that draw complex curves to send the curve description directly to a device without having to simulate the curve as a polygon with a large number of points.

Parameter Type/Description  

hDC HDC Identifies the device context.  
lpMode LPINT Points to a short integer specifying the desired poly mode. The poly mode is a state variable indicating how points in Polygon or Polyline function calls should be interpreted. All device drivers are not required to support all possible modes. A device driver returns zero if it does not support the specified mode. The lpMode parameter may be one of the following values:  
  Value Meaning
  PM_POLYLINE (1) The points define a conventional polygon or polyline.
  PM_BEZIER (2) The points define a sequence of 4-point Bezier spline curves. The first curve passes through the first four points, with the first and fourth points as end points, and the second and third points as control points. Each subsequent curve in the sequence has the end point of the previous curve as its start point, the next two points as control points, and the third as its end point.
    The last curve in the sequence is permitted to have fewer than four points. If the curve has only one point, it is considered a point. If it has two points, it is a line segment. If it has three points, it is a parabola defined by drawing a Bezier curve with the first and third points as end points and the two control points equal to the second point.
  Value Meaning
  PM_POLYLINESEGMENT (3) The points specify a list of coordinate pairs. Line segments are drawn connecting each successive pair of points.
  PM_POLYSCAN-LINE (4) The points specify a list of coordinate pairs. Line segments are drawn connecting each successive pair of points. Each line segment is a nominal-width line drawn using the current brush. Each line segment must be strictly vertical or horizontal, and scan lines must be passed in strictly increasing or decreasing order. This mode is only used for polygon calls.

Return Value

The return value is the previous poly mode. If the return value is zero, the device driver did not handle the request.

Comments

An application should issue the SET_POLY_MODE escape before it draws a complex curve. It should then call the Polyline or Polygon function with the desired control points defining the curve. After drawing the curve, the application should reset the driver to its previous state by issuing the SET_POLY_MODE escape.

Polyline calls draw using the currently selected pen.

Polygon calls draw using the currently selected pen and brush. If the start and end points are not equal, a line is drawn from the start point to the end point before filling the polygon (or curve).

GDI treats Polygon calls using PM_POLYLINESEGMENT mode exactly the same as Polyline calls.

Four points define a Bezier curve. GDI generates the curve by connecting the first and second, second and third, and third and fourth points. GDI then connects the midpoints of these consecutive line segments. Finally, GDI connects the midpoints of the lines connecting the midpoints, and so forth.

The line segments drawn in this way converge to a curve defined by the following parametric equations, expressed as a function of the independent variable t.

X(t) = (1-t)<^3> x + 3(1-t)<^2> tx + 3(1-t)t<^2> x + t<^3> x

Y(t) = (1-t)<^3> y + 3(1-t)<^2> ty + 3(1-t)t<^2> y + t<^3> y

The points (x1,y1), (x2,y2), (x3,y3) and (x4,y4) are the control points defining the curve. The independent variable t varies from 0 to 1.

A second-degree Bezier curve can be expressed as a third-degree Bezier curve using the following parameterization:

The points (Cx1,Cy1) and (Cx2,Cy2) are third-degree control points of a second-degree Bezier curve specified by the points (X1,Y1), (X2,Y2), and (X3,Y3).

Primitive types other than PM_BEZIER and PM_POLYLINESEGMENT may be added to this escape in the future. Applications should check the return value from this escape to determine whether or not the driver supports the specified poly mode.