1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

PixelPaint: Limit editing tools to selection

This effectively creates a double-buffer for tools to use when modifying
the layer's bitmap (content or mask). Once the changes have been made
the tool reports to the layer that it has made changes along with a Rect
of the changed region. The layer will then merge the changes from the
scratch image to the real bitmap. This merge is done as follows: If a
given pixel is inside the selected region, the pixel from the scratch
bitmap is copied to the real bitmap. If the pixel is not inside the
selected region, the pixel from the real bitmap is copied to the scratch
bitmap.

As an optimization, when there is no selection active, the new method
for getting the scratch bitmap will return the real bitmap and no
merging will need to take place.
This commit is contained in:
Timothy Slater 2022-10-22 13:35:52 -05:00 committed by Linus Groh
parent 7c33f8f7df
commit 0d7d759095
8 changed files with 51 additions and 14 deletions

View file

@ -87,10 +87,11 @@ void RectangleTool::on_mouseup(Layer* layer, MouseEvent& event)
return;
if (event.layer_event().button() == m_drawing_button) {
GUI::Painter painter(layer->currently_edited_bitmap());
GUI::Painter painter(layer->get_scratch_edited_bitmap());
draw_using(painter, m_rectangle_start_position, m_rectangle_end_position, m_thickness, m_corner_radius);
m_drawing_button = GUI::MouseButton::None;
layer->did_modify_bitmap();
auto modified_rect = Gfx::IntRect::from_two_points(m_rectangle_start_position, m_rectangle_end_position).inflated(m_thickness * 2, m_thickness * 2);
layer->did_modify_bitmap(modified_rect);
m_editor->update();
m_editor->did_complete_action(tool_name());
}