Sfoglia il codice sorgente

LibGUI: Make Widget ignore paint events that don't intersect it

LibGUI widgets fully contain their child widgets, so there's no pass
the paint event on to our children if we get a paint event that doesn't
intersect with our rect.

While Gfx::Painter was already dutifully clipping out any attempts at
painting, this avoids even more pointless work.
Andreas Kling 4 anni fa
parent
commit
b7e551b164
1 ha cambiato i file con 7 aggiunte e 0 eliminazioni
  1. 7 0
      Userland/Libraries/LibGUI/Widget.cpp

+ 7 - 0
Userland/Libraries/LibGUI/Widget.cpp

@@ -318,6 +318,13 @@ void Widget::handle_keydown_event(KeyEvent& event)
 void Widget::handle_paint_event(PaintEvent& event)
 {
     VERIFY(is_visible());
+
+    if (!rect().intersects(event.rect())) {
+        // This widget is not inside the paint event rect.
+        // Since widgets fully contain their children, we don't need to recurse further.
+        return;
+    }
+
     if (fill_with_background_color()) {
         Painter painter(*this);
         painter.fill_rect(event.rect(), palette().color(background_role()));