Logo Search packages:      
Sourcecode: libcaca version File versions  Download package

static void draw_thin_line ( struct line *  s  )  [static]

Thin line drawing function, using Bresenham's mid-point line scan-conversion algorithm and ASCII art graphics.

Parameters:
s a line structure
Returns:
void

Definition at line 316 of file line.c.

References caca_putchar().

Referenced by caca_draw_thin_line(), and caca_draw_thin_polyline().

{
    char *charmapx, *charmapy;
    int x1, y1, x2, y2;
    int dx, dy;
    int yinc;

    if(s->x2 >= s->x1)
    {
        if(s->y1 > s->y2)
            charmapx = ",'";
        else
            charmapx = "`.";
        x1 = s->x1; y1 = s->y1; x2 = s->x2; y2 = s->y2;
    }
    else
    {
        if(s->y1 > s->y2)
            charmapx = "`.";
        else
            charmapx = ",'";
        x2 = s->x1; y2 = s->y1; x1 = s->x2; y1 = s->y2;
    }

    dx = abs(x2 - x1);
    dy = abs(y2 - y1);

    if(y1 > y2)
    {
        charmapy = ",'";
        yinc = -1;
    }
    else
    {
        yinc = 1;
        charmapy = "`.";
    }

    if(dx >= dy)
    {
        int dpr = dy << 1;
        int dpru = dpr - (dx << 1);
        int delta = dpr - dx;
        int prev = 0;

        for(; dx>=0; dx--)
        {
            if(delta > 0)
            {
                caca_putchar(x1, y1, charmapy[1]);
                x1++;
                y1 += yinc;
                delta += dpru;
                prev = 1;
            }
            else
            {
                if(prev)
                    caca_putchar(x1, y1, charmapy[0]);
                else
                    caca_putchar(x1, y1, '-');
                x1++;
                delta += dpr;
                prev = 0;
            }
        }
    }
    else
    {
        int dpr = dx << 1;
        int dpru = dpr - (dy << 1);
        int delta = dpr - dy;

        for(; dy >= 0; dy--)
        {
            if(delta > 0)
            {
                caca_putchar(x1, y1, charmapx[0]);
                caca_putchar(x1 + 1, y1, charmapx[1]);
                x1++;
                y1 += yinc;
                delta += dpru;
            }
            else
            {
                caca_putchar(x1, y1, '|');
                y1 += yinc;
                delta += dpr;
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index