From 26d0b8339f9c25dbb3c6f9b01f8184a7d9ee77af Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 22 Jun 2018 13:00:26 +0200 Subject: [PATCH] Win32: Fix Screen_FillRect() : add clipping --- src/win32screen.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/win32screen.c b/src/win32screen.c index c8781624..123d88b0 100644 --- a/src/win32screen.c +++ b/src/win32screen.c @@ -346,6 +346,24 @@ void Screen_FillRect(int x, int y, int w, int h, byte color) int i; byte * ptr; + if (x < 0) + { + w += x; + x = 0; + } + if (y < 0) + { + h += y; + y = 0; + } + if (x > Windows_DIB_width || y > Windows_DIB_height) + return; + if ((x + w) > Windows_DIB_width) + w = Windows_DIB_width - x; + if ((y + h) > Windows_DIB_height) + h = Windows_DIB_height - y; + if (w <= 0 || h <= 0) + return; for (i = 0; i < h; i++) { ptr = Get_Screen_pixel_ptr(x, y + i); memset(ptr, color, w);