summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorTibor Nagy <xnagytibor@gmail.com>2020-04-05 13:01:13 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-05 15:30:53 +0200
commite14d27867c26ae27e1a9fd1e9ee83b36c4bca8dc (patch)
tree0c131fb55c634df364028bda73efd6fa0f556076 /Libraries
parentde32fd034745581d72d317232fcf47d45deed021 (diff)
downloadserenity-e14d27867c26ae27e1a9fd1e9ee83b36c4bca8dc.zip
LibGfx: Implement checkerboard drawing for Gfx::Painter
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGfx/Painter.cpp19
-rw-r--r--Libraries/LibGfx/Painter.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp
index 8d85517d87..2033f0fac7 100644
--- a/Libraries/LibGfx/Painter.cpp
+++ b/Libraries/LibGfx/Painter.cpp
@@ -142,6 +142,25 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
}
}
+void Painter::fill_rect_with_checkerboard(const Rect& a_rect, const Size& cell_size, Color color_dark, Color color_light)
+{
+ auto rect = a_rect.translated(translation()).intersected(clip_rect());
+ if (rect.is_empty())
+ return;
+
+ RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
+ const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
+
+ for (int i = 0; i < rect.height(); ++i) {
+ for (int j = 0; j < rect.width(); ++j) {
+ int cell_row = i / cell_size.height();
+ int cell_col = j / cell_size.width();
+ dst[j] = ((cell_row % 2) ^ (cell_col % 2)) ? color_light.value() : color_dark.value();
+ }
+ dst += dst_skip;
+ }
+}
+
void Painter::fill_rect_with_gradient(Orientation orientation, const Rect& a_rect, Color gradient_start, Color gradient_end)
{
#ifdef NO_FPU
diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h
index 0f141583c5..b4923bded1 100644
--- a/Libraries/LibGfx/Painter.h
+++ b/Libraries/LibGfx/Painter.h
@@ -45,6 +45,7 @@ public:
~Painter();
void clear_rect(const Rect&, Color);
void fill_rect(const Rect&, Color);
+ void fill_rect_with_checkerboard(const Rect&, const Size&, Color color_dark, Color color_light);
void fill_rect_with_gradient(Orientation, const Rect&, Color gradient_start, Color gradient_end);
void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end);
void draw_rect(const Rect&, Color, bool rough = false);