Browse Source

Fixed resize

flabbet 5 years ago
parent
commit
d3358c84ad
2 changed files with 18 additions and 5 deletions
  1. 9 5
      PixiEditor/Models/DataHolders/Document.cs
  2. 9 0
      PixiEditor/Models/Layers/Layer.cs

+ 9 - 5
PixiEditor/Models/DataHolders/Document.cs

@@ -132,12 +132,16 @@ namespace PixiEditor.Models.DataHolders
 
 
             int newWidth = (int) arguments[0];
             int newWidth = (int) arguments[0];
             int newHeight = (int) arguments[1];
             int newHeight = (int) arguments[1];
+
             for (int i = 0; i < Layers.Count; i++)
             for (int i = 0; i < Layers.Count; i++)
             {
             {
-                Layers[i].LayerBitmap = Layers[i].LayerBitmap.Resize(newWidth, newHeight,
-                    WriteableBitmapExtensions.Interpolation.NearestNeighbor);
-                Layers[i].Width = newWidth;
-                Layers[i].Height = newHeight;
+                float widthRatio = (float)newWidth / Width;
+                float heightRatio = (float)newHeight / Height;
+                int layerWidth = (int)(Layers[i].Width * widthRatio);
+                int layerHeight = (int)(Layers[i].Height * heightRatio);
+
+                Layers[i].Resize(layerWidth, layerHeight, newWidth, newHeight);
+                Layers[i].Offset = new Thickness(Layers[i].OffsetX * widthRatio, Layers[i].OffsetY * heightRatio, 0, 0);
             }
             }
 
 
             Height = newHeight;
             Height = newHeight;
@@ -254,7 +258,7 @@ namespace PixiEditor.Models.DataHolders
 
 
         public void CenterContent()
         public void CenterContent()
         {
         {
-            DoubleCords points = new DoubleCords();
+            DoubleCords points = GetEdgePoints();
 
 
             int smallestX = points.Coords1.X;
             int smallestX = points.Coords1.X;
             int smallestY = points.Coords1.Y;
             int smallestY = points.Coords1.Y;

+ 9 - 0
PixiEditor/Models/Layers/Layer.cs

@@ -134,6 +134,15 @@ namespace PixiEditor.Models.Layers
             };
             };
         }
         }
 
 
+        public void Resize(int width, int height, int newMaxWidth, int newMaxHeight)
+        {
+            LayerBitmap = LayerBitmap.Resize(width, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
+            Width = width;
+            Height = height;
+            MaxWidth = newMaxWidth;
+            MaxHeight = newMaxHeight;
+        }
+
         /// <summary>
         /// <summary>
         ///     Converts coordinates relative to viewport to relative to layer
         ///     Converts coordinates relative to viewport to relative to layer
         /// </summary>
         /// </summary>