Browse Source

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

main
Colin McMillen 12 months ago
parent
commit
b0fd20cd89
  1. 31
      Program.cs

31
Program.cs

@ -10,6 +10,7 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Drawing;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
@ -360,7 +361,7 @@ public class Texture : IDisposable {
Handle = GL.GenTexture();
if (Handle > maxHandle) {
Console.WriteLine("GL.GenTexture #" + Handle);
// Console.WriteLine("GL.GenTexture #" + Handle);
maxHandle = Handle;
}
GL.ActiveTexture(TextureUnit.Texture0);
@ -582,6 +583,22 @@ public class Game : GameWindow {
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.
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
@ -685,17 +702,25 @@ public class Game : GameWindow {
int minLoadedImage = Math.Max(0, photoIndex - 20);
int maxLoadedImage = Math.Min(photoIndex + 20, photos.Count - 1);
// 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) {
if (i < minUnloadedImage || i > maxUnloadedImage) {
loadedImages.Remove(i);
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.
for (int i = minLoadedImage; i <= maxLoadedImage; i++) {
if (!loadedImages.Contains(i)) {
Console.WriteLine("loading " + i);
// Console.WriteLine("loading " + i);
loadedImages.Add(i);
await Task.Run( () => { photos[i].LoadAsync(); });
}

Loading…
Cancel
Save