mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
PixelPaint: Add actions to rotate image left/right
This also required adding a new hook to `ImageClient`, since there wasn't a way of telling the ImageEditor that the full rect of the image has changed (as when we rotate).
This commit is contained in:
parent
6a8c408856
commit
ca6c9be94c
Notes:
sideshowbarker
2024-07-18 04:50:59 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/ca6c9be94cd Pull-request: https://github.com/SerenityOS/serenity/pull/9765
5 changed files with 46 additions and 0 deletions
|
@ -544,6 +544,12 @@ void Image::did_change(Gfx::IntRect const& a_modified_rect)
|
|||
client->image_did_change(modified_rect);
|
||||
}
|
||||
|
||||
void Image::did_change_rect()
|
||||
{
|
||||
for (auto* client : m_clients)
|
||||
client->image_did_change_rect(rect());
|
||||
}
|
||||
|
||||
ImageUndoCommand::ImageUndoCommand(Image& image)
|
||||
: m_snapshot(image.take_snapshot())
|
||||
, m_image(image)
|
||||
|
@ -585,4 +591,17 @@ void Image::flip(Gfx::Orientation orientation)
|
|||
did_change();
|
||||
}
|
||||
|
||||
void Image::rotate(Gfx::RotationDirection direction)
|
||||
{
|
||||
for (auto& layer : m_layers) {
|
||||
auto rotated = layer.bitmap().rotated(direction);
|
||||
VERIFY(rotated);
|
||||
layer.set_bitmap(*rotated);
|
||||
layer.did_modify_bitmap(rect());
|
||||
}
|
||||
|
||||
m_size = { m_size.height(), m_size.width() };
|
||||
did_change_rect();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibCore/File.h>
|
||||
#include <LibGUI/Command.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/Size.h>
|
||||
|
@ -32,6 +33,7 @@ public:
|
|||
virtual void image_did_modify_layer_bitmap(size_t) { }
|
||||
virtual void image_did_modify_layer_stack() { }
|
||||
virtual void image_did_change(Gfx::IntRect const&) { }
|
||||
virtual void image_did_change_rect(Gfx::IntRect const&) { }
|
||||
virtual void image_select_layer(Layer*) { }
|
||||
virtual void image_did_change_title(String const&) { }
|
||||
|
||||
|
@ -92,6 +94,7 @@ public:
|
|||
void set_title(String);
|
||||
|
||||
void flip(Gfx::Orientation orientation);
|
||||
void rotate(Gfx::RotationDirection direction);
|
||||
|
||||
private:
|
||||
explicit Image(Gfx::IntSize const&);
|
||||
|
@ -101,6 +104,7 @@ private:
|
|||
static Result<NonnullRefPtr<Image>, String> try_create_from_pixel_paint_file(Core::File& file, String const& file_path);
|
||||
|
||||
void did_change(Gfx::IntRect const& modified_rect = {});
|
||||
void did_change_rect();
|
||||
void did_modify_layer_stack();
|
||||
|
||||
String m_path;
|
||||
|
|
|
@ -453,6 +453,12 @@ void ImageEditor::image_did_change(Gfx::IntRect const& modified_image_rect)
|
|||
update(m_editor_image_rect.intersected(enclosing_int_rect(image_rect_to_editor_rect(modified_image_rect))));
|
||||
}
|
||||
|
||||
void ImageEditor::image_did_change_rect(Gfx::IntRect const& new_image_rect)
|
||||
{
|
||||
m_editor_image_rect = enclosing_int_rect(image_rect_to_editor_rect(new_image_rect));
|
||||
update(m_editor_image_rect);
|
||||
}
|
||||
|
||||
void ImageEditor::image_did_change_title(String const& path)
|
||||
{
|
||||
if (on_image_title_change)
|
||||
|
|
|
@ -106,6 +106,7 @@ private:
|
|||
virtual void leave_event(Core::Event&) override;
|
||||
|
||||
virtual void image_did_change(Gfx::IntRect const&) override;
|
||||
virtual void image_did_change_rect(Gfx::IntRect const&) override;
|
||||
virtual void image_select_layer(Layer*) override;
|
||||
virtual void image_did_change_title(String const&) override;
|
||||
|
||||
|
|
|
@ -424,6 +424,22 @@ int main(int argc, char** argv)
|
|||
editor->image().flip(Gfx::Orientation::Horizontal);
|
||||
},
|
||||
window));
|
||||
image_menu.add_action(GUI::Action::create(
|
||||
"Rotate &Left", [&](auto&) {
|
||||
auto* editor = current_image_editor();
|
||||
if (!editor)
|
||||
return;
|
||||
editor->image().rotate(Gfx::RotationDirection::CounterClockwise);
|
||||
},
|
||||
window));
|
||||
image_menu.add_action(GUI::Action::create(
|
||||
"Rotate &Right", [&](auto&) {
|
||||
auto* editor = current_image_editor();
|
||||
if (!editor)
|
||||
return;
|
||||
editor->image().rotate(Gfx::RotationDirection::Clockwise);
|
||||
},
|
||||
window));
|
||||
|
||||
auto& layer_menu = window->add_menu("&Layer");
|
||||
layer_menu.add_action(GUI::Action::create(
|
||||
|
|
Loading…
Reference in a new issue