瀏覽代碼

PixelPaint: Add ability to fit to either width, height, or image

Ben Wiederhake 3 年之前
父節點
當前提交
9013d0fe38
共有 2 個文件被更改,包括 19 次插入3 次删除
  1. 12 2
      Userland/Applications/PixelPaint/ImageEditor.cpp
  2. 7 1
      Userland/Applications/PixelPaint/ImageEditor.h

+ 12 - 2
Userland/Applications/PixelPaint/ImageEditor.cpp

@@ -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);

+ 7 - 1
Userland/Applications/PixelPaint/ImageEditor.h

@@ -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);