* Symmetric Double Step Line Algorithm * by Brian Wyvill * from "Graphics Gems", Academic Press, 1990 * * Exact copy from https://github.com/erich666/GraphicsGems/blob/dad26f941e12c8bf1f96ea21c1c04cd2206ae7c9/gems/DoubleLine.c * Except: * - not in view checks * - global variable instead of reverse flag * - condition for pixels_left < 0 removed * * @brief Draw a line on the back
| 659 | * @param col Color index from current palette |
| 660 | */ |
| 661 | void DrawLine(int x0, int y0, int x1, int y1, BYTE col) |
| 662 | { |
| 663 | int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left; |
| 664 | int sign_x, sign_y, step, i; |
| 665 | int x1_, y1_; |
| 666 | |
| 667 | gbPixelCol = col; |
| 668 | |
| 669 | gbNotInView = FALSE; |
| 670 | if (x0 < 0 + SCREEN_X || x0 >= SCREEN_WIDTH + SCREEN_X) { |
| 671 | gbNotInView = TRUE; |
| 672 | } |
| 673 | if (x1 < 0 + SCREEN_X || x1 >= SCREEN_WIDTH + SCREEN_X) { |
| 674 | gbNotInView = TRUE; |
| 675 | } |
| 676 | if (y0 < 0 + SCREEN_Y || y0 >= PANEL_Y) { |
| 677 | gbNotInView = TRUE; |
| 678 | } |
| 679 | if (y1 < 0 + SCREEN_Y || y1 >= PANEL_Y) { |
| 680 | gbNotInView = TRUE; |
| 681 | } |
| 682 | |
| 683 | dx = GG_ABSOLUTE(x1, x0, sign_x); |
| 684 | dy = GG_ABSOLUTE(y1, y0, sign_y); |
| 685 | /* decide increment sign by the slope sign */ |
| 686 | if (sign_x == sign_y) |
| 687 | step = 1; |
| 688 | else |
| 689 | step = -1; |
| 690 | |
| 691 | if (dy > dx) { /* chooses axis of greatest movement (make |
| 692 | * dx) */ |
| 693 | GG_SWAP(x0, y0); |
| 694 | GG_SWAP(x1, y1); |
| 695 | GG_SWAP(dx, dy); |
| 696 | gbRotateMap = TRUE; |
| 697 | } else |
| 698 | gbRotateMap = FALSE; |
| 699 | /* note error check for dx==0 should be included here */ |
| 700 | if (x0 > x1) { /* start from the smaller coordinate */ |
| 701 | x = x1; |
| 702 | y = y1; |
| 703 | x1_ = x0; |
| 704 | y1_ = y0; |
| 705 | } else { |
| 706 | x = x0; |
| 707 | y = y0; |
| 708 | x1_ = x1; |
| 709 | y1_ = y1; |
| 710 | } |
| 711 | |
| 712 | /* Note dx=n implies 0 - n or (dx+1) pixels to be set */ |
| 713 | /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */ |
| 714 | /* In fact (dx-1)/4 as 2 pixels are already plotted */ |
| 715 | xend = (dx - 1) / 4; |
| 716 | pixels_left = (dx - 1) % 4; /* number of pixels left over at the end */ |
| 717 | engine_draw_pixel(x, y); |
| 718 | engine_draw_pixel(x1_, y1_); /* plot first two points */ |
no test coverage detected