1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 12:03:07 +01:00

Part of #12100 : Use ScreenCoordsXY for gfx_draw_line_on_buffer (#14305)

This commit is contained in:
frutiemax
2021-05-11 07:16:59 -04:00
committed by GitHub
parent ae66592c2b
commit 0ac77f8744

View File

@@ -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<int64_t>(static_cast<int64_t>(dpi->pitch) + static_cast<int64_t>(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);
}
}
}