From e5c1b01806961476926c0d7d0cd527a459a01538 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 1 Aug 2023 23:14:00 -0400 Subject: [PATCH] more crop progress --- Program.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index fe2413e..459c9e0 100644 --- a/Program.cs +++ b/Program.cs @@ -639,6 +639,7 @@ public class Game : GameWindow { int ribbonIndex = 0; Vector2i mouseDragStart; Vector2i mouseDragEnd; + float activeScale = 1f; Shader shader = new(); Matrix4 projection; float zoomLevel = 0f; @@ -737,6 +738,11 @@ public class Game : GameWindow { photoIndex -= 5; } + // FIXME: crop should be a modal tool that starts with C and ends with Enter or Escape. + if (input.IsKeyPressed(Keys.C)) { + ApplyCrop(); + } + if (input.IsKeyPressed(Keys.P) && altIsDown) { ExportPhotos(); } @@ -993,7 +999,11 @@ public class Game : GameWindow { SwapBuffers(); } - void DrawCropBox() { + // left, right, top, bottom + (int, int, int, int) GetCrop() { + // FIXME: this expects the start point in the top left and the end point + // in the bottom right; some sign flipping needs to occur to make anchors + // in other direction work well. Vector2i start = mouseDragStart; Vector2i end = mouseDragEnd; end.Y = Math.Min(end.Y, start.Y + (end.X - start.X) * 4 / 6); @@ -1002,6 +1012,20 @@ public class Game : GameWindow { int right = Math.Max(start.X, end.X); int top = Math.Min(start.Y, end.Y); int bottom = Math.Max(start.Y, end.Y); + return (left, right, top, bottom); + } + + void ApplyCrop() { + var (left, right, top, bottom) = GetCrop(); + int area = (right - left) * (bottom - top); + if (area < 100) { + return; + } + + } + + void DrawCropBox() { + var (left, right, top, bottom) = GetCrop(); int area = (right - left) * (bottom - top); if (area < 100) { @@ -1032,10 +1056,12 @@ public class Game : GameWindow { if (zoomLevel > 0f) { scale = zoomLevel; } + activeScale = scale; Vector2i renderSize = (Vector2i) (((Vector2) active.Size) * scale); Vector2i center = (Vector2i) geometry.PhotoBox.Center; - Box2i photoBox = Util.MakeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y); + // Box2i photoBox = Util.MakeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y); + Box2i photoBox = Util.MakeBox(0, 0, renderSize.X, renderSize.Y); DrawTexture(active, photoBox); for (int i = 0; i < 5; i++) { Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY;