mirror of
https://github.com/RGBCube/serenity
synced 2025-06-19 21:32:06 +00:00
PixelPaint: Allow partial invalidation of Layer and Image
Let's give ourselves the tools needed to update less than the entire image every time we paint. This patch adds plumbing so that Layer invalidations have a modified rect that gets passed on to Image, and then on to ImageEditor.
This commit is contained in:
parent
b7e551b164
commit
f7053059c9
6 changed files with 14 additions and 13 deletions
|
@ -384,13 +384,13 @@ void Image::remove_client(ImageClient& client)
|
|||
m_clients.remove(&client);
|
||||
}
|
||||
|
||||
void Image::layer_did_modify_bitmap(Badge<Layer>, Layer const& layer)
|
||||
void Image::layer_did_modify_bitmap(Badge<Layer>, Layer const& layer, Gfx::IntRect const& modified_layer_rect)
|
||||
{
|
||||
auto layer_index = index_of(layer);
|
||||
for (auto* client : m_clients)
|
||||
client->image_did_modify_layer(layer_index);
|
||||
|
||||
did_change();
|
||||
did_change(modified_layer_rect.translated(layer.location()));
|
||||
}
|
||||
|
||||
void Image::layer_did_modify_properties(Badge<Layer>, Layer const& layer)
|
||||
|
@ -402,10 +402,11 @@ void Image::layer_did_modify_properties(Badge<Layer>, Layer const& layer)
|
|||
did_change();
|
||||
}
|
||||
|
||||
void Image::did_change()
|
||||
void Image::did_change(Gfx::IntRect const& a_modified_rect)
|
||||
{
|
||||
auto modified_rect = a_modified_rect.is_empty() ? this->rect() : a_modified_rect;
|
||||
for (auto* client : m_clients)
|
||||
client->image_did_change();
|
||||
client->image_did_change(modified_rect);
|
||||
}
|
||||
|
||||
ImageUndoCommand::ImageUndoCommand(Image& image)
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
virtual void image_did_remove_layer(size_t) { }
|
||||
virtual void image_did_modify_layer(size_t) { }
|
||||
virtual void image_did_modify_layer_stack() { }
|
||||
virtual void image_did_change() { }
|
||||
virtual void image_did_change(Gfx::IntRect const&) { }
|
||||
virtual void image_select_layer(Layer*) { }
|
||||
virtual void image_did_change_title(String const&) { }
|
||||
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
void add_client(ImageClient&);
|
||||
void remove_client(ImageClient&);
|
||||
|
||||
void layer_did_modify_bitmap(Badge<Layer>, Layer const&);
|
||||
void layer_did_modify_bitmap(Badge<Layer>, Layer const&, Gfx::IntRect const& modified_layer_rect);
|
||||
void layer_did_modify_properties(Badge<Layer>, Layer const&);
|
||||
|
||||
size_t index_of(Layer const&) const;
|
||||
|
@ -88,7 +88,7 @@ private:
|
|||
|
||||
static Result<NonnullRefPtr<Image>, String> try_create_from_pixel_paint_file(String const& file_path);
|
||||
|
||||
void did_change();
|
||||
void did_change(Gfx::IntRect const& modified_rect = {});
|
||||
void did_modify_layer_stack();
|
||||
|
||||
String m_path;
|
||||
|
|
|
@ -399,9 +399,9 @@ void ImageEditor::relayout()
|
|||
update();
|
||||
}
|
||||
|
||||
void ImageEditor::image_did_change()
|
||||
void ImageEditor::image_did_change(Gfx::IntRect const& modified_image_rect)
|
||||
{
|
||||
update(m_editor_image_rect);
|
||||
update(m_editor_image_rect.intersected(enclosing_int_rect(image_rect_to_editor_rect(modified_image_rect))));
|
||||
}
|
||||
|
||||
void ImageEditor::image_did_change_title(String const& path)
|
||||
|
|
|
@ -87,7 +87,7 @@ private:
|
|||
virtual void context_menu_event(GUI::ContextMenuEvent&) override;
|
||||
virtual void resize_event(GUI::ResizeEvent&) override;
|
||||
|
||||
virtual void image_did_change() override;
|
||||
virtual void image_did_change(Gfx::IntRect const&) override;
|
||||
virtual void image_select_layer(Layer*) override;
|
||||
virtual void image_did_change_title(String const&) override;
|
||||
|
||||
|
|
|
@ -61,9 +61,9 @@ Layer::Layer(Image& image, NonnullRefPtr<Gfx::Bitmap> bitmap, String name)
|
|||
{
|
||||
}
|
||||
|
||||
void Layer::did_modify_bitmap()
|
||||
void Layer::did_modify_bitmap(Gfx::IntRect const& rect)
|
||||
{
|
||||
m_image.layer_did_modify_bitmap({}, *this);
|
||||
m_image.layer_did_modify_bitmap({}, *this, rect);
|
||||
}
|
||||
|
||||
void Layer::set_visible(bool visible)
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
void set_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap) { m_bitmap = move(bitmap); }
|
||||
|
||||
void did_modify_bitmap();
|
||||
void did_modify_bitmap(Gfx::IntRect const& = {});
|
||||
|
||||
void set_selected(bool selected) { m_selected = selected; }
|
||||
bool is_selected() const { return m_selected; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue