[Previous] [Contents] [Index] [Next]

PgSetStrokeDash()

Set dashed lines

Synopsis:

void PgSetStrokeDash( unsigned char const *DashList,
                      int ListLen,
                      long DashScale );

Description:

This function defines a dash list that's used to draw lines. The DashList argument points to an array of up to 16 characters. The values alternate between stroke values and space values: the first value defines a stroke length, the next defines a space length, the next after that defines a stroke length, and so on.

The values in DashList are scaled by the DashScale argument, which is 16.16 fixed point. The upper 16 bits are the integer part and the lower 16 the fractional part. The fractional part is in 65536ths, not 10ths, 100ths, etc.

For example, to specify a decimal scaling factor of 1.5:

  1. Put 1 in the upper 16 bits.
  2. Put 0.5 * 65536 = 32768 (i.e. 0x8000) in the lower 16 bits.

The resulting scaling parameter is 0x00018000.

To specify a decimal scaling of 47.75:

  1. Put 47 (i.e. 0x2F) in the upper 16 bits.
  2. Put 0.75 * 65536 = 49152 (i.e. 0xC000) in the lower 16 bits.

The resulting scaling parameter is 0x002FC000.

Examples:

The following example:

typedef struct {
    char    *name;
    int     l;
    char    *p;
} DashListStruct;

/* NOTE: dash patterns are in octal */

DashListStruct DashList[] = {
  "solid",         0,  NULL,
  "dotted",        1,  "\1",
  "bigger dots",   1,  "\2",
  "dashed",        2,  "\10\4",
  "long dash",     2,  "\40\4",
  "dash dot dot",  6,  "\40\2\1\2\1\2",
  "long pattern",  16, 
        "\3\2\5\2\10\2\13\2\15\2\13\2\10\2\5\2",
  "complex",       7,  "\20\1\14\2\11\3\6",
};
#define  DashListNum \
         (sizeof( DashList ) / sizeof( DashListStruct ))
#define  DashListCHeight 20
#define  DashListWinY \
         (DashListNum*DashListCHeight)

Dashes() {
    DashListStruct   *DLPtr = DashList;
    PhPoint_t   p;
    PhRect_t    r;
    int i, y;
    
    PgSetFont( "helv14b" );
    PgSetTextColor( Pg_WHITE );
    PgSetStrokeColor( Pg_WHITE );
    for (y=i=0; i<DashListNum; i++, 
             y+=DashListCHeight, DLPtr++) {
        p.x = 2;
        p.y = y+14;
        PgDrawText( DLPtr->name, strlen( DLPtr->name ), 
                    &p, 0 );
        PgSetStrokeDash( DLPtr->p, DLPtr->l, 0x10000 );
        PgSetFillDither( Pg_WHITE, Pg_DBLUE, DLPtr->p );
        PgDrawILine( 100, y+(DithersListCHeight/2),
                    320, y+(DithersListCHeight/2) );
    }
}

will draw:

PgSetStrokeDash

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PgDrawLine(), PgDrawPolygon(), PgDrawRect(), PgSetStrokeColor(), PgSetStrokeWidth()


[Previous] [Contents] [Index] [Next]