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

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

Solid line drawing function, using Bresenham's mid-point line scan-conversion algorithm.

Parameters:
s a line structure
Returns:
void

Definition at line 249 of file line.c.

References caca_putchar().

Referenced by caca_draw_line(), and caca_draw_polyline().

{
    int x1, y1, x2, y2;
    int dx, dy;
    int xinc, yinc;

    x1 = s->x1; y1 = s->y1; x2 = s->x2; y2 = s->y2;

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

    xinc = (x1 > x2) ? -1 : 1;
    yinc = (y1 > y2) ? -1 : 1;

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

        for(; dx>=0; dx--)
        {
            caca_putchar(x1, y1, s->c);
            if(delta > 0)
            {
                x1 += xinc;
                y1 += yinc;
                delta += dpru;
            }
            else
            {
                x1 += xinc;
                delta += dpr;
            }
        }
    }
    else
    {
        int dpr = dx << 1;
        int dpru = dpr - (dy << 1);
        int delta = dpr - dy;

        for(; dy >= 0; dy--)
        {
            caca_putchar(x1, y1, s->c);
            if(delta > 0)
            {
                x1 += xinc;
                y1 += yinc;
                delta += dpru;
            }
            else
            {
                y1 += yinc;
                delta += dpr;
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index