draw text indicating zoom level
This commit is contained in:
parent
f853ef7cda
commit
fe9da67b04
29
Program.cs
29
Program.cs
@ -142,6 +142,7 @@ void main() {
|
|||||||
|
|
||||||
// FIXME: this should probably be IDisposable?
|
// FIXME: this should probably be IDisposable?
|
||||||
public class Photo {
|
public class Photo {
|
||||||
|
public bool Loaded = false;
|
||||||
private string file;
|
private string file;
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
private Texture placeholder;
|
private Texture placeholder;
|
||||||
@ -170,6 +171,7 @@ public class Photo {
|
|||||||
texture = new Texture(image);
|
texture = new Texture(image);
|
||||||
image.Dispose();
|
image.Dispose();
|
||||||
image = null;
|
image = null;
|
||||||
|
Loaded = true;
|
||||||
}
|
}
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
@ -253,22 +255,28 @@ public class UiGeometry {
|
|||||||
public static class Util {
|
public static class Util {
|
||||||
public const float PI = (float) Math.PI;
|
public const float PI = (float) Math.PI;
|
||||||
|
|
||||||
|
// FIXME: capitalize these functions
|
||||||
public static Box2i makeBox(int left, int top, int width, int height) {
|
public static Box2i makeBox(int left, int top, int width, int height) {
|
||||||
return new Box2i(left, top, left + width, top + height);
|
return new Box2i(left, top, left + width, top + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Image<Rgba32> makeImage(float width, float 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) {
|
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);
|
TextOptions options = new(font);
|
||||||
FontRectangle size = TextMeasurer.Measure(text, new TextOptions(font));
|
FontRectangle rect = TextMeasurer.Measure(text, new TextOptions(font));
|
||||||
Image<Rgba32> image = makeImage(size.Width, size.Height);
|
Image<Rgba32> image = makeImage(rect.Width, rect.Height);
|
||||||
IBrush brush = Brushes.Solid(Color.White);
|
IBrush brush = Brushes.Solid(Color.White);
|
||||||
IPen pen = Pens.Solid(Color.Black, 1f);
|
// IPen pen = Pens.Solid(Color.Black, 1f);
|
||||||
image.Mutate(x => x.DrawText(options, text, brush, pen));
|
// image.Mutate(x => x.DrawText(options, text, brush, pen));
|
||||||
|
image.Mutate(x => x.DrawText(options, text, brush));
|
||||||
Texture texture = new Texture(image);
|
Texture texture = new Texture(image);
|
||||||
image.Dispose();
|
image.Dispose();
|
||||||
return texture;
|
return texture;
|
||||||
@ -471,10 +479,11 @@ public class Game : GameWindow {
|
|||||||
DrawBox(box, 3, Color4.White);
|
DrawBox(box, 3, Color4.White);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Texture label = Util.renderText("hello world what is going on");
|
if (photos[photoIndex].Loaded) {
|
||||||
// Texture label = Util.renderStar(10);
|
Texture label = Util.renderText(String.Format("zoom: {0:F1}%", scale * 100));
|
||||||
DrawTexture(label, Util.makeBox(10, 10, label.Size.X, label.Size.Y));
|
DrawTexture(label, Util.makeBox(10, 10, label.Size.X, label.Size.Y));
|
||||||
label.Dispose();
|
label.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user