mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +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
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);
|
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)
|
ImageUndoCommand::ImageUndoCommand(Image& image)
|
||||||
: m_snapshot(image.take_snapshot())
|
: m_snapshot(image.take_snapshot())
|
||||||
, m_image(image)
|
, m_image(image)
|
||||||
|
@ -585,4 +591,17 @@ void Image::flip(Gfx::Orientation orientation)
|
||||||
did_change();
|
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 <LibCore/File.h>
|
||||||
#include <LibGUI/Command.h>
|
#include <LibGUI/Command.h>
|
||||||
#include <LibGUI/Forward.h>
|
#include <LibGUI/Forward.h>
|
||||||
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Forward.h>
|
#include <LibGfx/Forward.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <LibGfx/Size.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_bitmap(size_t) { }
|
||||||
virtual void image_did_modify_layer_stack() { }
|
virtual void image_did_modify_layer_stack() { }
|
||||||
virtual void image_did_change(Gfx::IntRect const&) { }
|
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_select_layer(Layer*) { }
|
||||||
virtual void image_did_change_title(String const&) { }
|
virtual void image_did_change_title(String const&) { }
|
||||||
|
|
||||||
|
@ -92,6 +94,7 @@ public:
|
||||||
void set_title(String);
|
void set_title(String);
|
||||||
|
|
||||||
void flip(Gfx::Orientation orientation);
|
void flip(Gfx::Orientation orientation);
|
||||||
|
void rotate(Gfx::RotationDirection direction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Image(Gfx::IntSize const&);
|
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);
|
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(Gfx::IntRect const& modified_rect = {});
|
||||||
|
void did_change_rect();
|
||||||
void did_modify_layer_stack();
|
void did_modify_layer_stack();
|
||||||
|
|
||||||
String m_path;
|
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))));
|
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)
|
void ImageEditor::image_did_change_title(String const& path)
|
||||||
{
|
{
|
||||||
if (on_image_title_change)
|
if (on_image_title_change)
|
||||||
|
|
|
@ -106,6 +106,7 @@ private:
|
||||||
virtual void leave_event(Core::Event&) override;
|
virtual void leave_event(Core::Event&) override;
|
||||||
|
|
||||||
virtual void image_did_change(Gfx::IntRect const&) 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_select_layer(Layer*) override;
|
||||||
virtual void image_did_change_title(String const&) 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);
|
editor->image().flip(Gfx::Orientation::Horizontal);
|
||||||
},
|
},
|
||||||
window));
|
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");
|
auto& layer_menu = window->add_menu("&Layer");
|
||||||
layer_menu.add_action(GUI::Action::create(
|
layer_menu.add_action(GUI::Action::create(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue