From 981104e3080fcc4b71923c21cec5347c2346ce1e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 19 May 2022 00:12:17 +0100 Subject: [PATCH] Add a functor fill mode to GfxFillPolygon --- src/gfx.cpp | 7 ++++++- src/gfx_func.h | 2 +- src/gfx_type.h | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index ea56408cea..3c26803a4b 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -226,8 +226,9 @@ static std::vector MakePolygonSegments(const std::vector &sh * FILLRECT_OPAQUE: Fill the polygon with the specified colour. * FILLRECT_CHECKER: Fill every other pixel with the specified colour, in a checkerboard pattern. * FILLRECT_RECOLOUR: Apply a recolour sprite to every pixel in the polygon. + * FILLRECT_FUNCTOR: Apply a functor to a line of pixels. */ -void GfxFillPolygon(const std::vector &shape, int colour, FillRectMode mode) +void GfxFillPolygon(const std::vector &shape, int colour, FillRectMode mode, GfxFillRectModeFunctor *fill_functor) { Blitter *blitter = BlitterFactory::GetCurrentBlitter(); const DrawPixelInfo *dpi = _cur_dpi; @@ -308,6 +309,10 @@ void GfxFillPolygon(const std::vector &shape, int colour, FillRectMode mo blitter->SetPixel(dst, x, 0, (uint8)colour); } break; + case FILLRECT_FUNCTOR: + /* Call the provided fill functor. */ + fill_functor(dst, x2 - x1); + break; } } diff --git a/src/gfx_func.h b/src/gfx_func.h index ead2ff8e1c..6c37a97f04 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -104,7 +104,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, void DrawCharCentered(WChar c, const Rect &r, TextColour colour); void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE); -void GfxFillPolygon(const std::vector &shape, int colour, FillRectMode mode = FILLRECT_OPAQUE); +void GfxFillPolygon(const std::vector &shape, int colour, FillRectMode mode = FILLRECT_OPAQUE, GfxFillRectModeFunctor *fill_functor = nullptr); void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0); void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); diff --git a/src/gfx_type.h b/src/gfx_type.h index 377278f466..30fcbc67b8 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -288,8 +288,11 @@ enum FillRectMode { FILLRECT_OPAQUE, ///< Fill rectangle with a single colour FILLRECT_CHECKER, ///< Draw only every second pixel, used for greying-out FILLRECT_RECOLOUR, ///< Apply a recolour sprite to the screen content + FILLRECT_FUNCTOR, ///< Apply a functor to a line of pixels }; +typedef void GfxFillRectModeFunctor(void *pixel, int count); + /** Palettes OpenTTD supports. */ enum PaletteType { PAL_DOS, ///< Use the DOS palette.