Browse Source

LibGUI+LibGfx: Paint scollbar tracks with a dithered pattern

Instead of a solid color, we now paint the track/gutter of scrollbars
using a 2-color dither pattern for a pleasant millennium feel. :^)
Andreas Kling 5 years ago
parent
commit
9e74793ce2
3 changed files with 22 additions and 1 deletions
  1. 1 1
      Libraries/LibGUI/ScrollBar.cpp
  2. 20 0
      Libraries/LibGfx/Painter.cpp
  3. 1 0
      Libraries/LibGfx/Painter.h

+ 1 - 1
Libraries/LibGUI/ScrollBar.cpp

@@ -220,7 +220,7 @@ void ScrollBar::paint_event(PaintEvent& event)
     Painter painter(*this);
     Painter painter(*this);
     painter.add_clip_rect(event.rect());
     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 decrement_pressed = m_automatic_scrolling_direction == AutomaticScrollingDirection::Decrement;
     bool increment_pressed = m_automatic_scrolling_direction == AutomaticScrollingDirection::Increment;
     bool increment_pressed = m_automatic_scrolling_direction == AutomaticScrollingDirection::Increment;

+ 20 - 0
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)
 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());
     auto rect = a_rect.translated(translation()).intersected(clip_rect());

+ 1 - 0
Libraries/LibGfx/Painter.h

@@ -45,6 +45,7 @@ public:
     ~Painter();
     ~Painter();
     void clear_rect(const Rect&, Color);
     void clear_rect(const Rect&, Color);
     void fill_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_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(Orientation, const Rect&, Color gradient_start, Color gradient_end);
     void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end);
     void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end);