PixelPaint: Add ability to fit to either width, height, or image
This commit is contained in:
parent
be697a440f
commit
9013d0fe38
Notes:
sideshowbarker
2024-07-18 00:52:02 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/9013d0fe380 Pull-request: https://github.com/SerenityOS/serenity/pull/11002
2 changed files with 19 additions and 3 deletions
Userland/Applications/PixelPaint
|
@ -610,7 +610,7 @@ void ImageEditor::set_pan_origin(Gfx::FloatPoint const& pan_origin)
|
|||
relayout();
|
||||
}
|
||||
|
||||
void ImageEditor::fit_image_to_view()
|
||||
void ImageEditor::fit_image_to_view(FitType type)
|
||||
{
|
||||
auto viewport_rect = rect();
|
||||
m_pan_origin = Gfx::FloatPoint(0, 0);
|
||||
|
@ -628,7 +628,17 @@ void ImageEditor::fit_image_to_view()
|
|||
auto image_size = image().size();
|
||||
auto height_ratio = floorf(border_ratio * viewport_rect.height()) / (float)image_size.height();
|
||||
auto width_ratio = floorf(border_ratio * viewport_rect.width()) / (float)image_size.width();
|
||||
set_absolute_scale(min(height_ratio, width_ratio), false);
|
||||
switch (type) {
|
||||
case FitType::Width:
|
||||
set_absolute_scale(width_ratio, false);
|
||||
break;
|
||||
case FitType::Height:
|
||||
set_absolute_scale(height_ratio, false);
|
||||
break;
|
||||
case FitType::Image:
|
||||
set_absolute_scale(min(height_ratio, width_ratio), false);
|
||||
break;
|
||||
}
|
||||
|
||||
float offset = m_show_rulers ? -m_ruler_thickness / (m_scale * 2.0f) : 0.0f;
|
||||
m_pan_origin = Gfx::FloatPoint(offset, offset);
|
||||
|
|
|
@ -54,9 +54,15 @@ public:
|
|||
|
||||
Layer* layer_at_editor_position(Gfx::IntPoint const&);
|
||||
|
||||
enum class FitType {
|
||||
Width,
|
||||
Height,
|
||||
Image
|
||||
};
|
||||
|
||||
float scale() const { return m_scale; }
|
||||
void scale_centered_on_position(Gfx::IntPoint const&, float);
|
||||
void fit_image_to_view();
|
||||
void fit_image_to_view(FitType type = FitType::Image);
|
||||
void reset_scale_and_position();
|
||||
void scale_by(float);
|
||||
void set_absolute_scale(float, bool do_relayout = true);
|
||||
|
|
Loading…
Add table
Reference in a new issue