diff --git a/Program.cs b/Program.cs index 780dff9..b9d7a4e 100644 --- a/Program.cs +++ b/Program.cs @@ -185,6 +185,8 @@ public class CropTool : ITool { if (input.IsKeyPressed(Keys.Enter)) { game.Cursor = MouseCursor.Default; + photo.ViewOffset = new(photo.Size.X / 2 - Rectangle.Center(r).X, + photo.Size.Y / 2 - Rectangle.Center(r).Y); return ToolStatus.Done; } @@ -598,7 +600,14 @@ public class Game : GameWindow { } if (input.IsKeyPressed(Keys.Q)) { - photos[photoIndex].ViewOffset = Vector2i.Zero; + if (photos[photoIndex].CropRectangle != Rectangle.Empty) { + Photo photo = photos[photoIndex]; + Rectangle r = photos[photoIndex].CropRectangle; + photo.ViewOffset = new(photo.Size.X / 2 - Rectangle.Center(r).X, + photo.Size.Y / 2 - Rectangle.Center(r).Y); + } else { + photos[photoIndex].ViewOffset = Vector2i.Zero; + } zoomLevel = 0f; } @@ -877,6 +886,7 @@ public class Game : GameWindow { void DrawPhotos() { Photo activePhoto = photos[photoIndex]; Texture active = activePhoto.Texture(); + bool cropActive = activeTool is CropTool; // FIXME: make a function for scaling & centering one box on another. // FIXME: cropping is fucky because activeScale is using the texture size, not the photo size. @@ -885,6 +895,8 @@ public class Game : GameWindow { float scale = Math.Min(scaleX, scaleY); if (zoomLevel > 0f) { scale = zoomLevel; + } else if (!cropActive && activePhoto.CropRectangle != Rectangle.Empty) { + scale *= 0.95f * active.Size.X / activePhoto.CropRectangle.Width; } activeScale = scale; @@ -902,7 +914,6 @@ public class Game : GameWindow { Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY; DrawTexture(star, geometry.StarBoxes[i].Min.X, geometry.StarBoxes[i].Min.Y); } - bool cropActive = activeTool is CropTool; DrawCropRectangle(cropActive); // Draw thumbnail boxes.