Explorar o código

Center content related bug fix

flabbet %!s(int64=3) %!d(string=hai) anos
pai
achega
6efb0b5d83

+ 11 - 4
PixiEditor/Models/DataHolders/Document/Document.Layers.cs

@@ -12,6 +12,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text.RegularExpressions;
 using System.Windows;
+using Windows.Graphics;
 
 namespace PixiEditor.Models.DataHolders
 {
@@ -614,18 +615,24 @@ namespace PixiEditor.Models.DataHolders
         /// <summary>
         ///     Moves offsets of layers by specified vector.
         /// </summary>
-        private void MoveOffsets(IList<Layer> layers, Coordinates moveVector)
+        private void MoveOffsets(IList<Layer> layers, IList<Int32Rect> bounds, Coordinates moveVector)
         {
-            foreach (Layer layer in layers)
+            for (int i = 0; i < layers.Count; i++)
             {
+                Layer layer = layers[i];
+                Int32Rect bound = bounds[i];
                 Thickness offset = layer.Offset;
                 layer.Offset = new Thickness(offset.Left + moveVector.X, offset.Top + moveVector.Y, 0, 0);
+                if (layer.Bounds != bound)
+                {
+                    layer.DynamicResizeAbsolute(bound);
+                }
             }
         }
 
         private void MoveOffsetsProcess(object[] arguments)
         {
-            if (arguments.Length > 0 && arguments[0] is List<Guid> guids && arguments[1] is Coordinates vector)
+            if (arguments.Length > 0 && arguments[0] is List<Guid> guids && arguments[1] is List<Int32Rect> bounds && arguments[2] is Coordinates vector)
             {
                 List<Layer> layers = new List<Layer>(guids.Count);
                 foreach (Guid guid in guids)
@@ -633,7 +640,7 @@ namespace PixiEditor.Models.DataHolders
                     layers.Add(Layers.First(x => x.GuidValue == guid));
                 }
 
-                MoveOffsets(layers, vector);
+                MoveOffsets(layers, bounds, vector);
             }
             else
             {

+ 7 - 3
PixiEditor/Models/DataHolders/Document/Document.cs

@@ -162,6 +162,8 @@ namespace PixiEditor.Models.DataHolders
                 return;
             }
 
+            List<Int32Rect> oldBounds = layersToCenter.Select(x => x.Bounds).ToList();
+
             DoubleCoords? maybePoints = ClipLayersAndGetEdgePoints(layersToCenter);
             if (maybePoints == null)
                 return;
@@ -178,14 +180,16 @@ namespace PixiEditor.Models.DataHolders
                 new Coordinates(Width, Height));
             Coordinates moveVector = new Coordinates(documentCenter.X - contentCenter.X, documentCenter.Y - contentCenter.Y);
 
-            MoveOffsets(layersToCenter, moveVector);
+            List<Int32Rect> newBounds = layersToCenter.Select(x => x.Bounds).ToList();
+
+            MoveOffsets(layersToCenter, newBounds, moveVector);
             List<Guid> guids = layersToCenter.Select(x => x.GuidValue).ToList();
             UndoManager.AddUndoChange(
                 new Change(
                     MoveOffsetsProcess,
-                    new object[] { guids, new Coordinates(-moveVector.X, -moveVector.Y) },
+                    new object[] { guids, oldBounds, new Coordinates(-moveVector.X, -moveVector.Y) },
                     MoveOffsetsProcess,
-                    new object[] { guids, moveVector },
+                    new object[] { guids, newBounds, moveVector },
                     "Center content"));
         }
 

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

@@ -215,6 +215,7 @@ namespace PixiEditor.Models.Layers
         public bool IsReset { get; private set; }
 
         public Int32Rect TightBounds => GetContentDimensions();
+        public Int32Rect Bounds => new Int32Rect(OffsetX, OffsetY, Width, Height);
 
         public event EventHandler<Int32Rect> LayerBitmapChanged;