|
|
@ -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<Task> 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); |
|
|
|