make a DrawText function; draw the active photo's filename

This commit is contained in:
Colin McMillen 2023-07-24 12:53:21 -04:00
parent 028419eb20
commit a0d6267905

View File

@ -143,24 +143,24 @@ void main() {
// FIXME: this should probably be IDisposable? // FIXME: this should probably be IDisposable?
public class Photo { public class Photo {
public bool Loaded = false; public bool Loaded = false;
private string file; public string File;
private Texture texture; private Texture texture;
private Texture placeholder; private Texture placeholder;
private Image<Rgba32>? image = null; private Image<Rgba32>? image = null;
public Photo(string file, Texture placeholder) { public Photo(string file, Texture placeholder) {
this.file = file; File = file;
this.placeholder = placeholder; this.placeholder = placeholder;
texture = placeholder; texture = placeholder;
} }
public async void Load() { public async void Load() {
image = await Image.LoadAsync<Rgba32>(file); image = await Image.LoadAsync<Rgba32>(File);
ExifProfile? exifs = image.Metadata.ExifProfile; ExifProfile? exifs = image.Metadata.ExifProfile;
if (exifs != null) { if (exifs != null) {
foreach (IExifValue exif in exifs.Values) { foreach (IExifValue exif in exifs.Values) {
if (exif.Tag.ToString() == "Model") { if (exif.Tag.ToString() == "Model") {
Console.WriteLine($"{file} {exif.Tag}: {exif.GetValue()}"); Console.WriteLine($"{File} {exif.Tag}: {exif.GetValue()}");
} }
} }
} }
@ -456,7 +456,8 @@ public class Game : GameWindow {
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
GL.ActiveTexture(TextureUnit.Texture0); GL.ActiveTexture(TextureUnit.Texture0);
Texture active = photos[photoIndex].Texture(); Photo activePhoto = photos[photoIndex];
Texture active = activePhoto.Texture();
// FIXME: make a function for scaling & centering one box on another. // FIXME: make a function for scaling & centering one box on another.
float scaleX = 1f * geometry.PhotoBox.Size.X / active.Size.X; float scaleX = 1f * geometry.PhotoBox.Size.X / active.Size.X;
@ -478,10 +479,10 @@ public class Game : GameWindow {
DrawBox(box, 3, Color4.White); DrawBox(box, 3, Color4.White);
} }
} }
if (photos[photoIndex].Loaded) {
Texture label = Util.RenderText($"zoom: {(scale * 100):F1}%"); DrawText(activePhoto.File, 10, 10);
DrawTexture(label, Util.MakeBox(10, 10, label.Size.X, label.Size.Y)); if (activePhoto.Loaded) {
label.Dispose(); DrawText($"zoom: {(scale * 100):F1}%", 10, 30);
} }
SwapBuffers(); SwapBuffers();
@ -506,6 +507,12 @@ public class Game : GameWindow {
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color); DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color);
} }
void DrawText(string text, int x, int y) {
Texture label = Util.RenderText(text);
DrawTexture(label, Util.MakeBox(x, y, label.Size.X, label.Size.Y));
label.Dispose();
}
protected override void OnResize(ResizeEventArgs e) { protected override void OnResize(ResizeEventArgs e) {
base.OnResize(e); base.OnResize(e);
Console.WriteLine($"OnResize: {e.Width}x{e.Height}"); Console.WriteLine($"OnResize: {e.Width}x{e.Height}");