Caution: This version of this document is no longer maintained. For the latest documentation, see

PgSetStrokeDash(), PgSetStrokeDashCx()

Set dashed lines


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

void PgSetStrokeDashCx( PhGC_t *gc,
                        unsigned char const *DashList,
                        int ListLen,
                        long DashScale );




These functions define 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.

PgSetStrokeDash() works on the current graphics context, while you can specify the graphics context gc for PgSetStrokeDashCx().


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,
  "complex",       7,  "\20\1\14\2\11\3\6",
#define  DashListNum \
         (sizeof( DashList ) / sizeof( DashListStruct ))
#define  DashListCHeight 20
#define  DashListWinY \

Dashes() {
    DashListStruct   *DLPtr = DashList;
    PhPoint_t   p;
    PhRect_t    r;
    int i, y;
    char Helvetica14b[MAX_FONT_TAG];

    if(PfGenerateFontName("Helvetica", PF_STYLE_BOLD, 14,
                          Helvetica14b) != NULL)
        PgSetFont( Helvetica14b );

    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+(DashListCHeight/2),
                    320, y+(DashListCHeight/2) );

The above code draws:




Interrupt handler No
Signal handler No
Thread No

See also:

PgDefaultStroke*(), PgDrawLine*(), PgDrawPolygon*(), PgDrawRect*(), PgSetDrawMode*(), PgSetStrokeCap*(), PgSetStrokeDither*(), PgSetStrokeJoin*(), PgSetStrokeTransPat*(), PgSetStrokeWidth*(), PgSetStrokeXORColor*()

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