PgDrawBezier(), PgDrawBezierv(), PgDrawBezierCx(), PgDrawBezierCxv()

Draw a stroked and/or filled bézier

Synopsis:

int  PgDrawBezier( PhPoint_t const *ptr,
                   int num,
                   PhPoint_t const *pos,
                   int flags );

int  PgDrawBezierv( PhPoint_t const *ptr,
                    int num,
                    PhPoint_t const *pos,
                    int flags );

int  PgDrawBezierCx( void *dc,
                     PhPoint_t const *ptr,
                     int num,
                     PhPoint_t const *pos,
                     int flags );

int  PgDrawBezierCxv( void *dc,
                      PhPoint_t const *ptr,
                      int num,
                      PhPoint_t const *pos,
                      int flags );

Arguments:

dc
PgDrawBezierCx() and PgDrawBezierCxv() only. A void pointer to any type of draw context. Examples of draw contexts are:
ptr
An array of four PhPoint_t structures that define the Bézier curve.
num
The number of points in the array (i.e. 4).
pos
A pointer to a PhPoint_t structure that specifies offsets to be added to all of the points or the first point, depending on the flags.
flags
Flags that control how the curve is drawn; see below.

Library:

ph

Description:

These functions build a command in the draw buffer to draw a multisegment Bézier curve from an array of points. PgDrawBezier() and PgDrawBezierv() work on the current draw context, while you can specify the draw context for PgDrawBezierCx() and PgDrawBezierCxv().

Each Bézier curve is defined by 4 points. The last point of a curve becomes the first point of the next curve. The first and fourth points are anchor points; the line passes through these. The second and third points are control points; the curve is “pulled” toward these points.

The flags argument must be one of the following:

You can OR flags with any combination of the following:

For absolute coordinates, pos is added to each point pointed to by ptr. For relative coordinates, the first coordinate is the sum of pos and the first point of the array; any subsequent coordinate is the sum of the previous point and the next point of the array.


Note: If you call the “v” or “Cxv” form of this function, the data isn't physically copied into the draw buffer. Instead, a pointer to the array is stored until the draw buffer is flushed. Make sure you call PgFlush() before you modify the point array.

Returns:

0
Success.
-1
The draw buffer is too small to hold the current draw state, the draw command, and the data. Increase the size of the draw buffer or decrease the number of points.

Examples:

The following example:

DrawFillStrokeBezier() {
    PhPoint_t   o = { 0, 0 };
    PhPoint_t   p[] = {43, 71, -92, -18, 344, -6, 20, 99};

    PgSetStrokeDash( "\1", 1, 0x10000 );
    PgSetStrokeColor( Pg_GRAY );
    PgDrawPolygon( &p, 4, &o,
                   Pg_DRAW_STROKE | Pg_CLOSED );
    PgSetStrokeDash( NULL, 0, 0 );
    PgSetStrokeColor( Pg_YELLOW );
    PgSetFillColor( Pg_PURPLE );
    PgDrawBezier( &p, 4, &o,
                   Pg_DRAW_FILL_STROKE | Pg_CLOSED );
}

will draw:

PgDrawBezier,fillstroke

The dotted lines show where the control points are relative to the anchor points.

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PgDrawPolygon*(), PgFlush(), PhPoint_t

To draw stroked Bézier curves, see also:

PgSetStrokeColor*(), PgSetStrokeCap*(), PgSetStrokeDash*(), PgSetStrokeDither*(), PgSetStrokeJoin*(), PgSetStrokeWidth*()

To draw filled Bézier curves, see also:

PgSetFillColor*(), PgSetFillDither*(), PgSetFillTransPat*()

Drawing attributes and Lines, pixels, and pixel arrays in the Raw Drawing and Animation chapter of the Photon Programmer's Guide