From e61242929837b2a332fa4d3ccc7f9487bfc767da Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Thu, 31 Aug 2023 23:07:15 -0400 Subject: [PATCH] add ViewOffset to Photo for display --- Photo.cs | 1 + Program.cs | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Photo.cs b/Photo.cs index e2a0e62..7b10d4b 100644 --- a/Photo.cs +++ b/Photo.cs @@ -102,6 +102,7 @@ public class Photo { public ushort Orientation = 1; public GpsInfo? Gps = null; public Rectangle CropRectangle = Rectangle.Empty; + public Vector2i ViewOffset = Vector2i.Zero; private static long touchCounter = 0; private Texture texture; diff --git a/Program.cs b/Program.cs index ec85cc3..7dd946d 100644 --- a/Program.cs +++ b/Program.cs @@ -87,14 +87,22 @@ public class Transform { } public interface ITool { - ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game); + ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo); string Status(); void Draw(UiGeometry geometry, Game game); } public class ViewTool : ITool { - public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game) { + public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo) { + Vector2i mousePosition = (Vector2i) mouse.Position; + if (mouse.IsButtonDown(MouseButton.Button1)) { + Vector2 delta = mouse.Delta; + Vector2i imageDelta = transform.ScreenToImageDelta((int) delta.X, (int) delta.Y); + photo.ViewOffset = Vector2i.Add(photo.ViewOffset, imageDelta); + Console.WriteLine("+++ " + photo.ViewOffset); + } + return ToolStatus.Active; } @@ -121,7 +129,7 @@ public class CropTool : ITool { mouseDragEnd = new(photo.CropRectangle.Right, photo.CropRectangle.Bottom); } - public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game) { + public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo) { Vector2i mousePosition = (Vector2i) mouse.Position; Vector2i imagePosition = transform.ScreenToImage(mousePosition); @@ -585,6 +593,7 @@ public class Game : GameWindow { } if (input.IsKeyPressed(Keys.Q)) { + photos[photoIndex].ViewOffset = Vector2i.Zero; zoomLevel = 0f; } @@ -620,7 +629,8 @@ public class Game : GameWindow { } // Delegate input to the active tool. - ToolStatus status = activeTool.HandleInput(KeyboardState, MouseState, transform, this); + ToolStatus status = activeTool.HandleInput( + KeyboardState, MouseState, transform, this, photos[photoIndex]); // Change back to the default tool if the active tool is done. if (status != ToolStatus.Active) { @@ -798,7 +808,7 @@ public class Game : GameWindow { List tasks = new(); foreach (Photo p in allPhotos) { tasks.Add(Task.Run( () => { - p.LoadThumbnailAsync(geometry.ThumbnailSize); + p.LoadThumbnailAsync(new Vector2i(256, 256)); lock (numThumbnailsLoadedLock) { numThumbnailsLoaded++; toast.Set($"[{numThumbnailsLoaded}/{allPhotos.Count}] Loading thumbnails"); @@ -875,7 +885,10 @@ public class Game : GameWindow { 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, + Vector2i offset = new((int) (activePhoto.ViewOffset.X * scale), + (int) (activePhoto.ViewOffset.Y * scale)); + Box2i photoBox = Util.MakeBox(center.X - renderSize.X / 2 + offset.X, + center.Y - renderSize.Y / 2 + offset.Y, renderSize.X, renderSize.Y); activeOffset = new(photoBox.Min.X, photoBox.Min.Y); transform = new Transform(activeScale, activeOffset, activePhoto.Size);