diff --git a/GraphicsManager/GraphicsManager.csproj b/GraphicsManager/GraphicsManager.csproj
index 091acc0..50771e6 100644
--- a/GraphicsManager/GraphicsManager.csproj
+++ b/GraphicsManager/GraphicsManager.csproj
@@ -10,7 +10,7 @@
False
https://git.jacobtech.com/JacobTech.com/GraphicsManager
git
- 1.0.0-alpha7
+ 1.0.0-alpha8
diff --git a/GraphicsManager/Objects/Core/Font.cs b/GraphicsManager/Objects/Core/Font.cs
index 4c4fad5..b2880db 100755
--- a/GraphicsManager/Objects/Core/Font.cs
+++ b/GraphicsManager/Objects/Core/Font.cs
@@ -9,10 +9,59 @@ public class Font
private static List? System = null;
private List _Faces = new();
private Library lib;
+
+ internal Font()
+ {
+ Name = null!;
+ Assembly = null!;
+ Embeded = false;
+ if (lib is null) lib = new();
+ //TODO add more systemfont dection methods
+ if (System is null)
+ {
+ System = new();
+ if (OperatingSystem.IsLinux())
+ {
+ try
+ {
+ Process proc = new()
+ {
+ StartInfo = new()
+ {
+ FileName = "/bin/bash",
+ Arguments = "-c \"fc-list ':' file\"",
+ RedirectStandardOutput = true,
+ }
+ };
+ proc.Start();
+ proc.WaitForExit();
+ string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
+ for (int i = 0; i < files.Length; i++)
+ {
+ System!.Add(new Face(lib, files[i], 0));
+ }
+ }
+ catch
+ {
+ }
+ }
+ }
+
+ for (int i = 0; i < System!.Count; i++) _Faces.Add(System![i]);
+ //TODO add a reserved backup font
+ }
public IReadOnlyList Faces => _Faces.AsReadOnly();
public void SetEmbeddedFont(string Font, Assembly? Assembly = null)
{
_ = Font ?? throw new ArgumentNullException(nameof(Font));
+ string Base = "GraphicsManager.Resources.Fonts.";
+ if (Assembly is not null) Base = string.Empty;
+ byte[] f = (Assembly is null
+ ? Tools.GetResourceBytes(Base + Font)
+ : Tools.GetResourceBytes(Assembly!, $"{Base}{Font}"));
+ if (HasTopFont) _Faces[0] = new Face(lib, f, 0);
+ else _Faces.Insert(0, new Face(lib, f, 0));
+ HasTopFont = true;
this.Assembly = Assembly;
this.Embeded = true;
this.Name = Font;
@@ -26,89 +75,14 @@ public class Font
Assembly = Assembly,
Embeded = true,
Name = Font,
+ HasTopFont = true
};
- Library lib = new();
string Base = "GraphicsManager.Resources.Fonts.";
if (Assembly is not null) Base = string.Empty;
byte[] f = (Assembly is null
? Tools.GetResourceBytes(Base + Font)
: Tools.GetResourceBytes(Assembly!, $"{Base}{Font}"));
- fontclass._Faces.Add(new Face(lib, f, 0));
- if (System is null)
- {
- System = new();
- if (OperatingSystem.IsLinux())
- {
- try
- {
- Process proc = new()
- {
- StartInfo = new()
- {
- FileName = "/bin/bash",
- Arguments = "-c \"fc-list ':' file\"",
- RedirectStandardOutput = true,
- }
- };
- proc.Start();
- proc.WaitForExit();
- string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
- for (int i = 0; i < files.Length; i++)
- {
- System!.Add(new Face(fontclass.lib, files[i], 0));
- }
- }
- catch
- {
- }
- }
- }
-
- for (int i = 0; i < System!.Count; i++) fontclass._Faces.Add(System![i]);
- return fontclass;
- }
-
- public static Font MakeFontFromSystem()
- {
-
- Font fontclass = new()
- {
- Assembly = null,
- Embeded = false,
- Name = default!,
- lib = new()
- };
- if (Font.System is null)
- {
- Font.System = new();
- if (OperatingSystem.IsLinux())
- {
- try
- {
- Process proc = new()
- {
- StartInfo = new()
- {
- FileName = "/bin/bash",
- Arguments = "-c \"fc-list ':' file\"",
- RedirectStandardOutput = true,
- }
- };
- proc.Start();
- proc.WaitForExit();
- string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
- for (int i = 0; i < files.Length; i++)
- {
- Font.System!.Add(new Face(fontclass.lib, files[i], 0));
- }
- }
- catch
- {
- }
- }
- }
-
- for (int i = 0; i < Font.System!.Count; i++) fontclass._Faces.Add(Font.System![i]);
+ fontclass._Faces.Insert(0, new Face(fontclass.lib, f, 0));
return fontclass;
}
@@ -120,55 +94,25 @@ public class Font
Assembly = null,
Embeded = false,
Name = Font,
+ HasTopFont = true
};
- fontclass.lib = new();
- fontclass._Faces.Add(new Face(fontclass.lib, File.ReadAllBytes(Font), 0));
- if (System is null)
- {
- System = new();
- if (OperatingSystem.IsLinux())
- {
- try
- {
- Process proc = new()
- {
- StartInfo = new()
- {
- FileName = "/bin/bash",
- Arguments = "-c \"fc-list ':' file\"",
- RedirectStandardOutput = true,
- }
- };
- proc.Start();
- proc.WaitForExit();
- string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
- for (int i = 0; i < files.Length; i++)
- {
- System!.Add(new Face(fontclass.lib, files[i], 0));
- }
- }
- catch
- {
- }
- }
- }
-
- for (int i = 0; i < System!.Count; i++) fontclass._Faces.Add(System![i]);
+ fontclass._Faces.Insert(0, new Face(fontclass.lib, Font, 0));
return fontclass;
}
-
+
public void SetFontFile(string Font)
{
_ = Font ?? throw new ArgumentNullException(nameof(Font));
- _Faces.RemoveAt(0);
- _Faces.Reverse();
- _Faces.Add(new Face(lib, File.ReadAllBytes(Font), 0));
- _Faces.Reverse();
+ if (HasTopFont) _Faces[0] = new Face(lib, Font, 0);
+ else _Faces.Insert(0, new Face(lib, Font, 0));
+ HasTopFont = true;
this.Assembly = null;
this.Embeded = false;
this.Name = Font;
}
+ private bool HasTopFont = false;
+ public uint PixelHeight { get; set; } = 20;
public string Name { get; private set; } = default!;
public bool Embeded { get; private set; }
public Assembly? Assembly { get; private set; }
diff --git a/GraphicsManager/Objects/Core/Texture.cs b/GraphicsManager/Objects/Core/Texture.cs
index df63372..cbd43db 100755
--- a/GraphicsManager/Objects/Core/Texture.cs
+++ b/GraphicsManager/Objects/Core/Texture.cs
@@ -45,7 +45,7 @@ public class Texture
{
}
- internal static Texture TextureForChar(Label l, char charter, uint PixelHeight, Face[] faces)
+ internal static Texture TextureForChar(Font l, char charter, Face[] faces)
{
Texture t = new();
for (int i = 0; i < faces.Length; i++)
@@ -54,7 +54,7 @@ public class Texture
{
if (!Label._characters.ContainsKey(l)) Label._characters.Add(l, new Dictionary());
if (Label._characters[l].ContainsKey(charter)) return Label._characters[l][(ushort)charter].Texture;
- faces[i].SetPixelSizes(0, PixelHeight);
+ faces[i].SetPixelSizes(0, l.PixelHeight);
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
diff --git a/GraphicsManager/Objects/Label.cs b/GraphicsManager/Objects/Label.cs
index 6606f05..c55386a 100755
--- a/GraphicsManager/Objects/Label.cs
+++ b/GraphicsManager/Objects/Label.cs
@@ -12,6 +12,7 @@ namespace GraphicsManager.Objects;
public class Label : IRenderObject
{
public static readonly Shader DefaultTextShader = new("Label", true);
+ public static readonly Font DefaultFont = new();
public IParent? Parent { get; private set; }
public ObjectAnchor Anchor { get; set; } = ObjectAnchor.Left | ObjectAnchor.Top;
private Vector2 laf = new(), saf = new();
@@ -20,10 +21,10 @@ public class Label : IRenderObject
public Vector2 SizeAsFloat { get { return saf; } }
public bool Visible { get; set; } = true;
- public static readonly Dictionary