From 75e186c392813377e7523f95cdf7cc899f3e4124 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Sun, 16 Jul 2023 19:23:03 -0400 Subject: [PATCH] add new Photo class --- Program.cs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Program.cs b/Program.cs index 2489712..ecdc79a 100644 --- a/Program.cs +++ b/Program.cs @@ -138,6 +138,15 @@ void main() { } +public class Photo { + public Texture Texture; + + public Photo(string filename) { + Image image = Image.Load(filename); + Texture = new Texture(image); + } +} + public class Texture : IDisposable { public int Handle; public Vector2i Size; @@ -247,8 +256,8 @@ public class Game : GameWindow { int VertexBufferObject; int ElementBufferObject; int VertexArrayObject; - List textures = new(); - int textureIndex = 0; + List photos = new(); + int textureIndex = 0; // FIXME: rename to photoIndex Shader shader = new(); Matrix4 projection; @@ -268,7 +277,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 < textures.Count) { + if (0 <= i && i < photos.Count) { textureIndex = i; } } @@ -287,7 +296,7 @@ public class Game : GameWindow { // 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) { + if (textureIndex < photos.Count - 1) { downTimer = now + 10000 * 200; textureIndex++; } @@ -338,9 +347,8 @@ public class Game : GameWindow { string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); foreach (string file in files) { if (file.ToLower().EndsWith(".jpg")) { - Image image = Image.Load(file); - textures.Add(new Texture(image)); - if (textures.Count > 10) { + photos.Add(new Photo(file)); + if (photos.Count > 10) { break; } } @@ -357,7 +365,7 @@ public class Game : GameWindow { GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject); GL.ActiveTexture(TextureUnit.Texture0); - Texture active = textures[textureIndex]; + Texture active = photos[textureIndex].Texture; // FIXME: make a function for scaling & centering one box on another. float scaleX = 1f * geometry.PhotoBox.Size.X / active.Size.X; @@ -368,9 +376,9 @@ public class Game : GameWindow { Vector2i center = (Vector2i) geometry.PhotoBox.Center; Box2i photoBox = Util.makeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y); DrawTexture(active, photoBox); - for (int i = 0; i < textures.Count; i++) { + for (int i = 0; i < photos.Count; i++) { Box2i box = geometry.ThumbnailBoxes[i]; - DrawTexture(textures[i], box); + DrawTexture(photos[i].Texture, box); if (i == textureIndex) { DrawBox(box, 5, Color4.Black); DrawBox(box, 3, Color4.White);