diff --git a/Program.cs b/Program.cs index 692f3d0..f93042f 100644 --- a/Program.cs +++ b/Program.cs @@ -286,6 +286,9 @@ public class Photo { public Texture Texture() { if (texture == placeholder && image != null) { + // The texture needs to be created on the GL thread, so we instantiate + // it here (since this is called from OnRenderFrame), as long as the + // image is ready to go. texture = new Texture(image); image.Dispose(); image = null; @@ -365,7 +368,7 @@ public class UiGeometry { public UiGeometry(Vector2i windowSize) { WindowSize = windowSize; - int numThumbnails = 13; + 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++) { @@ -467,6 +470,7 @@ public class Game : GameWindow { int VertexArrayObject; List photos = new(); int photoIndex = 0; + int ribbonIndex = 0; Shader shader = new(); Matrix4 projection; float zoomLevel = 0f; @@ -477,6 +481,7 @@ public class Game : GameWindow { KeyboardState input = KeyboardState; + // FIXME: add a confirm dialog before closing. (Also for the window-close button.) // Close when Escape is pressed. if (input.IsKeyDown(Keys.Escape)) { Close(); @@ -487,9 +492,7 @@ public class Game : GameWindow { for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) { Box2i box = geometry.ThumbnailBoxes[i]; if (box.ContainsInclusive((Vector2i) MouseState.Position)) { - if (0 <= i && i < photos.Count) { - photoIndex = i; - } + photoIndex = Math.Clamp(ribbonIndex + i, 0, photos.Count - 1); } } } @@ -594,7 +597,7 @@ public class Game : GameWindow { } } - for (int i = 0; i < 100 && i < photos.Count; i++) { + for (int i = 0; i < 40 && i < photos.Count; i++) { await Task.Run( () => { photos[i].Load(); }); } } @@ -627,11 +630,15 @@ public class Game : GameWindow { DrawTexture(active, photoBox); // Draw thumbnail boxes. + ribbonIndex = Math.Clamp(photoIndex - (geometry.ThumbnailBoxes.Count - 1) / 2, 0, Math.Max(0, photos.Count - geometry.ThumbnailBoxes.Count)); DrawFilledBox(geometry.ThumbnailBox, Color4.Black); - for (int i = 0; i < photos.Count && i < geometry.ThumbnailBoxes.Count(); i++) { + for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) { + if (ribbonIndex + i >= photos.Count) { + break; + } Box2i box = geometry.ThumbnailBoxes[i]; - DrawTexture(photos[i].Texture(), box); - if (i == photoIndex) { + DrawTexture(photos[ribbonIndex + i].Texture(), box); + if (ribbonIndex + i == photoIndex) { DrawBox(box, 5, Color4.Black); DrawBox(box, 3, Color4.White); }