add toasts! and toast about thumbnail loading

This commit is contained in:
Colin McMillen 2023-08-26 12:40:36 -04:00
parent 9620a3af1d
commit 393369773b

View File

@ -346,6 +346,27 @@ public static class Util {
} }
} }
public class Toast {
private string message = "";
private double time;
private double expiryTime;
public void Set(string message) {
this.message = message;
this.expiryTime = time + 5.0;
}
public string Get() {
return message;
}
public void Update(double elapsed) {
time += elapsed;
if (time > expiryTime) {
message = "";
}
}
}
public class Game : GameWindow { public class Game : GameWindow {
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) :
@ -378,14 +399,15 @@ public class Game : GameWindow {
int VertexBufferObject; int VertexBufferObject;
int ElementBufferObject; int ElementBufferObject;
int VertexArrayObject; int VertexArrayObject;
readonly object thumbnailsLoadedLock = new(); int numThumbnailsLoaded = 0;
int thumbnailsLoaded = 0; readonly object numThumbnailsLoadedLock = new();
List<Photo> allPhotos = new(); List<Photo> allPhotos = new();
List<Photo> photos = new(); List<Photo> photos = new();
HashSet<Photo> loadedImages = new(); HashSet<Photo> loadedImages = new();
HashSet<Photo> loadingImages = new(); HashSet<Photo> loadingImages = new();
readonly object loadedImagesLock = new(); readonly object loadedImagesLock = new();
readonly ViewTool viewTool = new ViewTool(); readonly ViewTool viewTool = new ViewTool();
Toast toast = new();
ITool activeTool; ITool activeTool;
int photoIndex = 0; int photoIndex = 0;
int ribbonIndex = 0; int ribbonIndex = 0;
@ -399,6 +421,7 @@ public class Game : GameWindow {
protected override void OnUpdateFrame(FrameEventArgs e) { protected override void OnUpdateFrame(FrameEventArgs e) {
base.OnUpdateFrame(e); base.OnUpdateFrame(e);
toast.Update(e.Time);
Photo previousPhoto = photos[photoIndex]; Photo previousPhoto = photos[photoIndex];
@ -641,8 +664,8 @@ public class Game : GameWindow {
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\07\31"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\07\31");
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
for (int i = 0; i < files.Count(); i++) { for (int i = 0; i < files.Count(); i++) {
string file = files[i]; string file = files[i];
@ -726,14 +749,13 @@ public class Game : GameWindow {
foreach (Photo p in allPhotos) { foreach (Photo p in allPhotos) {
tasks.Add(Task.Run( () => { tasks.Add(Task.Run( () => {
p.LoadThumbnailAsync(geometry.ThumbnailSize); p.LoadThumbnailAsync(geometry.ThumbnailSize);
lock (thumbnailsLoadedLock) { lock (numThumbnailsLoadedLock) {
thumbnailsLoaded++; numThumbnailsLoaded++;
Console.WriteLine(thumbnailsLoaded); toast.Set($"Loading thumbnails: {numThumbnailsLoaded}/{allPhotos.Count}");
} }
})); }));
} }
Console.WriteLine("TASKS: " + tasks.Count); await Task.WhenAll(tasks).ContinueWith(t => { toast.Set("Loading thumbnails: done!"); });
await Task.WhenAll(tasks).ContinueWith(t => { Console.WriteLine("done????"); });
} }
// To find the JPEG compression level of a file from the command line: // To find the JPEG compression level of a file from the command line:
@ -830,7 +852,7 @@ public class Game : GameWindow {
// Second line. // Second line.
y += 20; y += 20;
DrawText(activeTool.Status(), geometry.StatusBox.Min.X, y); DrawText(activeTool.Status() + toast.Get(), geometry.StatusBox.Min.X, y);
DrawText(String.Format("FPS: {0,2}", fpsCounter.Fps), geometry.StatusBox.Max.X - 66, y); DrawText(String.Format("FPS: {0,2}", fpsCounter.Fps), geometry.StatusBox.Max.X - 66, y);
if (activePhoto.Loaded) { if (activePhoto.Loaded) {
DrawText($"{(scale * 100):F1}%", geometry.StatusBox.Max.X - 136, y); DrawText($"{(scale * 100):F1}%", geometry.StatusBox.Max.X - 136, y);
@ -1008,7 +1030,7 @@ static class Program {
// nwSettings.Size = new Vector2i(1600, 900); // nwSettings.Size = new Vector2i(1600, 900);
nwSettings.MinimumSize = UiGeometry.MIN_WINDOW_SIZE; nwSettings.MinimumSize = UiGeometry.MIN_WINDOW_SIZE;
nwSettings.Title = "Totte"; nwSettings.Title = "Totte";
nwSettings.IsEventDriven = true; nwSettings.IsEventDriven = false;
nwSettings.Icon = new WindowIcon(Util.RenderAppIcon()); nwSettings.Icon = new WindowIcon(Util.RenderAppIcon());
using (Game game = new(gwSettings, nwSettings)) { using (Game game = new(gwSettings, nwSettings)) {