Browse Source

allow keyboard repeat for moving between thumbnails

main
Colin McMillen 12 months ago
parent
commit
8600a7e490
  1. 52
      Program.cs

52
Program.cs

@ -6,6 +6,7 @@ using OpenTK.Windowing.GraphicsLibraryFramework;
using System.Runtime.CompilerServices;
// https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Image.html
using Image = SixLabors.ImageSharp.Image;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
namespace SemiColinGames;
@ -17,6 +18,7 @@ public class CameraInfo {
}
public static readonly CameraInfo NIKON_D7000 = new(new Vector2i(4928, 3264));
public static readonly CameraInfo CANON_EOS_R6M2 = new(new Vector2i(6000, 4000));
public static readonly CameraInfo IPHONE_12_MINI = new(new Vector2i(4032, 3024));
}
@ -142,11 +144,17 @@ public class Texture : IDisposable {
public Texture(Image<Rgba32> image) {
Size = new Vector2i(image.Width, image.Height);
Console.WriteLine("----------------------------------");
Console.WriteLine($"image loaded: {Size}");
//foreach (IExifValue exif in image.Metadata.ExifProfile.Values) {
// Console.WriteLine($"{exif.Tag} : {exif.GetValue()}");
//}
ExifProfile? exifs = image.Metadata.ExifProfile;
if (exifs != null) {
foreach (IExifValue exif in exifs.Values) {
if (exif.Tag.ToString() == "Model") {
Console.WriteLine($"{exif.Tag}: {exif.GetValue()}");
}
}
}
byte[] pixelBytes = new byte[Size.X * Size.Y * Unsafe.SizeOf<Rgba32>()];
image.CopyPixelDataTo(pixelBytes);
image.Dispose();
@ -187,7 +195,7 @@ public class Texture : IDisposable {
public class UiGeometry {
public static Vector2i MIN_WINDOW_SIZE = new(640, 480);
private static CameraInfo activeCamera = CameraInfo.NIKON_D7000;
private static CameraInfo activeCamera = CameraInfo.CANON_EOS_R6M2;
public readonly Vector2i WindowSize;
public readonly List<Box2i> ThumbnailBoxes = new();
@ -198,7 +206,7 @@ public class UiGeometry {
public UiGeometry(Vector2i windowSize) {
WindowSize = windowSize;
int numThumbnails = 12;
int numThumbnails = 20;
int thumbnailHeight = WindowSize.Y / numThumbnails;
int thumbnailWidth = (int) 1.0 * thumbnailHeight * activeCamera.Resolution.X / activeCamera.Resolution.Y;
for (int i = 0; i < numThumbnails; i++) {
@ -223,6 +231,10 @@ public class Game : GameWindow {
UiGeometry geometry = new();
// Input handling.
long downTimer = Int64.MaxValue;
long upTimer = Int64.MaxValue;
// Four points, each consisting of (x, y, z, tex_x, tex_y).
float[] vertices = new float[20];
@ -242,9 +254,16 @@ public class Game : GameWindow {
protected override void OnUpdateFrame(FrameEventArgs e) {
base.OnUpdateFrame(e);
long now = DateTime.Now.Ticks;
KeyboardState input = KeyboardState;
// Close when Escape is pressed.
if (input.IsKeyDown(Keys.Escape)) {
Close();
}
// Look for mouse clicks on thumbnails.
if (MouseState.IsButtonPressed(0)) {
for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) {
Box2i box = geometry.ThumbnailBoxes[i];
@ -256,17 +275,26 @@ public class Game : GameWindow {
}
}
if (input.IsKeyDown(Keys.Escape)) {
Close();
// Track keyboard repeat times for advancing up/down.
if (!input.IsKeyDown(Keys.Down)) {
downTimer = Int64.MaxValue;
}
if (input.IsKeyPressed(Keys.Down)) {
if (!input.IsKeyDown(Keys.Up)) {
upTimer = Int64.MaxValue;
}
// FIXME: make a proper Model class for tracking the state of the controls?
if (input.IsKeyPressed(Keys.Down) || now > downTimer) {
if (textureIndex < textures.Count - 1) {
downTimer = now + 10000 * 200;
textureIndex++;
}
}
if (input.IsKeyPressed(Keys.Up)) {
if (input.IsKeyPressed(Keys.Up) || now > upTimer) {
if (textureIndex > 0) {
upTimer = now + 10000 * 200;
textureIndex--;
}
}
@ -306,11 +334,15 @@ public class Game : GameWindow {
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
// Load textures from JPEGs.
string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\");
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\");
string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\");
foreach (string file in files) {
if (file.ToLower().EndsWith(".jpg")) {
Image<Rgba32> image = Image.Load<Rgba32>(file);
textures.Add(new Texture(image));
if (textures.Count > 10) {
break;
}
}
}
}

Loading…
Cancel
Save