draw text indicating zoom level

This commit is contained in:
Colin McMillen 2023-07-24 12:36:44 -04:00
parent f853ef7cda
commit fe9da67b04

View File

@ -142,6 +142,7 @@ void main() {
// FIXME: this should probably be IDisposable?
public class Photo {
public bool Loaded = false;
private string file;
private Texture texture;
private Texture placeholder;
@ -170,6 +171,7 @@ public class Photo {
texture = new Texture(image);
image.Dispose();
image = null;
Loaded = true;
}
return texture;
}
@ -253,22 +255,28 @@ public class UiGeometry {
public static class Util {
public const float PI = (float) Math.PI;
// FIXME: capitalize these functions
public static Box2i makeBox(int left, int top, int width, int height) {
return new Box2i(left, top, left + width, top + height);
}
public static Image<Rgba32> makeImage(float width, float height) {
return new((int) Math.Ceiling(width), (int) Math.Ceiling(height), new Rgba32(0x00, 0x00, 0x00, 0x00));
return new((int) Math.Ceiling(width), (int) Math.Ceiling(height));
}
public static Texture renderText(string text) {
Font font = SystemFonts.CreateFont("Consolas", 36, FontStyle.Bold);
return renderText(text, 16);
}
public static Texture renderText(string text, int size) {
Font font = SystemFonts.CreateFont("Consolas", size, FontStyle.Bold);
TextOptions options = new(font);
FontRectangle size = TextMeasurer.Measure(text, new TextOptions(font));
Image<Rgba32> image = makeImage(size.Width, size.Height);
FontRectangle rect = TextMeasurer.Measure(text, new TextOptions(font));
Image<Rgba32> image = makeImage(rect.Width, rect.Height);
IBrush brush = Brushes.Solid(Color.White);
IPen pen = Pens.Solid(Color.Black, 1f);
image.Mutate(x => x.DrawText(options, text, brush, pen));
// IPen pen = Pens.Solid(Color.Black, 1f);
// image.Mutate(x => x.DrawText(options, text, brush, pen));
image.Mutate(x => x.DrawText(options, text, brush));
Texture texture = new Texture(image);
image.Dispose();
return texture;
@ -471,10 +479,11 @@ public class Game : GameWindow {
DrawBox(box, 3, Color4.White);
}
}
Texture label = Util.renderText("hello world what is going on");
// Texture label = Util.renderStar(10);
DrawTexture(label, Util.makeBox(10, 10, label.Size.X, label.Size.Y));
label.Dispose();
if (photos[photoIndex].Loaded) {
Texture label = Util.renderText(String.Format("zoom: {0:F1}%", scale * 100));
DrawTexture(label, Util.makeBox(10, 10, label.Size.X, label.Size.Y));
label.Dispose();
}
SwapBuffers();
}