1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:07:34 +00:00

LibGfx: Add Painter::fill_rect(rect, paint_style)

The usual fill_rect()... but with style :^)
This commit is contained in:
MacDue 2023-01-15 22:18:46 +00:00 committed by Andreas Kling
parent 223cedc896
commit f3c0987afe
2 changed files with 20 additions and 0 deletions

View file

@ -151,6 +151,25 @@ void Painter::fill_rect(IntRect const& a_rect, Color color)
fill_physical_rect(rect * scale(), color); fill_physical_rect(rect * scale(), color);
} }
void Painter::fill_rect(IntRect const& rect, PaintStyle const& paint_style)
{
auto a_rect = rect.translated(translation());
auto clipped_rect = a_rect.intersected(clip_rect());
if (clipped_rect.is_empty())
return;
a_rect *= scale();
clipped_rect *= scale();
auto start_offset = clipped_rect.location() - a_rect.location();
paint_style.paint(a_rect, [&](PaintStyle::SamplerFunction sample) {
for (int y = 0; y < clipped_rect.height(); ++y) {
for (int x = 0; x < clipped_rect.width(); ++x) {
IntPoint point(x, y);
set_physical_pixel(point + clipped_rect.location(), sample(point + start_offset), true);
}
}
});
}
void Painter::fill_rect_with_dither_pattern(IntRect const& a_rect, Color color_a, Color color_b) void Painter::fill_rect_with_dither_pattern(IntRect const& a_rect, Color color_a, Color color_b)
{ {
VERIFY(scale() == 1); // FIXME: Add scaling support. VERIFY(scale() == 1); // FIXME: Add scaling support.

View file

@ -48,6 +48,7 @@ public:
void clear_rect(IntRect const&, Color); void clear_rect(IntRect const&, Color);
void fill_rect(IntRect const&, Color); void fill_rect(IntRect const&, Color);
void fill_rect(IntRect const&, PaintStyle const&);
void fill_rect_with_dither_pattern(IntRect const&, Color, Color); void fill_rect_with_dither_pattern(IntRect const&, Color, Color);
void fill_rect_with_checkerboard(IntRect const&, IntSize, Color color_dark, Color color_light); void fill_rect_with_checkerboard(IntRect const&, IntSize, Color color_dark, Color color_light);
void fill_rect_with_gradient(Orientation, IntRect const&, Color gradient_start, Color gradient_end); void fill_rect_with_gradient(Orientation, IntRect const&, Color gradient_start, Color gradient_end);