diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 5334f2da0cc..f3e73b32d0a 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -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(); +} + } diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h index 64dc43ea6f6..b681c10c13a 100644 --- a/Userland/Applications/PixelPaint/Image.h +++ b/Userland/Applications/PixelPaint/Image.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -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, 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; diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 79e8c357cea..7e9d011e709 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -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) diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index 9e2de93e090..a86cd4f1540 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -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; diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index 4d212b120ee..b495cbe35a6 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -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(