Exemplo n.º 1
0
Arquivo: GLCD.c Projeto: jschisler/pic
void GLCD_DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color)
{
    uint8_t deltax, deltay, x, y, steep;
    int8_t error, ystep;

    steep = _GLCD_absDiff(y1, y2) > _GLCD_absDiff(x1, x2);

    if (steep) {
        _GLCD_swap(x1, y1);
        _GLCD_swap(x2, y2);
    }

    if (x1 > x2) {
        _GLCD_swap(x1, x2);
        _GLCD_swap(y1, y2);
    }

    deltax = x2 - x1;
    deltay = _GLCD_absDiff(y2, y1);
    error = deltax / 2;
    y = y1;
    if (y1 < y2) ystep = 1;
    else ystep = -1;

    for (x = x1; x <= x2; x++) {
        if (steep) GLCD_SetDot(y, x, color);
        else GLCD_SetDot(x, y, color);
        error = error - deltay;
        if (error < 0) {
            y = y + ystep;
            error = error + deltax;
        }
    }
}
Exemplo n.º 2
0
void glcd::DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,
                    uint8_t color) {
    uint8_t deltax, deltay, x, y, steep;
    int8_t error, ystep;

#ifdef XXX
    /*
     * Rather than fudge up coordinates that are outside of range,
     * It is better to allow the algorithm to run with them "as is"
     * so that any pixels on the line that land inside the valid display
     * coordinates will be drawn properly.
     *
     * If the coordinates are patched, then the line drawn will not
     * be anything close to the original slope as the endpoint coordinates
     * will have been altered.
     */

    if (x1 >= this->CurrentWidth())
        x1 = 0;
    if (x2 >= this->CurrentWidth())
        x2 = 0;
    if (y1 >= this->CurrentHeight())
        y1 = 0;
    if (y2 >= this->CurrentHeight())
        y2 = 0;
#endif

    steep = _GLCD_absDiff(y1, y2) > _GLCD_absDiff(x1, x2);

    if (steep) {
        _GLCD_swap(x1, y1);
        _GLCD_swap(x2, y2);
    }

    if (x1 > x2) {
        _GLCD_swap(x1, x2);
        _GLCD_swap(y1, y2);
    }

    deltax = x2 - x1;
    deltay = _GLCD_absDiff(y2, y1);
    error = deltax / 2;
    y = y1;
    if (y1 < y2)
        ystep = 1;
    else
        ystep = -1;

    for (x = x1; x <= x2; x++) {
        if (steep)
            this->SetDot(y, x, color);
        else
            this->SetDot(x, y, color);
        error = error - deltay;
        if (error < 0) {
            y = y + ystep;
            error = error + deltax;
        }
    }
}