mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
PixelPaint: Add keyboard zoom shortcuts
You can now use Ctrl+= and Ctrl+- to zoom in and out.
This commit is contained in:
parent
b48b8c372e
commit
2976311536
Notes:
sideshowbarker
2024-07-18 20:15:28 +09:00
Author: https://github.com/danielledeleo Commit: https://github.com/SerenityOS/serenity/commit/29763115367 Pull-request: https://github.com/SerenityOS/serenity/pull/6368 Issue: https://github.com/SerenityOS/serenity/issues/4138 Reviewed-by: https://github.com/linusg
3 changed files with 31 additions and 6 deletions
|
@ -370,15 +370,19 @@ Layer* ImageEditor::layer_at_editor_position(const Gfx::IntPoint& editor_positio
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void ImageEditor::scale_centered_on_position(const Gfx::IntPoint& position, float scale_delta)
|
||||
void ImageEditor::clamped_scale(float scale_delta)
|
||||
{
|
||||
auto old_scale = m_scale;
|
||||
|
||||
m_scale += scale_delta;
|
||||
if (m_scale < 0.1f)
|
||||
m_scale = 0.1f;
|
||||
if (m_scale > 100.0f)
|
||||
m_scale = 100.0f;
|
||||
}
|
||||
|
||||
void ImageEditor::scale_centered_on_position(const Gfx::IntPoint& position, float scale_delta)
|
||||
{
|
||||
auto old_scale = m_scale;
|
||||
clamped_scale(scale_delta);
|
||||
|
||||
Gfx::FloatPoint focus_point {
|
||||
m_pan_origin.x() - (position.x() - width() / 2.0f) / old_scale,
|
||||
|
@ -393,11 +397,19 @@ void ImageEditor::scale_centered_on_position(const Gfx::IntPoint& position, floa
|
|||
relayout();
|
||||
}
|
||||
|
||||
void ImageEditor::scale_by(float scale_delta)
|
||||
{
|
||||
if (scale_delta != 0) {
|
||||
clamped_scale(scale_delta);
|
||||
relayout();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageEditor::reset_scale_and_position()
|
||||
{
|
||||
if (m_scale != 1.0f)
|
||||
m_scale = 1.0f;
|
||||
|
||||
|
||||
m_pan_origin = Gfx::FloatPoint(0, 0);
|
||||
relayout();
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
|
||||
void scale_centered_on_position(const Gfx::IntPoint&, float);
|
||||
void reset_scale_and_position();
|
||||
void scale_by(float);
|
||||
|
||||
Color primary_color() const { return m_primary_color; }
|
||||
void set_primary_color(Color);
|
||||
|
@ -107,6 +108,7 @@ private:
|
|||
GUI::MouseEvent event_adjusted_for_layer(const GUI::MouseEvent&, const Layer&) const;
|
||||
GUI::MouseEvent event_with_pan_and_scale_applied(const GUI::MouseEvent&) const;
|
||||
|
||||
void clamped_scale(float);
|
||||
void relayout();
|
||||
|
||||
RefPtr<Image> m_image;
|
||||
|
|
|
@ -217,12 +217,23 @@ 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(
|
||||
"Zoom &In", { Mod_Ctrl, Key_Equal }, [&](auto&) {
|
||||
image_editor.scale_by(0.1f);
|
||||
},
|
||||
window));
|
||||
|
||||
view_menu.add_action(GUI::Action::create(
|
||||
"Zoom &Out", { Mod_Ctrl, Key_Minus }, [&](auto&) {
|
||||
image_editor.scale_by(-0.1f);
|
||||
},
|
||||
window));
|
||||
|
||||
view_menu.add_action(GUI::Action::create(
|
||||
"&Reset Zoom", { Mod_Ctrl, Key_0 }, [&](auto&) {
|
||||
image_editor.reset_scale_and_position();
|
||||
return;
|
||||
},
|
||||
window));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue