From 0ac77f874487d9dbf16b88448a584cc83e014d82 Mon Sep 17 00:00:00 2001 From: frutiemax Date: Tue, 11 May 2021 07:16:59 -0400 Subject: [PATCH] Part of #12100 : Use ScreenCoordsXY for gfx_draw_line_on_buffer (#14305) --- src/openrct2/drawing/Line.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/openrct2/drawing/Line.cpp b/src/openrct2/drawing/Line.cpp index b6082d8250..15122bc27c 100644 --- a/src/openrct2/drawing/Line.cpp +++ b/src/openrct2/drawing/Line.cpp @@ -16,44 +16,43 @@ * Draws a horizontal line of specified colour to a buffer. * rct2: 0x0068474C */ -static void gfx_draw_line_on_buffer(rct_drawpixelinfo* dpi, char colour, int32_t y, int32_t x, int32_t no_pixels) +static void gfx_draw_line_on_buffer(rct_drawpixelinfo* dpi, char colour, const ScreenCoordsXY& coords, int32_t no_pixels) { - y -= dpi->y; + ScreenCoordsXY offset{ coords.x - dpi->x, coords.y - dpi->y }; // Check to make sure point is in the y range - if (y < 0) + if (offset.y < 0) return; - if (y >= dpi->height) + if (offset.y >= dpi->height) return; // Check to make sure we are drawing at least a pixel if (!no_pixels) no_pixels++; - x -= dpi->x; - // If x coord outside range leave - if (x < 0) + if (offset.x < 0) { // Unless the number of pixels is enough to be in range - no_pixels += x; + no_pixels += offset.x; if (no_pixels <= 0) return; // Resets starting point to 0 as we don't draw outside the range - x = 0; + offset.x = 0; } // Ensure that the end point of the line is within range - if (x + no_pixels - dpi->width > 0) + if (offset.x + no_pixels - dpi->width > 0) { // If the end point has any pixels outside range // cut them off. If there are now no pixels return. - no_pixels -= x + no_pixels - dpi->width; + no_pixels -= offset.x + no_pixels - dpi->width; if (no_pixels <= 0) return; } // Get the buffer we are drawing to and move to the first coordinate. - uint8_t* bits_pointer = dpi->bits + y * (dpi->pitch + dpi->width) + x; + uint8_t* bits_pointer = dpi->bits + + offset.y * (static_cast(static_cast(dpi->pitch) + static_cast(dpi->width))) + offset.x; // Draw the line to the specified colour for (; no_pixels > 0; --no_pixels, ++bits_pointer) @@ -141,14 +140,14 @@ void gfx_draw_line_software(rct_drawpixelinfo* dpi, const ScreenLine& line, int3 { // Vertical lines are drawn 1 pixel at a time if (steep) - gfx_draw_line_on_buffer(dpi, colour, x, y, 1); + gfx_draw_line_on_buffer(dpi, colour, { y, x }, 1); error -= delta_y; if (error < 0) { // Non vertical lines are drawn with as many pixels in a horizontal line as possible if (!steep) - gfx_draw_line_on_buffer(dpi, colour, y, x_start, no_pixels); + gfx_draw_line_on_buffer(dpi, colour, { x_start, y }, no_pixels); // Reset non vertical line vars x_start = x + 1; @@ -160,7 +159,7 @@ void gfx_draw_line_software(rct_drawpixelinfo* dpi, const ScreenLine& line, int3 // Catch the case of the last line if (x + 1 == x2 && !steep) { - gfx_draw_line_on_buffer(dpi, colour, y, x_start, no_pixels); + gfx_draw_line_on_buffer(dpi, colour, { x_start, y }, no_pixels); } } }