diff --git a/Photo.cs b/Photo.cs index 55b1b91..793ec5f 100644 --- a/Photo.cs +++ b/Photo.cs @@ -105,6 +105,7 @@ public class Photo { public GpsInfo? Gps = null; public Rectangle CropRectangle = Rectangle.Empty; public Vector2i ViewOffset = Vector2i.Zero; + public float Rotation = 0; private static long touchCounter = 0; private Texture texture; diff --git a/Program.cs b/Program.cs index 19a87c4..5351f82 100644 --- a/Program.cs +++ b/Program.cs @@ -261,6 +261,46 @@ public class CropTool : ITool { } +public class StraightenTool : ITool { + + Photo photo; + float initialRotation; + + public StraightenTool(Photo photo) { + this.photo = photo; + initialRotation = photo.Rotation; + } + + public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo, UiGeometry geometry) { + if (input.IsKeyPressed(Keys.Left)) { + photo.Rotation += 1; + } + + if (input.IsKeyPressed(Keys.Right)) { + photo.Rotation -= 1; + } + + if (input.IsKeyPressed(Keys.Enter)) { + return ToolStatus.Done; + } + + if (input.IsKeyPressed(Keys.Escape)) { + photo.Rotation = initialRotation; + return ToolStatus.Canceled; + } + + return ToolStatus.Active; + } + + public void Draw(UiGeometry geometry, Game game) { + } + + public string Status() { + return String.Format("[straighten] {0}", photo.Rotation); + } +} + + public class UiGeometry { public static Vector2i MIN_WINDOW_SIZE = new(1024, 768); @@ -678,6 +718,9 @@ public class Game : GameWindow { if (input.IsKeyPressed(Keys.C)) { activeTool = new CropTool(photos[photoIndex]); } + if (input.IsKeyPressed(Keys.S)) { + activeTool = new StraightenTool(photos[photoIndex]); + } } // Delegate input to the active tool.