From a2a5448afe18ddccd27eb98dd26fbec9c99ece4e Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Fri, 15 Sep 2023 13:17:10 -0400 Subject: [PATCH] straightentool now works in 100ths of degrees --- Photo.cs | 6 +++--- Program.cs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Photo.cs b/Photo.cs index fa4eb91..a0bfad2 100644 --- a/Photo.cs +++ b/Photo.cs @@ -105,7 +105,7 @@ public class Photo { public GpsInfo? Gps = null; public Rectangle CropRectangle = Rectangle.Empty; public Vector2i ViewOffset = Vector2i.Zero; - public float RotationDegrees = 0; + public int RotationDegreeHundredths = 0; private static long touchCounter = 0; private Texture texture; @@ -219,8 +219,8 @@ public class Photo { Console.WriteLine($"{Filename} => {jpgOut}"); await image.SaveAsync(jpgOut, new JpegEncoder() { Quality = 100 }); - if (Math.Abs(RotationDegrees) > 0.001) { - image.Mutate(x => x.Rotate(RotationDegrees)); + if (RotationDegreeHundredths != 0) { + image.Mutate(x => x.Rotate(RotationDegreeHundredths / 100f)); } if (CropRectangle != Rectangle.Empty) { image.Mutate(x => x.Crop(CropRectangle)); diff --git a/Program.cs b/Program.cs index 23d0af8..a3af112 100644 --- a/Program.cs +++ b/Program.cs @@ -257,24 +257,24 @@ public class CropTool : ITool { public class StraightenTool : ITool { Photo photo; - float initialRotation; + int initialRotation; public StraightenTool(Photo photo) { this.photo = photo; - initialRotation = photo.RotationDegrees; + initialRotation = photo.RotationDegreeHundredths; } public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo, UiGeometry geometry) { if (input.IsKeyPressed(Keys.D0)) { - photo.RotationDegrees = 0; + photo.RotationDegreeHundredths = 0; } if (input.IsKeyPressed(Keys.Left)) { - photo.RotationDegrees += .1f; + photo.RotationDegreeHundredths += 10; } if (input.IsKeyPressed(Keys.Right)) { - photo.RotationDegrees -= .1f; + photo.RotationDegreeHundredths -= 10; } if (input.IsKeyPressed(Keys.Enter)) { @@ -282,7 +282,7 @@ public class StraightenTool : ITool { } if (input.IsKeyPressed(Keys.Escape)) { - photo.RotationDegrees = initialRotation; + photo.RotationDegreeHundredths = initialRotation; return ToolStatus.Canceled; } @@ -290,7 +290,7 @@ public class StraightenTool : ITool { } public string Status() { - return String.Format("[straighten] {0:F2}", photo.RotationDegrees); + return String.Format("[straighten] {0:F2}", photo.RotationDegreeHundredths / 100f); } } @@ -983,7 +983,7 @@ public class Game : GameWindow { renderSize.X, renderSize.Y); activeOffset = new(photoBox.Min.X, photoBox.Min.Y); transform = new Transform(activeScale, activeOffset, activePhoto.Size); - DrawTexture(active, photoBox, Color4.White, activePhoto.RotationDegrees); + DrawTexture(active, photoBox, Color4.White, activePhoto.RotationDegreeHundredths / 100f); for (int i = 0; i < 5; i++) { Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY; DrawTexture(star, geometry.StarBoxes[i].Min.X, geometry.StarBoxes[i].Min.Y);