Przeglądaj źródła

SharedGraphics: Make Painter::fill_rect() respect the current DrawOp.

Andreas Kling 6 lat temu
rodzic
commit
b7967d1292
2 zmienionych plików z 25 dodań i 0 usunięć
  1. 24 0
      SharedGraphics/Painter.cpp
  2. 1 0
      SharedGraphics/Painter.h

+ 24 - 0
SharedGraphics/Painter.cpp

@@ -56,8 +56,32 @@ Painter::~Painter()
 #endif
 }
 
+void Painter::fill_rect_with_draw_op(const Rect& a_rect, Color color)
+{
+    auto rect = a_rect;
+    rect.move_by(m_translation);
+    rect.intersect(m_clip_rect);
+
+    if (rect.is_empty())
+        return;
+
+    RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
+    const unsigned dst_skip = m_target->width();
+
+    for (int i = rect.height() - 1; i >= 0; --i) {
+        for (int j = 0; j < rect.width(); ++j)
+            set_pixel_with_draw_op(dst[j], color.value());
+        dst += dst_skip;
+    }
+}
+
 void Painter::fill_rect(const Rect& a_rect, Color color)
 {
+    if (m_draw_op != DrawOp::Copy) {
+        fill_rect_with_draw_op(a_rect, color);
+        return;
+    }
+
     auto rect = a_rect;
     rect.move_by(m_translation);
     rect.intersect(m_clip_rect);

+ 1 - 0
SharedGraphics/Painter.h

@@ -47,6 +47,7 @@ public:
 
 private:
     void set_pixel_with_draw_op(dword& pixel, const Color&);
+    void fill_rect_with_draw_op(const Rect&, Color);
 
     const Font* m_font;
     Point m_translation;