add toasts! and toast about thumbnail loading
This commit is contained in:
parent
9620a3af1d
commit
393369773b
44
Program.cs
44
Program.cs
@ -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 Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) :
|
||||
@ -378,14 +399,15 @@ public class Game : GameWindow {
|
||||
int VertexBufferObject;
|
||||
int ElementBufferObject;
|
||||
int VertexArrayObject;
|
||||
readonly object thumbnailsLoadedLock = new();
|
||||
int thumbnailsLoaded = 0;
|
||||
int numThumbnailsLoaded = 0;
|
||||
readonly object numThumbnailsLoadedLock = new();
|
||||
List<Photo> allPhotos = new();
|
||||
List<Photo> photos = new();
|
||||
HashSet<Photo> loadedImages = new();
|
||||
HashSet<Photo> loadingImages = new();
|
||||
readonly object loadedImagesLock = new();
|
||||
readonly ViewTool viewTool = new ViewTool();
|
||||
Toast toast = new();
|
||||
ITool activeTool;
|
||||
int photoIndex = 0;
|
||||
int ribbonIndex = 0;
|
||||
@ -399,6 +421,7 @@ public class Game : GameWindow {
|
||||
|
||||
protected override void OnUpdateFrame(FrameEventArgs e) {
|
||||
base.OnUpdateFrame(e);
|
||||
toast.Update(e.Time);
|
||||
|
||||
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\import");
|
||||
// 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\many-birds\");
|
||||
string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
|
||||
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
|
||||
|
||||
for (int i = 0; i < files.Count(); i++) {
|
||||
string file = files[i];
|
||||
@ -726,14 +749,13 @@ public class Game : GameWindow {
|
||||
foreach (Photo p in allPhotos) {
|
||||
tasks.Add(Task.Run( () => {
|
||||
p.LoadThumbnailAsync(geometry.ThumbnailSize);
|
||||
lock (thumbnailsLoadedLock) {
|
||||
thumbnailsLoaded++;
|
||||
Console.WriteLine(thumbnailsLoaded);
|
||||
lock (numThumbnailsLoadedLock) {
|
||||
numThumbnailsLoaded++;
|
||||
toast.Set($"Loading thumbnails: {numThumbnailsLoaded}/{allPhotos.Count}");
|
||||
}
|
||||
}));
|
||||
}
|
||||
Console.WriteLine("TASKS: " + tasks.Count);
|
||||
await Task.WhenAll(tasks).ContinueWith(t => { Console.WriteLine("done????"); });
|
||||
await Task.WhenAll(tasks).ContinueWith(t => { toast.Set("Loading thumbnails: done!"); });
|
||||
}
|
||||
|
||||
// To find the JPEG compression level of a file from the command line:
|
||||
@ -830,7 +852,7 @@ public class Game : GameWindow {
|
||||
|
||||
// Second line.
|
||||
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);
|
||||
if (activePhoto.Loaded) {
|
||||
DrawText($"{(scale * 100):F1}%", geometry.StatusBox.Max.X - 136, y);
|
||||
@ -1008,7 +1030,7 @@ static class Program {
|
||||
// nwSettings.Size = new Vector2i(1600, 900);
|
||||
nwSettings.MinimumSize = UiGeometry.MIN_WINDOW_SIZE;
|
||||
nwSettings.Title = "Totte";
|
||||
nwSettings.IsEventDriven = true;
|
||||
nwSettings.IsEventDriven = false;
|
||||
nwSettings.Icon = new WindowIcon(Util.RenderAppIcon());
|
||||
|
||||
using (Game game = new(gwSettings, nwSettings)) {
|
||||
|
Loading…
Reference in New Issue
Block a user