浏览代码

Forgot to clamp stuff

Krzysztof Krysiński 3 年之前
父节点
当前提交
4b56086db4

+ 2 - 2
PixiEditor/Models/DataHolders/Document/Document.Operations.cs

@@ -32,8 +32,8 @@ namespace PixiEditor.Models.DataHolders
             int offsetX = GetOffsetXForAnchor(Width, width, anchor);
             int offsetY = GetOffsetYForAnchor(Height, height, anchor);
 
-            int widthDiff = width - oldWidth;
-            int heightDiff = height - oldHeight;
+            int widthDiff = Math.Abs(width - oldWidth);
+            int heightDiff = Math.Abs(height - oldHeight);
 
             PixelSize diff = new PixelSize(widthDiff, heightDiff);
 

+ 1 - 1
PixiEditor/Models/DataHolders/Document/Document.cs

@@ -132,7 +132,7 @@ namespace PixiEditor.Models.DataHolders
             Thickness[] oldOffsets = Layers.Select(x => x.Offset).ToArray();
             int oldWidth = Width;
             int oldHeight = Height;
-            PixelSize diff = new PixelSize(width - oldWidth, height - oldHeight);
+            PixelSize diff = new PixelSize(Math.Abs(width - oldWidth), Math.Abs(height - oldHeight));
             PixelSize[] oldSize = Layers.Select(x => x.GetSize()).ToArray();
 
             MoveOffsets(Layers, moveVector);

+ 3 - 3
PixiEditor/Models/Undo/StorageBasedChange.cs

@@ -356,9 +356,6 @@ namespace PixiEditor.Models.Undo
             int targetWidth = Math.Max(chunk.Width, layer.Width);
             int targetHeight = Math.Max(chunk.Height, layer.Height);
 
-            targetWidth = Math.Clamp(targetWidth, 0, layerData.MaxWidth - layerData.OffsetX);
-            targetHeight = Math.Clamp(targetHeight, 0, layerData.MaxHeight - layerData.OffsetY);
-
             int targetOffsetX = Math.Min(layerData.OffsetX, layerData.SerializedRect.Left);
             int targetOffsetY = Math.Min(layerData.OffsetY, layerData.SerializedRect.Top);
 
@@ -375,6 +372,9 @@ namespace PixiEditor.Models.Undo
                 targetHeight += layerData.SerializedRect.Top;
             }
 
+            targetWidth = Math.Clamp(targetWidth, 0, layerData.MaxWidth - layerData.OffsetX);
+            targetHeight = Math.Clamp(targetHeight, 0, layerData.MaxHeight - layerData.OffsetY);
+
             targetOffsetX = Math.Max(0, targetOffsetX);
             targetOffsetY = Math.Max(0, targetOffsetY);