mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:37:35 +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
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;
|
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;
|
m_scale += scale_delta;
|
||||||
if (m_scale < 0.1f)
|
if (m_scale < 0.1f)
|
||||||
m_scale = 0.1f;
|
m_scale = 0.1f;
|
||||||
if (m_scale > 100.0f)
|
if (m_scale > 100.0f)
|
||||||
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 {
|
Gfx::FloatPoint focus_point {
|
||||||
m_pan_origin.x() - (position.x() - width() / 2.0f) / old_scale,
|
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();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageEditor::scale_by(float scale_delta)
|
||||||
|
{
|
||||||
|
if (scale_delta != 0) {
|
||||||
|
clamped_scale(scale_delta);
|
||||||
|
relayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ImageEditor::reset_scale_and_position()
|
void ImageEditor::reset_scale_and_position()
|
||||||
{
|
{
|
||||||
if (m_scale != 1.0f)
|
if (m_scale != 1.0f)
|
||||||
m_scale = 1.0f;
|
m_scale = 1.0f;
|
||||||
|
|
||||||
m_pan_origin = Gfx::FloatPoint(0, 0);
|
m_pan_origin = Gfx::FloatPoint(0, 0);
|
||||||
relayout();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ public:
|
||||||
|
|
||||||
void scale_centered_on_position(const Gfx::IntPoint&, float);
|
void scale_centered_on_position(const Gfx::IntPoint&, float);
|
||||||
void reset_scale_and_position();
|
void reset_scale_and_position();
|
||||||
|
void scale_by(float);
|
||||||
|
|
||||||
Color primary_color() const { return m_primary_color; }
|
Color primary_color() const { return m_primary_color; }
|
||||||
void set_primary_color(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_adjusted_for_layer(const GUI::MouseEvent&, const Layer&) const;
|
||||||
GUI::MouseEvent event_with_pan_and_scale_applied(const GUI::MouseEvent&) const;
|
GUI::MouseEvent event_with_pan_and_scale_applied(const GUI::MouseEvent&) const;
|
||||||
|
|
||||||
|
void clamped_scale(float);
|
||||||
void relayout();
|
void relayout();
|
||||||
|
|
||||||
RefPtr<Image> m_image;
|
RefPtr<Image> m_image;
|
||||||
|
|
|
@ -217,12 +217,23 @@ int main(int argc, char** argv)
|
||||||
image_editor.redo();
|
image_editor.redo();
|
||||||
});
|
});
|
||||||
edit_menu.add_action(redo_action);
|
edit_menu.add_action(redo_action);
|
||||||
|
|
||||||
auto& view_menu = menubar->add_menu("&View");
|
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(
|
view_menu.add_action(GUI::Action::create(
|
||||||
"&Reset Zoom", { Mod_Ctrl, Key_0 }, [&](auto&) {
|
"&Reset Zoom", { Mod_Ctrl, Key_0 }, [&](auto&) {
|
||||||
image_editor.reset_scale_and_position();
|
image_editor.reset_scale_and_position();
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue