From 3c1e2c8dadfc1b813af46ed29c04753be10c0636 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 26 Jul 2023 17:29:59 -0400 Subject: [PATCH] start work on filtering by rating --- Program.cs | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/Program.cs b/Program.cs index 7947d99..ce0f27c 100644 --- a/Program.cs +++ b/Program.cs @@ -563,6 +563,7 @@ public class Game : GameWindow { int VertexBufferObject; int ElementBufferObject; int VertexArrayObject; + List allPhotos = new(); List photos = new(); HashSet loadedImages = new(); int photoIndex = 0; @@ -644,28 +645,42 @@ public class Game : GameWindow { // Make sure the photoIndex is actually valid. photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1); + // Handle presses of the "rating" keys -- 0-5 and `. + // A normal press just sets the rating of the current photo. + // If the user is holding "shift", we instead filter to only show photos of that rating or higher. + int rating = -1; + if (input.IsKeyPressed(Keys.D0) || input.IsKeyPressed(Keys.GraveAccent)) { - photos[photoIndex].Rating = 0; + rating = 0; } if (input.IsKeyPressed(Keys.D1)) { - photos[photoIndex].Rating = 1; + rating = 1; } if (input.IsKeyPressed(Keys.D2)) { - photos[photoIndex].Rating = 2; + rating = 2; } if (input.IsKeyPressed(Keys.D3)) { - photos[photoIndex].Rating = 3; + rating = 3; } if (input.IsKeyPressed(Keys.D4)) { - photos[photoIndex].Rating = 4; + rating = 4; } if (input.IsKeyPressed(Keys.D5)) { - photos[photoIndex].Rating = 5; + rating = 5; + } + + if (rating >= 0) { + bool shifted = input.IsKeyDown(Keys.LeftShift) || input.IsKeyDown(Keys.RightShift); + if (shifted) { + FilterByRating(rating); + } else { + photos[photoIndex].Rating = rating; + } } if (input.IsKeyPressed(Keys.Q)) { @@ -693,6 +708,10 @@ public class Game : GameWindow { } } + void FilterByRating(int rating) { + Console.WriteLine("filter to " + rating); + } + protected override void OnLoad() { base.OnLoad(); @@ -741,11 +760,12 @@ public class Game : GameWindow { string file = files[i]; if (file.ToLower().EndsWith(".jpg")) { Photo photo = new Photo(file, TEXTURE_BLACK); - photos.Add(photo); + allPhotos.Add(photo); } } - photos.Sort(ComparePhotosByDate); + allPhotos.Sort(ComparePhotosByDate); + photos = allPhotos; } private static int ComparePhotosByDate(Photo x, Photo y) {