diff options
author | Jagger De Leo <jcdl@fastmail.com> | 2021-04-15 21:09:25 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-04-16 19:57:28 +0200 |
commit | b48b8c372edb8b2d070bec92c557f63809295e43 (patch) | |
tree | a01178663fa0f5add30819942ad850dd530e11c8 | |
parent | 223472c57ff5c736c59a5591708da3fc22529adc (diff) | |
download | serenity-b48b8c372edb8b2d070bec92c557f63809295e43.zip |
PixelPaint: Add Zoom Reset button to new View Menubar.
If you lose your image while panning and zooming around, it is handy to
have a reset function to get back home. :^)
-rw-r--r-- | Userland/Applications/PixelPaint/ImageEditor.cpp | 9 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/ImageEditor.h | 1 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/main.cpp | 8 |
3 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index e91cbcf275..7fc67a9d59 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -393,6 +393,15 @@ void ImageEditor::scale_centered_on_position(const Gfx::IntPoint& position, floa relayout(); } +void ImageEditor::reset_scale_and_position() +{ + if (m_scale != 1.0f) + m_scale = 1.0f; + + m_pan_origin = Gfx::FloatPoint(0, 0); + relayout(); +} + void ImageEditor::relayout() { if (!image()) diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index ab5de26bff..ae4576ff4b 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -64,6 +64,7 @@ public: Layer* layer_at_editor_position(const Gfx::IntPoint&); void scale_centered_on_position(const Gfx::IntPoint&, float); + void reset_scale_and_position(); Color primary_color() const { return m_primary_color; } void set_primary_color(Color); diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index eba74da9ce..0b49c8ea63 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -217,6 +217,14 @@ int main(int argc, char** argv) image_editor.redo(); }); edit_menu.add_action(redo_action); + + auto& view_menu = menubar->add_menu("&View"); + view_menu.add_action(GUI::Action::create( + "&Reset Zoom", { Mod_Ctrl, Key_0 }, [&](auto&) { + image_editor.reset_scale_and_position(); + return; + }, + window)); auto& tool_menu = menubar->add_menu("&Tool"); toolbox.for_each_tool([&](auto& tool) { |