Drawing a Straight Line

To draw a straight line, set the current position with GpiMove or GpiSetCurrentPosition. Set the end point of the line by filling in a POINTL structure, then draw the line with GpiLine. The following figure shows how to draw a straight line in a PM application.

#include <os2.h>

    BOOL DrawLine(HPS hps, LONG xStart, LONG yStart, LONG xEnd, LONG yEnd){
        POINTL ptl;                       /* Point structure              */

        ptl.x = xStart;                   /* Loads starting x-coordinate  */
        ptl.y = yStart;                   /* Loads starting y-coordinate  */
        GpiMove(hps, &ptl);               /* Sets current position        */
        ptl.x = xEnd;                     /* Loads ending x-coordinate    */
        ptl.y = yEnd;                     /* Loads ending y-coordinate    */
        if (GpiLine(hps, &ptl) == GPI_OK){
            return TRUE;                  /* Draw Line.                   */
        } /* if */
        else return FALSE;
    } /* DrawLine */

The second argument of GpiMove is the address of a POINTL structure that contains coordinates of the line's starting point. The second argument of GpiLine is the address of another POINTL structure that contains the coordinates of the last point on the line.


[Back: Using Line and Arc Primitives]
[Next: Creating a Rubber-Banding Effect with a Straight Line]