PixelPaint: Make PenTool only invalidate the modified area :^)

This commit is contained in:
Andreas Kling 2021-07-06 20:38:24 +02:00
parent f7053059c9
commit 7cbcf5a5fa

View file

@ -31,7 +31,7 @@ void PenTool::on_mousedown(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent
GUI::Painter painter(layer.bitmap());
painter.draw_line(event.position(), event.position(), m_editor->color_for(event), m_thickness);
layer.did_modify_bitmap();
layer.did_modify_bitmap(Gfx::IntRect::centered_on(event.position(), Gfx::IntSize { m_thickness, m_thickness }));
m_last_drawing_event_position = event.position();
}
@ -49,11 +49,16 @@ void PenTool::on_mousemove(Layer& layer, GUI::MouseEvent& event, GUI::MouseEvent
return;
GUI::Painter painter(layer.bitmap());
if (m_last_drawing_event_position != Gfx::IntPoint(-1, -1))
Gfx::IntRect changed_rect;
if (m_last_drawing_event_position != Gfx::IntPoint(-1, -1)) {
painter.draw_line(m_last_drawing_event_position, event.position(), m_editor->color_for(event), m_thickness);
else
changed_rect = Gfx::IntRect::from_two_points(m_last_drawing_event_position, event.position());
} else {
painter.draw_line(event.position(), event.position(), m_editor->color_for(event), m_thickness);
layer.did_modify_bitmap();
changed_rect = Gfx::IntRect::from_two_points(event.position(), event.position());
}
changed_rect.inflate(m_thickness * 4, m_thickness * 4);
layer.did_modify_bitmap(changed_rect);
m_last_drawing_event_position = event.position();
}