* Draws a line from (x1, y1) to (x2, y2) using given colour. * @param x1 The X-coordinate of the begin of the line. * @param y1 The Y-coordinate of the begin of the line. * @param x2 The X-coordinate of the end of the line. * @param y2 The Y-coordinate of the end of the line. * @param colour The colour to use to draw the line. */
| 2481 | * @param colour The colour to use to draw the line. |
| 2482 | */ |
| 2483 | void GUI_DrawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint8 colour) |
| 2484 | { |
| 2485 | uint8 *screen = GFX_Screen_GetActive(); |
| 2486 | int16 increment = 1; |
| 2487 | |
| 2488 | if (x1 < g_clipping.left || x1 > g_clipping.right || y1 < g_clipping.top || y1 > g_clipping.bottom || x2 < g_clipping.left || x2 > g_clipping.right || y2 < g_clipping.top || y2 > g_clipping.bottom) { |
| 2489 | while (true) { |
| 2490 | uint16 clip1 = GetNeededClipping(x1, y1); |
| 2491 | uint16 clip2 = GetNeededClipping(x2, y2); |
| 2492 | |
| 2493 | if (clip1 == 0 && clip2 == 0) break; |
| 2494 | if ((clip1 & clip2) != 0) return; |
| 2495 | |
| 2496 | switch (clip1) { |
| 2497 | case 1: case 9: ClipTop(&x1, &y1, x2, y2); break; |
| 2498 | case 2: case 6: ClipBottom(&x1, &y1, x2, y2); break; |
| 2499 | case 4: case 5: ClipLeft(&x1, &y1, x2, y2); break; |
| 2500 | case 8: case 10: ClipRight(&x1, &y1, x2, y2); break; |
| 2501 | default: |
| 2502 | switch (clip2) { |
| 2503 | case 1: case 9: ClipTop(&x2, &y2, x1, y1); break; |
| 2504 | case 2: case 6: ClipBottom(&x2, &y2, x1, y1); break; |
| 2505 | case 4: case 5: ClipLeft(&x2, &y2, x1, y1); break; |
| 2506 | case 8: case 10: ClipRight(&x2, &y2, x1, y1); break; |
| 2507 | default: break; |
| 2508 | } |
| 2509 | } |
| 2510 | } |
| 2511 | } |
| 2512 | |
| 2513 | y2 -= y1; |
| 2514 | |
| 2515 | if (y2 == 0) { |
| 2516 | if (x1 >= x2) { |
| 2517 | int16 x = x1; |
| 2518 | x1 = x2; |
| 2519 | x2 = x; |
| 2520 | } |
| 2521 | |
| 2522 | x2 -= x1 - 1; |
| 2523 | |
| 2524 | screen += y1 * SCREEN_WIDTH + x1; |
| 2525 | |
| 2526 | memset(screen, colour, x2); |
| 2527 | return; |
| 2528 | } |
| 2529 | |
| 2530 | if (y2 < 0) { |
| 2531 | int16 x = x1; |
| 2532 | x1 = x2; |
| 2533 | x2 = x; |
| 2534 | y2 = -y2; |
| 2535 | y1 -= y2; |
| 2536 | } |
| 2537 | |
| 2538 | screen += y1 * SCREEN_WIDTH; |
| 2539 | |
| 2540 | x2 -= x1; |
no test coverage detected