add ViewOffset to Photo for display
This commit is contained in:
parent
31e419b81b
commit
e612429298
1
Photo.cs
1
Photo.cs
@ -102,6 +102,7 @@ public class Photo {
|
|||||||
public ushort Orientation = 1;
|
public ushort Orientation = 1;
|
||||||
public GpsInfo? Gps = null;
|
public GpsInfo? Gps = null;
|
||||||
public Rectangle CropRectangle = Rectangle.Empty;
|
public Rectangle CropRectangle = Rectangle.Empty;
|
||||||
|
public Vector2i ViewOffset = Vector2i.Zero;
|
||||||
|
|
||||||
private static long touchCounter = 0;
|
private static long touchCounter = 0;
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
|
25
Program.cs
25
Program.cs
@ -87,14 +87,22 @@ public class Transform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface ITool {
|
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();
|
string Status();
|
||||||
void Draw(UiGeometry geometry, Game game);
|
void Draw(UiGeometry geometry, Game game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class ViewTool : ITool {
|
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;
|
return ToolStatus.Active;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +129,7 @@ public class CropTool : ITool {
|
|||||||
mouseDragEnd = new(photo.CropRectangle.Right, photo.CropRectangle.Bottom);
|
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 mousePosition = (Vector2i) mouse.Position;
|
||||||
Vector2i imagePosition = transform.ScreenToImage(mousePosition);
|
Vector2i imagePosition = transform.ScreenToImage(mousePosition);
|
||||||
|
|
||||||
@ -585,6 +593,7 @@ public class Game : GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.Q)) {
|
if (input.IsKeyPressed(Keys.Q)) {
|
||||||
|
photos[photoIndex].ViewOffset = Vector2i.Zero;
|
||||||
zoomLevel = 0f;
|
zoomLevel = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,7 +629,8 @@ public class Game : GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delegate input to the active tool.
|
// 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.
|
// Change back to the default tool if the active tool is done.
|
||||||
if (status != ToolStatus.Active) {
|
if (status != ToolStatus.Active) {
|
||||||
@ -798,7 +808,7 @@ public class Game : GameWindow {
|
|||||||
List<Task> tasks = new();
|
List<Task> tasks = new();
|
||||||
foreach (Photo p in allPhotos) {
|
foreach (Photo p in allPhotos) {
|
||||||
tasks.Add(Task.Run( () => {
|
tasks.Add(Task.Run( () => {
|
||||||
p.LoadThumbnailAsync(geometry.ThumbnailSize);
|
p.LoadThumbnailAsync(new Vector2i(256, 256));
|
||||||
lock (numThumbnailsLoadedLock) {
|
lock (numThumbnailsLoadedLock) {
|
||||||
numThumbnailsLoaded++;
|
numThumbnailsLoaded++;
|
||||||
toast.Set($"[{numThumbnailsLoaded}/{allPhotos.Count}] Loading thumbnails");
|
toast.Set($"[{numThumbnailsLoaded}/{allPhotos.Count}] Loading thumbnails");
|
||||||
@ -875,7 +885,10 @@ public class Game : GameWindow {
|
|||||||
|
|
||||||
Vector2i renderSize = (Vector2i) (((Vector2) active.Size) * scale);
|
Vector2i renderSize = (Vector2i) (((Vector2) active.Size) * scale);
|
||||||
Vector2i center = (Vector2i) geometry.PhotoBox.Center;
|
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);
|
renderSize.X, renderSize.Y);
|
||||||
activeOffset = new(photoBox.Min.X, photoBox.Min.Y);
|
activeOffset = new(photoBox.Min.X, photoBox.Min.Y);
|
||||||
transform = new Transform(activeScale, activeOffset, activePhoto.Size);
|
transform = new Transform(activeScale, activeOffset, activePhoto.Size);
|
||||||
|
Loading…
Reference in New Issue
Block a user