add PageUp/PageDown/Home/End keybindings for going through photos

This commit is contained in:
Colin McMillen 2023-07-25 21:44:22 -04:00
parent 27a4a64ccb
commit b0fd20cd89

View File

@ -10,6 +10,7 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Xmp; using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Drawing; using SixLabors.ImageSharp.Drawing;
using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Xml.Linq; using System.Xml.Linq;
@ -360,7 +361,7 @@ public class Texture : IDisposable {
Handle = GL.GenTexture(); Handle = GL.GenTexture();
if (Handle > maxHandle) { if (Handle > maxHandle) {
Console.WriteLine("GL.GenTexture #" + Handle); // Console.WriteLine("GL.GenTexture #" + Handle);
maxHandle = Handle; maxHandle = Handle;
} }
GL.ActiveTexture(TextureUnit.Texture0); GL.ActiveTexture(TextureUnit.Texture0);
@ -582,6 +583,22 @@ public class Game : GameWindow {
photoIndex--; photoIndex--;
} }
if (input.IsKeyPressed(Keys.Home)) {
photoIndex = 0;
}
if (input.IsKeyPressed(Keys.End)) {
photoIndex = photos.Count - 1;
}
if (input.IsKeyPressed(Keys.PageDown)) {
photoIndex += 10;
}
if (input.IsKeyPressed(Keys.PageUp)) {
photoIndex -= 10;
}
// Make sure the photoIndex is actually valid. // Make sure the photoIndex is actually valid.
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1); photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
@ -685,17 +702,25 @@ public class Game : GameWindow {
int minLoadedImage = Math.Max(0, photoIndex - 20); int minLoadedImage = Math.Max(0, photoIndex - 20);
int maxLoadedImage = Math.Min(photoIndex + 20, photos.Count - 1); int maxLoadedImage = Math.Min(photoIndex + 20, photos.Count - 1);
// First, unload images that are far outside our window. // First, unload images that are far outside our window.
// FIXME: also cancel any in-progress loading tasks that have moved outside our window.
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
foreach (int i in loadedImages) { foreach (int i in loadedImages) {
if (i < minUnloadedImage || i > maxUnloadedImage) { if (i < minUnloadedImage || i > maxUnloadedImage) {
loadedImages.Remove(i); loadedImages.Remove(i);
photos[i].Unload(); photos[i].Unload();
Console.WriteLine("unloading " + i); // Console.WriteLine("unloading " + i);
} }
} }
stopwatch.Stop();
if (stopwatch.Elapsed.TotalMilliseconds > 1) {
Console.WriteLine(stopwatch.Elapsed.TotalMilliseconds);
}
// Then, start loading any images that aren't in our window. // Then, start loading any images that aren't in our window.
for (int i = minLoadedImage; i <= maxLoadedImage; i++) { for (int i = minLoadedImage; i <= maxLoadedImage; i++) {
if (!loadedImages.Contains(i)) { if (!loadedImages.Contains(i)) {
Console.WriteLine("loading " + i); // Console.WriteLine("loading " + i);
loadedImages.Add(i); loadedImages.Add(i);
await Task.Run( () => { photos[i].LoadAsync(); }); await Task.Run( () => { photos[i].LoadAsync(); });
} }