| 495 | } // namespace |
| 496 | |
| 497 | void GfxRenderer::drawLine(int x1, int y1, int x2, int y2, const bool state) const { |
| 498 | if (fontCacheManager_ && fontCacheManager_->isScanning()) return; |
| 499 | if (x1 == x2) { |
| 500 | if (y2 < y1) { |
| 501 | std::swap(y1, y2); |
| 502 | } |
| 503 | for (int y = y1; y <= y2; y++) { |
| 504 | drawPixel(x1, y, state); |
| 505 | } |
| 506 | } else if (y1 == y2) { |
| 507 | if (x2 < x1) { |
| 508 | std::swap(x1, x2); |
| 509 | } |
| 510 | for (int x = x1; x <= x2; x++) { |
| 511 | drawPixel(x, y1, state); |
| 512 | } |
| 513 | } else { |
| 514 | // Bresenham's line algorithm — integer arithmetic only |
| 515 | int dx = x2 - x1; |
| 516 | int dy = y2 - y1; |
| 517 | int sx = (dx > 0) ? 1 : -1; |
| 518 | int sy = (dy > 0) ? 1 : -1; |
| 519 | dx = sx * dx; // abs |
| 520 | dy = sy * dy; // abs |
| 521 | |
| 522 | int err = dx - dy; |
| 523 | while (true) { |
| 524 | drawPixel(x1, y1, state); |
| 525 | if (x1 == x2 && y1 == y2) break; |
| 526 | int e2 = 2 * err; |
| 527 | if (e2 > -dy) { |
| 528 | err -= dy; |
| 529 | x1 += sx; |
| 530 | } |
| 531 | if (e2 < dx) { |
| 532 | err += dx; |
| 533 | y1 += sy; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | void GfxRenderer::drawLine(int x1, int y1, int x2, int y2, const int lineWidth, const bool state) const { |
| 540 | for (int i = 0; i < lineWidth; i++) { |
no test coverage detected