automatically zoom in on crops

This commit is contained in:
Colin McMillen 2023-09-01 00:00:55 -04:00
parent d72a90a9f0
commit 31f2668aa3

View File

@ -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)) {
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.