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)) { if (input.IsKeyPressed(Keys.Enter)) {
game.Cursor = MouseCursor.Default; 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; return ToolStatus.Done;
} }
@ -598,7 +600,14 @@ public class Game : GameWindow {
} }
if (input.IsKeyPressed(Keys.Q)) { 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; photos[photoIndex].ViewOffset = Vector2i.Zero;
}
zoomLevel = 0f; zoomLevel = 0f;
} }
@ -877,6 +886,7 @@ public class Game : GameWindow {
void DrawPhotos() { void DrawPhotos() {
Photo activePhoto = photos[photoIndex]; Photo activePhoto = photos[photoIndex];
Texture active = activePhoto.Texture(); Texture active = activePhoto.Texture();
bool cropActive = activeTool is CropTool;
// FIXME: make a function for scaling & centering one box on another. // 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. // 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); float scale = Math.Min(scaleX, scaleY);
if (zoomLevel > 0f) { if (zoomLevel > 0f) {
scale = zoomLevel; scale = zoomLevel;
} else if (!cropActive && activePhoto.CropRectangle != Rectangle.Empty) {
scale *= 0.95f * active.Size.X / activePhoto.CropRectangle.Width;
} }
activeScale = scale; activeScale = scale;
@ -902,7 +914,6 @@ public class Game : GameWindow {
Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY; Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY;
DrawTexture(star, geometry.StarBoxes[i].Min.X, geometry.StarBoxes[i].Min.Y); DrawTexture(star, geometry.StarBoxes[i].Min.X, geometry.StarBoxes[i].Min.Y);
} }
bool cropActive = activeTool is CropTool;
DrawCropRectangle(cropActive); DrawCropRectangle(cropActive);
// Draw thumbnail boxes. // Draw thumbnail boxes.