Browse Source

Fixed rotate whole image

flabbet 2 years ago
parent
commit
a16af5263d

+ 1 - 1
src/ChunkyImageLib/ChunkyImage.cs

@@ -156,7 +156,7 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable
                 preciseBounds ??= globalChunkBounds;
                 preciseBounds = preciseBounds.Value.Union(globalChunkBounds);
             }
-            preciseBounds = preciseBounds?.Intersect(new RectI(VecI.Zero, CommittedSize));
+            preciseBounds = preciseBounds?.Intersect(new RectI(preciseBounds.Value.Pos, CommittedSize));
 
             return preciseBounds;
         }

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changes/Root/FlipImage_Change.cs

@@ -74,8 +74,8 @@ internal sealed class FlipImage_Change : Change
         bool flipY = flipType == FlipType.Vertical;
         
         flipped.DrawingSurface.Canvas.Save();
-                flipped.DrawingSurface.Canvas.Scale(flipX ? -1 : 1, flipY ? -1 : 1, flipX ? bounds.X + bounds.Width / 2f : 0,
-            flipY ? bounds.Y + bounds.Height / 2f : 0f);
+                flipped.DrawingSurface.Canvas.Scale(flipX ? -1 : 1, flipY ? -1 : 1, flipX ? bounds.X + (bounds.Width / 2f) : 0,
+            flipY ? bounds.Y + (bounds.Height / 2f) : 0f);
         flipped.DrawingSurface.Canvas.DrawSurface(originalSurface.DrawingSurface, 0, 0, paint);
         flipped.DrawingSurface.Canvas.Restore();
         

+ 8 - 3
src/PixiEditor.ChangeableDocument/Changes/Root/RotateImage_Change.cs

@@ -72,7 +72,7 @@ internal sealed class RotateImage_Change : Change
         int newWidth = rotation == RotationAngle.D180 ? originalWidth : originalHeight;
         int newHeight = rotation == RotationAngle.D180 ? originalHeight : originalWidth;
 
-        VecI originalSize = new VecI(originalWidth, originalHeight);
+        VecI oldSize = new VecI(originalWidth, originalHeight);
         VecI newSize = new VecI(newWidth, newHeight);
         
         using Paint paint = new()
@@ -80,7 +80,7 @@ internal sealed class RotateImage_Change : Change
             BlendMode = DrawingApi.Core.Surface.BlendMode.Src
         };
         
-        using Surface originalSurface = new(originalSize);
+        using Surface originalSurface = new(oldSize);
         img.DrawMostUpToDateRegionOn(
             bounds, 
             ChunkResolution.Full,
@@ -106,7 +106,12 @@ internal sealed class RotateImage_Change : Change
         flipped.DrawingSurface.Canvas.RotateRadians(RotationAngleToRadians(rotation), 0, 0);
         flipped.DrawingSurface.Canvas.DrawSurface(originalSurface.DrawingSurface, 0, 0, paint);
         flipped.DrawingSurface.Canvas.Restore();
-        
+
+        if (membersToRotate.Count == 0) 
+        {
+            img.EnqueueResize(newSize);
+        }
+
         img.EnqueueClear();
         img.EnqueueDrawImage(bounds.Pos, flipped);
 

+ 1 - 4
src/PixiEditor/ViewModels/SubViewModels/Document/DocumentManagerViewModel.cs

@@ -124,12 +124,9 @@ internal class DocumentManagerViewModel : SubViewModel<ViewModelMain>
         ActiveDocument?.Operations.RotateImage(RotationAngle.D180, ActiveDocument.GetSelectedMembers());
     }
 
-    [Command.Basic("PixiEditor.Document.Rotate270Deg", "Rotate Image 270 deg", "Rotate Image 270 deg", CanExecute = "PixiEditor.HasDocument")]
+    [Command.Basic("PixiEditor.Document.Rotate270Deg", "Rotate Image -90 deg", "Rotate Image -90 deg", CanExecute = "PixiEditor.HasDocument")]
     public void Rotate270Deg()
     {
-        if (ActiveDocument == null)
-            return;
-        
         ActiveDocument?.Operations.RotateImage(RotationAngle.D270);
     }
     

+ 3 - 3
src/PixiEditor/Views/MainWindow.xaml

@@ -260,14 +260,14 @@
                         <MenuItem Header="_Rotation">
                             <MenuItem Header="Rotate Image 90&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate90Deg"/>
                             <MenuItem Header="Rotate Image 180&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate180Deg"/>
-                            <MenuItem Header="Rotate Image 270&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate270Deg"/>
+                            <MenuItem Header="Rotate Image -90&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate270Deg"/>
                             
                             <Separator/>
                             <MenuItem Header="Rotate Selected Layers 90&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate90DegLayers"/>
                             <MenuItem Header="Rotate Selected Layers 180&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate180DegLayers"/>
-                            <MenuItem Header="Rotate Selected Layers 270&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate270DegLayers"/>
+                            <MenuItem Header="Rotate Selected Layers -90&#186;" cmds:Menu.Command="PixiEditor.Document.Rotate270DegLayers"/>
                         </MenuItem>
-                        <MenuItem Header="_Flipping">
+                        <MenuItem Header="_Flip">
                             <MenuItem Header="Flip Image _Horizontally" cmds:Menu.Command="PixiEditor.Document.FlipImageHorizontal"/>
                             <MenuItem Header="Flip Image _Vertically" cmds:Menu.Command="PixiEditor.Document.FlipImageVertical"/>
                             <MenuItem Header="Flip Selected Layers _Horizontally" cmds:Menu.Command="PixiEditor.Document.FlipLayersHorizontal"/>