overview.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Using Area Primitives (1.2)
◄About Section►  ◄Function Group►                     ◄Up► ◄Next► ◄Previous►
────────────────────────────────────────────────────────────────────────────
 
                      Using Areas and Area Primitives
 
You can use area functions to perform the following tasks:
 
♦  Draw a single closed figure.
 
♦  Draw multiple intersecting closed figures.
 
♦  Draw multiple disjoint closed figures.
 
♦  Draw any combination of the three.
 
♦  Create a custom fill pattern from a bitmap.
 
♦  Create a custom fill pattern from a font character.
 
Drawing a Single Closed Figure
 
The following code fragment shows how to use area functions to draw a single
closed figure that is filled using the alternate mode. The closed figure in
this example is a five-pointed star.
 
/* Initialize the array of points for the 5-pointed star. */
 
aptl[0].x = 37; aptl[0].y = 82;
aptl[1].x = 400; aptl[1].y = 195;
aptl[2].x = 40; aptl[2].y = 320;
aptl[3].x = 260; aptl[3].y = 10;
aptl[4].x = 260; aptl[4].y = 390;
aptl[5].x = 37; aptl[5].y = 82;
 
/* Draw the star. */
 
GpiBeginArea(hps, BA_ALTERNATE);
GpiMove(hps, aptl);
GpiPolyLine(hps, 6L, aptl);
GpiEndArea(hps);
 
Drawing Multiple Intersecting Closed Figures
 
The following code fragment shows how to use area functions to draw two
intersecting boxes that are filled using the winding mode:
 
GpiBeginArea(hps, BA_WINDING);
ptl.x = 500; ptl.y = 300;
GpiMove(hps, &ptl);
ptl.x = 700; ptl.y = 500;
GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
ptl.x = 580; ptl.y = 370;
GpiMove(hps, &ptl);
ptl.x = 780; ptl.y = 570;
GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
GpiEndArea(hps);
 
Drawing Multiple Disjoint Closed Figures
 
The following code fragment shows how to use area functions to draw two
disjoint boxes that are filled using the winding mode:
 
GpiBeginArea(hps, BA_WINDING);
ptl.x = 100; ptl.y = 200;
GpiMove(hps, &ptl);
ptl.x = 200; ptl.y = 400;
GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
ptl.x = 580; ptl.y = 470;
GpiMove(hps, &ptl);
ptl.x = 780; ptl.y = 570;
GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
GpiEndArea(hps);
 
Creating a Custom Fill Pattern from a Bitmap
 
The following code fragment shows how to create a custom fill pattern by
using a hard-coded bitmap, which in this example creates a cross-hatch
pattern:
 
CreatePattern();
GpiSetPatternSet(hps, lcidCustom);
    .
    .
    .
CreatePattern()
{
 
    /* Bitmap information */
 
    HBITMAP hbm;             /* bitmap handle                    */
    BITMAPINFOHEADER bmp;    /* structure for bitmap information */
    PBITMAPINFO pbmi;        /* pointer to structure for data    */
    CHAR cBuffer[80];        /* structure template               */
 
    bmp.cbFix = 12;        /* length of structure */
    bmp.cx = 8;            /* 8 pels wide         */
    bmp.cy = 8;            /* 8 pels high         */
    bmp.cPlanes = 1;       /* 1 plane             */
    bmp.cBitCount = 1;     /* 1 bit per pel       */
 
    /*
     * Initialize the bitmap data by loading "cBuffer" with the bitmap
     * information.
     */
 
    pbmi = (PBITMAPINFO) cBuffer;
    pbmi->cbFix = 12;       /* length of structure */
    pbmi->cx = 8;           /* 8 bits wide         */
    pbmi->cy = 8;           /* 8 bits high         */
    pbmi->cPlanes = 1;      /* 1 plane             */
    pbmi->cBitCount = 1;    /* 1 bit per pel       */
 
    /* Initialize first two color-table entries to black and white. */
 
    pbmi->argbColor[0].bRed = 0;       /* Color[0] = black */
    pbmi->argbColor[0].bGreen = 0;     /* Color[0] = black */
    pbmi->argbColor[0].bBlue = 0;      /* Color[0] = black */
    pbmi->argbColor[1].bRed = 255;     /* Color[1] = white */
    pbmi->argbColor[1].bGreen = 255;   /* Color[1] = white */
    pbmi->argbColor[1].bBlue = 255;    /* Color[1] = white */
 
    /* Create a bitmap and retrieve its handle. */
 
    hbm = GpiCreateBitmap(hps,
        &bmp,
        CBM_INIT,
        (PBYTE) abPattern5,   /* array of bits */
        pbmi);
 
    /* Tag the bitmap just created with a custom identifier (lcid). */
 
    GpiSetBitmapId(hps, hbm, lcidCustom);
}
 
Creating a Custom Fill Pattern from a Font Character
 
The following code fragment shows how to create a custom fill pattern by
using a character from a font:
 
LoadFont();
GpiSetPatternSet(hps, lcidCustom);
GpiSetPattern(hps, lCodePoint);
    .
    .
    .
LoadFont()
{
 
    /* Determine the number of loaded public fonts. */
 
    cFonts = GpiQueryFonts(hps, QF_PUBLIC, NULL, &lCount,
        (LONG) (sizeof(fm)), (PFONTMETRICS) afm);
 
    /* Load the metrics for all public fonts into afm. */
 
    cFonts = GpiQueryFonts(hps, QF_PUBLIC, NULL, &lCount,
        (LONG) (sizeof(fm)), (PFONTMETRICS) afm);
 
    /* Grab the first image font with a point size larger than 8. */
 
    for(i = 1;
        (afm[i].fsDefn % 2 != 0) &&
        (afm[i].sNominalPointSize / 10 >= 8);
        i++);
 
    /* Load the FATTRS structure with corresponding metrics. */
 
    fat.usRecordLength = sizeof(fat);
    fat.fsSelection = afm[i].fsSelection;
    fat.lMatch = afm[i].lMatch;
    strcpy(fat.szFacename, afm[i].szFacename);
    fat.idRegistry = afm[i].idRegistry;
    fat.usCodePage = afm[i].usCodePage;
    fat.lMaxBaselineExt = afm[i].lMaxBaselineExt;
    fat.lAveCharWidth = afm[i].lAveCharWidth;
    fat.fsType = afm[i].fsType;
    fat.fsFontUse = 0;
 
    /* Ask MS OS/2 to select this font and assign it a custom lcid. */
 
    GpiCreateLogFont(hps, (PSTR8) cBuffer, lcidCustom, (PFATTRS) &fat);
    GpiSetCharSet(hps, lcidCustom);
}
 
 
                                      ♦