diff --git a/Libraries/LibGUI/ScrollBar.cpp b/Libraries/LibGUI/ScrollBar.cpp index f29308b969..3844ad2330 100644 --- a/Libraries/LibGUI/ScrollBar.cpp +++ b/Libraries/LibGUI/ScrollBar.cpp @@ -220,7 +220,7 @@ void ScrollBar::paint_event(PaintEvent& event) Painter painter(*this); painter.add_clip_rect(event.rect()); - painter.fill_rect(rect(), palette().button().lightened(1.1f)); + painter.fill_rect_with_dither_pattern(rect(), palette().button().lightened(1.3f), palette().button()); bool decrement_pressed = m_automatic_scrolling_direction == AutomaticScrollingDirection::Decrement; bool increment_pressed = m_automatic_scrolling_direction == AutomaticScrollingDirection::Increment; diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index f312ab2612..418e1d47f2 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -136,6 +136,26 @@ void Painter::fill_rect(const Rect& a_rect, Color color) } } +void Painter::fill_rect_with_dither_pattern(const Rect& a_rect, Color color_a, Color color_b) +{ + 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) { + if (i & 1) + dst[j] = (j & 1) ? color_a.value() : color_b.value(); + else + dst[j] = (j & 1) ? color_b.value() : color_a.value(); + } + dst += dst_skip; + } +} + 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()); diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h index 87ecf8b045..d02535e608 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_dither_pattern(const Rect&, Color, 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);