Almost Done
removed more unused things and made code better
This commit is contained in:
parent
58586278d2
commit
2aa3f024f4
@ -91,14 +91,6 @@ public record Argumets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Verify()
|
|
||||||
{
|
|
||||||
return
|
|
||||||
(goodarg(Process) &&
|
|
||||||
goodarg(RemoteDirectory) &&
|
|
||||||
goodarg(LocalDirectory));
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool goodarg(string? arg)
|
private bool goodarg(string? arg)
|
||||||
{
|
{
|
||||||
return !(string.IsNullOrEmpty(arg) || string.IsNullOrWhiteSpace(arg));
|
return !(string.IsNullOrEmpty(arg) || string.IsNullOrWhiteSpace(arg));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using OpenTK.Mathematics;
|
||||||
|
|
||||||
namespace Updater;
|
namespace Updater;
|
||||||
|
|
||||||
@ -14,41 +15,48 @@ public class Config
|
|||||||
{
|
{
|
||||||
DownloadAmount = ConfigFileSize.MegaByte,
|
DownloadAmount = ConfigFileSize.MegaByte,
|
||||||
DownloadSpeed = ConfigFileSize.MegaByte,
|
DownloadSpeed = ConfigFileSize.MegaByte,
|
||||||
|
DrawingGaps = new()
|
||||||
|
{
|
||||||
|
X = 0,
|
||||||
|
Y = 0,
|
||||||
|
Z = 0,
|
||||||
|
W = 0
|
||||||
|
},
|
||||||
DownloadThreads = 1,
|
DownloadThreads = 1,
|
||||||
Scale = 2
|
Scale = 1
|
||||||
};
|
};
|
||||||
file.Colors = new Colors()
|
file.Colors = new Colors()
|
||||||
{
|
{
|
||||||
Background = new ConfigColor()
|
Background = new ConfigColor()
|
||||||
{
|
{
|
||||||
R = 0.1568627450980392f,
|
R = 40,
|
||||||
G = 0.1568627450980392f,
|
G = 40,
|
||||||
B = 0.1568627450980392f,
|
B = 40,
|
||||||
A = 1f
|
A = 255
|
||||||
},
|
},
|
||||||
Progress_bars = new ProgressBars()
|
Progress_bars = new ProgressBars()
|
||||||
{
|
{
|
||||||
Backcolor = new ConfigColor()
|
Backcolor = new ConfigColor()
|
||||||
{
|
{
|
||||||
R = 1.0f,
|
R = 255,
|
||||||
G = 1.0f,
|
G = 255,
|
||||||
B = 1.0f,
|
B = 255,
|
||||||
A = 1f
|
A = 255
|
||||||
},
|
},
|
||||||
Fillcolor = new ConfigColor()
|
Fillcolor = new ConfigColor()
|
||||||
{
|
{
|
||||||
R = 0.0392156862745098f,
|
R = 10,
|
||||||
G = 0.8509803921568627f,
|
G = 217,
|
||||||
B = 1f,
|
B = 255,
|
||||||
A = 1f
|
A = 255
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Text = new ConfigColor()
|
Text = new ConfigColor()
|
||||||
{
|
{
|
||||||
R = 1.0f,
|
R = 255,
|
||||||
G = 1.0f,
|
G = 255,
|
||||||
B = 1.0f,
|
B = 255,
|
||||||
A = 1f
|
A = 255
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!Directory.Exists(Handler.JT)) Directory.CreateDirectory(Handler.JT);
|
if (!Directory.Exists(Handler.JT)) Directory.CreateDirectory(Handler.JT);
|
||||||
@ -111,11 +119,9 @@ public class Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonSerializable(typeof(ConfigFile))]
|
[JsonSerializable(typeof(ConfigFile))]
|
||||||
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, WriteIndented = true)]
|
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Default,
|
||||||
internal partial class ConfigFileContext : JsonSerializerContext
|
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, WriteIndented = true)]
|
||||||
{
|
internal partial class ConfigFileContext : JsonSerializerContext;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ConfigFile
|
public class ConfigFile
|
||||||
{
|
{
|
||||||
@ -141,16 +147,25 @@ public class Format
|
|||||||
{
|
{
|
||||||
public ConfigFileSize DownloadSpeed { get; set; }
|
public ConfigFileSize DownloadSpeed { get; set; }
|
||||||
public ConfigFileSize DownloadAmount { get; set; }
|
public ConfigFileSize DownloadAmount { get; set; }
|
||||||
|
public ConfigVector DrawingGaps { get; set; } = default!;
|
||||||
public int DownloadThreads { get; set; }
|
public int DownloadThreads { get; set; }
|
||||||
public float Scale { get; set; }
|
public float Scale { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfigColor
|
public class ConfigColor
|
||||||
{
|
{
|
||||||
public float R { get; set; }
|
public byte R { get; set; }
|
||||||
public float G { get; set; }
|
public byte G { get; set; }
|
||||||
public float B { get; set; }
|
public byte B { get; set; }
|
||||||
public float A { get; set; }
|
public byte A { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConfigVector
|
||||||
|
{
|
||||||
|
public int X { get; set; }
|
||||||
|
public int Y { get; set; }
|
||||||
|
public int Z { get; set; }
|
||||||
|
public int W { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ConfigFileSize
|
public enum ConfigFileSize
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
namespace Updater
|
|
||||||
{
|
|
||||||
internal interface IRenderObject
|
|
||||||
{
|
|
||||||
public void Draw();
|
|
||||||
public void Clean();
|
|
||||||
public bool Visible { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace Updater;
|
|
||||||
|
|
||||||
internal struct LabelStr
|
|
||||||
{
|
|
||||||
internal float Scale;
|
|
||||||
internal string Font;
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using GraphicsManager;
|
using GraphicsManager;
|
||||||
using GraphicsManager.Enums;
|
using GraphicsManager.Enums;
|
||||||
@ -33,21 +32,14 @@ public class NewUpdater : FPSWindow
|
|||||||
};
|
};
|
||||||
Speed.Elapsed += Speed_Elapsed;
|
Speed.Elapsed += Speed_Elapsed;
|
||||||
CanControleUpdate = false;
|
CanControleUpdate = false;
|
||||||
//small = (uint)Math.Round(0.0656167979002625 * StartGUI.Height, 0);
|
|
||||||
//RenderObjects.Add(Total_Downloaded = new RenderText("Download Amount", "OpenSans-Regular", small, -0.9381188f, 0.149797574f, 1.0f, new Vector2(1f, 0f), new Vector4(cf.Colors.Text.R, cf.Colors.Text.G, cf.Colors.Text.B, cf.Colors.Text.A)));
|
|
||||||
//small = (uint)Math.Round(0.078740157480315 * StartGUI.Height, 0);
|
|
||||||
//RenderObjects.Add(Transfer_Speed = new RenderText("Download Speed", "OpenSans-Regular", small, -0.9381188f, -0.05263158f, 1.2f, new Vector2(1f, 0f), new Vector4(cf.Colors.Text.R, cf.Colors.Text.G, cf.Colors.Text.B, cf.Colors.Text.A)));
|
|
||||||
|
|
||||||
FontFamily r = FontFamily.LoadFontFamily(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Updater.Resource.OpenSans.zip"), "OpenSans");
|
FontFamily r = FontFamily.LoadFontFamily(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Updater.Resource.OpenSans.zip"), "OpenSans");
|
||||||
FontInteraction fi = FontInteraction.Load(r);
|
FontInteraction fi = FontInteraction.Load(r);
|
||||||
cf = Config.GetConfig();
|
cf = Config.GetConfig();
|
||||||
|
|
||||||
Size = new(cf.Scale(Size.X), cf.Scale(Size.Y));
|
Size = new(cf.Scale(Size.X), cf.Scale(Size.Y));
|
||||||
Argumets = args;
|
Argumets = args;
|
||||||
int WallDistance = cf.Scale(15);
|
int WallDistance = cf.Scale(15);
|
||||||
BackgroundColor = cf.Colors.Background.ToColor4();
|
BackgroundColor = cf.Colors.Background.ToColor4();
|
||||||
|
Texture ProgressbarTexture = TextureManager.AddTexture(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Updater.Resource.Progress.png"));
|
||||||
Texture ProgressbarTexture = TextureManager.AddTexture(File.OpenRead("/home/jacob/Pictures/Progress.png"));
|
|
||||||
Controls.Add(TotalProgress = new(ProgressbarTexture)
|
Controls.Add(TotalProgress = new(ProgressbarTexture)
|
||||||
{
|
{
|
||||||
Location = new(WallDistance, cf.Scale(70)),
|
Location = new(WallDistance, cf.Scale(70)),
|
||||||
@ -55,7 +47,7 @@ public class NewUpdater : FPSWindow
|
|||||||
BackgroundColor = cf.Colors.Progress_bars.Backcolor.ToColor4(),
|
BackgroundColor = cf.Colors.Progress_bars.Backcolor.ToColor4(),
|
||||||
ProgressColor = cf.Colors.Progress_bars.Fillcolor.ToColor4(),
|
ProgressColor = cf.Colors.Progress_bars.Fillcolor.ToColor4(),
|
||||||
ProgressValue = 5,
|
ProgressValue = 5,
|
||||||
ProgressGap = new(cf.Scale(3)),
|
DrawingGap = new(cf.Format.DrawingGaps.X, cf.Format.DrawingGaps.Y, cf.Format.DrawingGaps.Z, cf.Format.DrawingGaps.W),
|
||||||
Shader = Rectangle.DefaultAlphaShader[Context],
|
Shader = Rectangle.DefaultAlphaShader[Context],
|
||||||
TextureDisplay = TextureDisplay.ProgressHorizontalCenter,
|
TextureDisplay = TextureDisplay.ProgressHorizontalCenter,
|
||||||
UpdateOnDraw = true,
|
UpdateOnDraw = true,
|
||||||
@ -69,10 +61,19 @@ public class NewUpdater : FPSWindow
|
|||||||
Text = "Downloading ...."
|
Text = "Downloading ...."
|
||||||
});
|
});
|
||||||
Total_Downloaded.Location = new(cf.Scale(5), (TotalProgress.Size.Y - Total_Downloaded.Size.Y) / 2);
|
Total_Downloaded.Location = new(cf.Scale(5), (TotalProgress.Size.Y - Total_Downloaded.Size.Y) / 2);
|
||||||
|
FontInteraction tmp = fi.Clone();
|
||||||
|
tmp.FontSize = FontSize.Bold;
|
||||||
|
tmp.PixelHeight += 10;
|
||||||
|
Label Information;
|
||||||
|
Controls.Add(Information = new(tmp)
|
||||||
|
{
|
||||||
|
Text = "Downloading " + Argumets.RemoteDirectory,
|
||||||
|
Location = new(WallDistance + Total_Downloaded.Location.X, cf.Scale(5))
|
||||||
|
});
|
||||||
Controls.Add(Transfer_Speed = new(fi)
|
Controls.Add(Transfer_Speed = new(fi)
|
||||||
{
|
{
|
||||||
Text = "abcdefghijklmnopqrstuvwxyz",
|
Text = "Adverage Speed: ....",
|
||||||
Location = new(WallDistance + Total_Downloaded.Location.X, cf.Scale(5))
|
Location = new(Information.Location.X, + Information.Size.Y + cf.Scale(7))
|
||||||
});
|
});
|
||||||
|
|
||||||
int gap = cf.Scale(10);
|
int gap = cf.Scale(10);
|
||||||
@ -93,7 +94,7 @@ public class NewUpdater : FPSWindow
|
|||||||
BackgroundColor = TotalProgress.BackgroundColor,
|
BackgroundColor = TotalProgress.BackgroundColor,
|
||||||
ProgressColor = TotalProgress.ProgressColor,
|
ProgressColor = TotalProgress.ProgressColor,
|
||||||
ProgressValue = 100,
|
ProgressValue = 100,
|
||||||
ProgressGap = TotalProgress.ProgressGap,
|
DrawingGap = TotalProgress.DrawingGap,
|
||||||
Shader = TotalProgress.Shader,
|
Shader = TotalProgress.Shader,
|
||||||
TextureDisplay = TotalProgress.TextureDisplay,
|
TextureDisplay = TotalProgress.TextureDisplay,
|
||||||
UpdateOnDraw = true,
|
UpdateOnDraw = true,
|
||||||
@ -106,11 +107,11 @@ public class NewUpdater : FPSWindow
|
|||||||
Download.DoWork += Download_DoWork;
|
Download.DoWork += Download_DoWork;
|
||||||
Download.RunWorkerCompleted += Download_RunWorkerCompleted;
|
Download.RunWorkerCompleted += Download_RunWorkerCompleted;
|
||||||
Download.WorkerReportsProgress = true;
|
Download.WorkerReportsProgress = true;
|
||||||
Invoke(Download.RunWorkerAsync);
|
// Invoke(Download.RunWorkerAsync);
|
||||||
Speed.Start();
|
Speed.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ulong last;
|
private ulong last = 1;
|
||||||
private string end = "";
|
private string end = "";
|
||||||
|
|
||||||
private void Speed_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
private void Speed_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
||||||
@ -195,29 +196,34 @@ public class NewUpdater : FPSWindow
|
|||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine(exception);
|
HandelError(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
StackTrace st = new(ex, true);
|
HandelError(ex);
|
||||||
StackFrame? frame = st.GetFrame(0);
|
|
||||||
if (frame is null) return;
|
|
||||||
int line = frame.GetFileLineNumber();
|
|
||||||
string msg = $"Error in Updater.exe in function Download_DoWork on line '{line}' through error '{ex.Message}'\nERROR:\n'{ex}' FRAM:\n '{frame}'";
|
|
||||||
MessageBox.Show(ex.ToString());
|
|
||||||
_ = new HttpClient().PostAsync($"https://{Handler.Domain}/Updater/Error/updater", new StringContent(msg));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine(exception);
|
HandelError(exception);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HandelError(Exception ex)
|
||||||
|
{
|
||||||
|
StackTrace st = new(ex, true);
|
||||||
|
StackFrame? frame = st.GetFrame(0);
|
||||||
|
if (frame is null) return;
|
||||||
|
int line = frame.GetFileLineNumber();
|
||||||
|
string msg = $"Error in Updater.exe in function Download_DoWork on line '{line}' through error '{ex.Message}'\nERROR:\n'{ex}' FRAM:\n '{frame}'";
|
||||||
|
MessageBox.Show(ex.ToString());
|
||||||
|
_ = new HttpClient().PostAsync($"https://{Handler.Domain}/Updater/Error/updater", new StringContent(msg));
|
||||||
|
}
|
||||||
|
|
||||||
private async Task StartDownloadForFile(string file, ProgressBar<ulong> pb, Label pbLabel)
|
private async Task StartDownloadForFile(string file, ProgressBar<ulong> pb, Label pbLabel)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(file)) return;
|
if (string.IsNullOrWhiteSpace(file)) return;
|
||||||
@ -309,17 +315,17 @@ public class NewUpdater : FPSWindow
|
|||||||
Number = Math.Round(Number / Math.Pow(bytes, Exponet), 2, MidpointRounding.ToEven);
|
Number = Math.Round(Number / Math.Pow(bytes, Exponet), 2, MidpointRounding.ToEven);
|
||||||
if (!Number.ToString().Contains('.'))
|
if (!Number.ToString().Contains('.'))
|
||||||
{
|
{
|
||||||
return $"{Number}.00{Size}/s";
|
return $"Adverage Speed: {Number}.00{Size}/s";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Number.ToString().Remove(0, Number.ToString().IndexOf('.')).Length == 1)
|
if (Number.ToString().Remove(0, Number.ToString().IndexOf('.')).Length == 1)
|
||||||
{
|
{
|
||||||
return $"{Number}0{Size}/s";
|
return $"Adverage Speed: {Number}0{Size}/s";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $"{Number}{Size}/s";
|
return $"Adverage Speed: {Number}{Size}/s";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,184 +0,0 @@
|
|||||||
using OpenTK.Graphics.OpenGL4;
|
|
||||||
using OpenTK.Mathematics;
|
|
||||||
using SharpFont;
|
|
||||||
using SixLabors.ImageSharp;
|
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
|
||||||
using SixLabors.ImageSharp.Processing;
|
|
||||||
|
|
||||||
namespace Updater
|
|
||||||
{
|
|
||||||
internal class RenderObject : IRenderObject
|
|
||||||
{
|
|
||||||
public static Shader DefaultShader = new(
|
|
||||||
@"
|
|
||||||
#version 330 core
|
|
||||||
layout (location = 0) in vec3 aPos;
|
|
||||||
uniform vec4 objColor;
|
|
||||||
out vec4 vertexColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(aPos, 1.0);
|
|
||||||
vertexColor = objColor;
|
|
||||||
}
|
|
||||||
",
|
|
||||||
@"
|
|
||||||
#version 330 core
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
in vec4 vertexColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
FragColor = vertexColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
");
|
|
||||||
|
|
||||||
public RenderObject(float[] Points, uint[] Indexs, Vector4 Color, BufferUsageHint Hint = BufferUsageHint.StaticDraw, Image<Rgba32>? image = null, bool Invert = true)
|
|
||||||
{
|
|
||||||
BufferObject = GL.GenBuffer();
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
|
||||||
ArrayObject = GL.GenVertexArray();
|
|
||||||
GL.BindVertexArray(ArrayObject);
|
|
||||||
int add = 3;
|
|
||||||
if (image is not null) add = 5;
|
|
||||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, add * sizeof(float), 0);
|
|
||||||
if (image is not null)
|
|
||||||
{
|
|
||||||
img = true;
|
|
||||||
if (Invert) image.Mutate(x => x.Flip(FlipMode.Vertical));
|
|
||||||
var pixels = new List<byte>(4 * image.Width * image.Height);
|
|
||||||
|
|
||||||
for (int y = 0; y < image.Height; y++)
|
|
||||||
{
|
|
||||||
Span<Rgba32> row = new Span<Rgba32>();
|
|
||||||
|
|
||||||
for (int x = 0; x < image.Width; x++)
|
|
||||||
{
|
|
||||||
pixels.Add(row[x].R);
|
|
||||||
pixels.Add(row[x].G);
|
|
||||||
pixels.Add(row[x].B);
|
|
||||||
pixels.Add(row[x].A);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Shader = new Shader(
|
|
||||||
@"
|
|
||||||
#version 330
|
|
||||||
layout(location = 0) in vec3 aPosition;
|
|
||||||
layout(location = 1) in vec2 aTexCoord;
|
|
||||||
out vec2 texCoord;
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
texCoord = aTexCoord;
|
|
||||||
gl_Position = vec4(aPosition, 1.0);
|
|
||||||
}",
|
|
||||||
@"
|
|
||||||
#version 330
|
|
||||||
out vec4 outputColor;
|
|
||||||
in vec2 texCoord;
|
|
||||||
uniform sampler2D texture0;
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
outputColor = texture(texture0, texCoord);
|
|
||||||
}
|
|
||||||
"
|
|
||||||
);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
|
|
||||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
|
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixels.ToArray());
|
|
||||||
int texCoordLocation = Shader.GetAttribLocation("aTexCoord");
|
|
||||||
GL.EnableVertexAttribArray(texCoordLocation);
|
|
||||||
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
GL.EnableVertexAttribArray(0);
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
|
||||||
GL.BufferData(BufferTarget.ArrayBuffer, Points.Length * sizeof(float), Points, Hint);
|
|
||||||
GL.BindVertexArray(ArrayObject);
|
|
||||||
ElementBufferObject = GL.GenBuffer();
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
|
||||||
GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(uint), Indexs, Hint);
|
|
||||||
this.Points_ = Points;
|
|
||||||
this.Indexs = Indexs;
|
|
||||||
this.Hint = Hint;
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector4 Color { get; set; }
|
|
||||||
|
|
||||||
public bool Visible { get; set; } = true;
|
|
||||||
|
|
||||||
public void Draw()
|
|
||||||
{
|
|
||||||
if (Visible)
|
|
||||||
{
|
|
||||||
Shader.Use();
|
|
||||||
GL.Uniform4(0, Color);
|
|
||||||
if (img)
|
|
||||||
{
|
|
||||||
GL.Enable(EnableCap.Blend);
|
|
||||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
|
||||||
GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
|
||||||
}
|
|
||||||
GL.BindVertexArray(ArrayObject);
|
|
||||||
GL.DrawElements(PrimitiveType.Triangles, Indexs.Length, DrawElementsType.UnsignedInt, 0);
|
|
||||||
if (img) GL.Disable(EnableCap.Blend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clean()
|
|
||||||
{
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
||||||
GL.DeleteBuffer(BufferObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
~RenderObject()
|
|
||||||
{
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
||||||
GL.DeleteBuffer(BufferObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
readonly bool img = false;
|
|
||||||
|
|
||||||
public Shader Shader { get; set; } = DefaultShader;
|
|
||||||
public int ElementBufferObject { get; }
|
|
||||||
public int BufferObject { get; }
|
|
||||||
public int ArrayObject { get; }
|
|
||||||
private float[] Points_;
|
|
||||||
public float[] Points
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Points_;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Points_ = value;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int add = 3;
|
|
||||||
if (img) add = 5;
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
|
||||||
GL.BindVertexArray(ArrayObject);
|
|
||||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, add * sizeof(float), 0);
|
|
||||||
GL.EnableVertexAttribArray(0);
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
|
||||||
GL.BufferData(BufferTarget.ArrayBuffer, Points_.Length * sizeof(float), Points_, Hint);
|
|
||||||
GL.BindVertexArray(ArrayObject);
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
|
||||||
GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(uint), Indexs, Hint);
|
|
||||||
}
|
|
||||||
catch (AccessViolationException v)
|
|
||||||
{
|
|
||||||
Console.WriteLine(v.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint[] Indexs { get; set; }
|
|
||||||
public BufferUsageHint Hint { get; set; } = BufferUsageHint.StaticDraw;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,295 +0,0 @@
|
|||||||
using OpenTK.Graphics.OpenGL4;
|
|
||||||
using OpenTK.Mathematics;
|
|
||||||
using SharpFont;
|
|
||||||
using System.Reflection;
|
|
||||||
using Encoding = SharpFont.Encoding;
|
|
||||||
|
|
||||||
namespace Updater;
|
|
||||||
|
|
||||||
internal class RenderText : IRenderObject
|
|
||||||
{
|
|
||||||
public static readonly Shader DefaultTextShader = new(@"#version 460
|
|
||||||
|
|
||||||
layout (location = 0) in vec2 in_pos;
|
|
||||||
layout (location = 1) in vec2 in_uv;
|
|
||||||
|
|
||||||
out vec2 vUV;
|
|
||||||
|
|
||||||
layout (location = 0) uniform mat4 model;
|
|
||||||
layout (location = 1) uniform mat4 projection;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
vUV = in_uv.xy;
|
|
||||||
gl_Position = projection * model * vec4(in_pos.xy, 0.0, 1.0);
|
|
||||||
}",
|
|
||||||
@"
|
|
||||||
#version 460
|
|
||||||
|
|
||||||
in vec2 vUV;
|
|
||||||
|
|
||||||
layout (binding=0) uniform sampler2D u_texture;
|
|
||||||
|
|
||||||
layout (location = 2) uniform vec4 textColor;
|
|
||||||
|
|
||||||
out vec4 fragColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
vec2 uv = vUV.xy;
|
|
||||||
float text = texture(u_texture, uv).r;
|
|
||||||
fragColor = vec4(textColor.rgba*text);
|
|
||||||
}");
|
|
||||||
|
|
||||||
public RenderText(string Text, string Font, uint PixelHeight, float x, float y, float scale, Vector2 dir, Vector4 col)
|
|
||||||
{
|
|
||||||
this.Text = Text;
|
|
||||||
this.PixelHeight = PixelHeight;
|
|
||||||
this.X = FloatToInt(x, 1);
|
|
||||||
this.Y = FloatToInt(y, 1, true);
|
|
||||||
this.Scale = scale;
|
|
||||||
this.DIR = dir;
|
|
||||||
this.Color = col;
|
|
||||||
this.Font = Font;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Library lib = new();
|
|
||||||
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
||||||
Stream? resource_stream = assembly.GetManifestResourceStream($"Updater.Resource.{Font}.ttf");
|
|
||||||
MemoryStream ms = new();
|
|
||||||
resource_stream?.CopyTo(ms);
|
|
||||||
Face face = new(lib, ms.ToArray(), 0);
|
|
||||||
face.SetPixelSizes(0, PixelHeight);
|
|
||||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
|
||||||
GL.ActiveTexture(TextureUnit.Texture0);
|
|
||||||
face.SelectCharmap(Encoding.Unicode);
|
|
||||||
|
|
||||||
for (uint c = 0; c < 0; c++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
face.LoadChar(c, LoadFlags.Render, LoadTarget.Normal);
|
|
||||||
GlyphSlot glyph = face.Glyph;
|
|
||||||
FTBitmap bitmap = glyph.Bitmap;
|
|
||||||
int texObj = GL.GenTexture();
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, texObj);
|
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
|
||||||
PixelInternalFormat.R8, bitmap.Width, bitmap.Rows, 0,
|
|
||||||
PixelFormat.Red, PixelType.UnsignedByte, bitmap.Buffer);
|
|
||||||
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
|
|
||||||
|
|
||||||
Character ch = new();
|
|
||||||
ch.TextureID = texObj;
|
|
||||||
ch.Size = new Vector2(bitmap.Width, bitmap.Rows);
|
|
||||||
ch.Bearing = new Vector2(glyph.BitmapLeft, glyph.BitmapTop);
|
|
||||||
ch.Advance = (int)glyph.Advance.X.Value;
|
|
||||||
if (!_characters.ContainsKey(this)) _characters.Add(this, new Dictionary<uint, Character>());
|
|
||||||
_characters[this].Add(c, ch);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
|
||||||
|
|
||||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4);
|
|
||||||
|
|
||||||
float[] vquad =
|
|
||||||
{
|
|
||||||
0.0f, -1.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, -1.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f, 0.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
VBO = GL.GenBuffer();
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VBO);
|
|
||||||
GL.BufferData(BufferTarget.ArrayBuffer, 4 * 6 * 4, vquad, BufferUsageHint.StaticDraw);
|
|
||||||
|
|
||||||
VAO = GL.GenVertexArray();
|
|
||||||
GL.BindVertexArray(VAO);
|
|
||||||
GL.EnableVertexAttribArray(0);
|
|
||||||
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * 4, 0);
|
|
||||||
GL.EnableVertexAttribArray(1);
|
|
||||||
GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * 4, 2 * 4);
|
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
||||||
GL.BindVertexArray(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public bool Visible { get; set; } = true;
|
|
||||||
|
|
||||||
public static readonly Dictionary<RenderText, Dictionary<uint, Character>> _characters = new();
|
|
||||||
|
|
||||||
public int VAO { get; set; }
|
|
||||||
public int VBO { get; set; }
|
|
||||||
public float X { get; set; }
|
|
||||||
public float Y { get; set; }
|
|
||||||
public Vector2 DIR { get; set; }
|
|
||||||
public string Text { get; set; }
|
|
||||||
public uint PixelHeight { get; set; }
|
|
||||||
public float Scale { get; set; }
|
|
||||||
public Shader Shader { get; } = DefaultTextShader;
|
|
||||||
private string Font { get; set; }
|
|
||||||
|
|
||||||
private Vector4 Color { get; set; }
|
|
||||||
|
|
||||||
public void Clean()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static float FloatToInt(float p, int Size, bool Invert = false)
|
|
||||||
{
|
|
||||||
double half = Math.Round((double)Size / (double)2, 15);
|
|
||||||
if (p == 0) return (int)half;
|
|
||||||
if (Invert)
|
|
||||||
{
|
|
||||||
if (p < 0)
|
|
||||||
{
|
|
||||||
p *= -1;
|
|
||||||
p++;
|
|
||||||
return float.Parse($"{(half * p)}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return float.Parse($"{half - (p * half)}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (p < 0)
|
|
||||||
{
|
|
||||||
p *= -1;
|
|
||||||
p++;
|
|
||||||
return float.Parse($"{Size - (half * p)}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return float.Parse($"{p * half + half}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw()
|
|
||||||
{
|
|
||||||
if (Visible)
|
|
||||||
{
|
|
||||||
Shader.Use();
|
|
||||||
GL.Enable(EnableCap.Blend);
|
|
||||||
GL.Uniform4(2, Color);
|
|
||||||
_ = Matrix4.CreateScale(new Vector3(1f / 1, 1f / 1, 1.0f));
|
|
||||||
Matrix4 projectionM = Matrix4.CreateOrthographicOffCenter(0.0f, 1, 1, 0.0f, -1.0f, 1.0f);
|
|
||||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
|
||||||
GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
|
||||||
GL.UniformMatrix4(1, false, ref projectionM);
|
|
||||||
GL.ActiveTexture(TextureUnit.Texture0);
|
|
||||||
GL.BindVertexArray(VAO);
|
|
||||||
|
|
||||||
float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X);
|
|
||||||
Matrix4 rotateM = Matrix4.CreateRotationZ(angle_rad);
|
|
||||||
Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(X, Y, 0f));
|
|
||||||
|
|
||||||
// Iterate through all characters
|
|
||||||
float char_x = 0.0f;
|
|
||||||
|
|
||||||
|
|
||||||
Library lib = new();
|
|
||||||
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
||||||
Stream? resource_stream = assembly.GetManifestResourceStream($"Updater.Resource.{Font}.ttf");
|
|
||||||
MemoryStream ms = new();
|
|
||||||
resource_stream?.CopyTo(ms);
|
|
||||||
Face face = new(lib, ms.ToArray(), 0);
|
|
||||||
|
|
||||||
face.SetPixelSizes(0, PixelHeight);
|
|
||||||
|
|
||||||
// set 1 byte pixel alignment
|
|
||||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
|
||||||
|
|
||||||
// set texture unit
|
|
||||||
GL.ActiveTexture(TextureUnit.Texture0);
|
|
||||||
face.SelectCharmap(Encoding.Unicode);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (char c in Text)
|
|
||||||
{
|
|
||||||
if (_characters.ContainsKey(this) == false || _characters[this].ContainsKey(c) == false)
|
|
||||||
{
|
|
||||||
var temp = ((ushort)c);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
face.LoadChar(temp, LoadFlags.Render, LoadTarget.Normal);
|
|
||||||
GlyphSlot glyph = face.Glyph;
|
|
||||||
FTBitmap bitmap = glyph.Bitmap;
|
|
||||||
|
|
||||||
int texObj = GL.GenTexture();
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, texObj);
|
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
|
||||||
PixelInternalFormat.R8, bitmap.Width, bitmap.Rows, 0,
|
|
||||||
PixelFormat.Red, PixelType.UnsignedByte, bitmap.Buffer);
|
|
||||||
|
|
||||||
// set texture parameters
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
|
|
||||||
GL.TextureParameter(texObj, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
|
|
||||||
|
|
||||||
// add character
|
|
||||||
Character cha = new();
|
|
||||||
cha.TextureID = texObj;
|
|
||||||
cha.Size = new Vector2(bitmap.Width, bitmap.Rows);
|
|
||||||
cha.Bearing = new Vector2(glyph.BitmapLeft, glyph.BitmapTop);
|
|
||||||
cha.Advance = (int)glyph.Advance.X.Value;
|
|
||||||
if (!_characters.ContainsKey(this)) _characters.Add(this, new Dictionary<uint, Character>());
|
|
||||||
_characters[this].Add(temp, cha);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Character ch = _characters[this][c];
|
|
||||||
|
|
||||||
float w = ch.Size.X * Scale;
|
|
||||||
float h = ch.Size.Y * Scale;
|
|
||||||
float xrel = char_x + ch.Bearing.X * Scale;
|
|
||||||
float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale;
|
|
||||||
|
|
||||||
// Now advance cursors for next glyph (note that advance is number of 1/64 pixels)
|
|
||||||
char_x += (ch.Advance >> 6) * Scale; // Bitshift by 6 to get value in pixels (2^6 = 64 (divide amount of 1/64th pixels by 64 to get amount of pixels))
|
|
||||||
|
|
||||||
Matrix4 scaleM = Matrix4.CreateScale(new Vector3(w, h, 1.0f));
|
|
||||||
Matrix4 transRelM = Matrix4.CreateTranslation(new Vector3(xrel, yrel, 0.0f));
|
|
||||||
|
|
||||||
Matrix4 modelM = scaleM * transRelM * rotateM * transOriginM; // OpenTK `*`-operator is reversed
|
|
||||||
GL.UniformMatrix4(0, false, ref modelM);
|
|
||||||
|
|
||||||
// Render glyph texture over quad
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, ch.TextureID);
|
|
||||||
|
|
||||||
// Render quad
|
|
||||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
GL.BindVertexArray(0);
|
|
||||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
|
||||||
GL.Disable(EnableCap.Blend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
BIN
Updater/Resource/Progress.png
Normal file
BIN
Updater/Resource/Progress.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
@ -1,82 +0,0 @@
|
|||||||
using OpenTK.Graphics.OpenGL4;
|
|
||||||
|
|
||||||
namespace Updater
|
|
||||||
{
|
|
||||||
public class Shader : IDisposable
|
|
||||||
{
|
|
||||||
public int Handle { get; }
|
|
||||||
private readonly int VertexShader;
|
|
||||||
private readonly int FragmentShader;
|
|
||||||
private bool disposedValue = false;
|
|
||||||
|
|
||||||
public Shader(string VertexShaderSource, string FragmentShaderSource)
|
|
||||||
{
|
|
||||||
VertexShader = GL.CreateShader(ShaderType.VertexShader);
|
|
||||||
GL.ShaderSource(VertexShader, VertexShaderSource);
|
|
||||||
|
|
||||||
FragmentShader = GL.CreateShader(ShaderType.FragmentShader);
|
|
||||||
GL.ShaderSource(FragmentShader, FragmentShaderSource);
|
|
||||||
|
|
||||||
GL.CompileShader(VertexShader);
|
|
||||||
|
|
||||||
string infoLogVert = GL.GetShaderInfoLog(VertexShader);
|
|
||||||
if (infoLogVert != string.Empty)
|
|
||||||
Console.WriteLine(infoLogVert);
|
|
||||||
|
|
||||||
GL.CompileShader(FragmentShader);
|
|
||||||
|
|
||||||
string infoLogFrag = GL.GetShaderInfoLog(FragmentShader);
|
|
||||||
|
|
||||||
if (infoLogFrag != string.Empty)
|
|
||||||
Console.WriteLine(infoLogFrag);
|
|
||||||
|
|
||||||
Handle = GL.CreateProgram();
|
|
||||||
|
|
||||||
GL.AttachShader(Handle, VertexShader);
|
|
||||||
GL.AttachShader(Handle, FragmentShader);
|
|
||||||
|
|
||||||
GL.LinkProgram(Handle);
|
|
||||||
|
|
||||||
GL.DetachShader(Handle, VertexShader);
|
|
||||||
GL.DetachShader(Handle, FragmentShader);
|
|
||||||
GL.DeleteShader(FragmentShader);
|
|
||||||
GL.DeleteShader(VertexShader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Use()
|
|
||||||
{
|
|
||||||
GL.UseProgram(Handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetAttribLocation(string attribName)
|
|
||||||
{
|
|
||||||
return GL.GetAttribLocation(Handle, attribName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Shader Clone()
|
|
||||||
{
|
|
||||||
return (Shader)MemberwiseClone();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (!disposedValue)
|
|
||||||
{
|
|
||||||
GL.DeleteProgram(Handle);
|
|
||||||
|
|
||||||
disposedValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~Shader()
|
|
||||||
{
|
|
||||||
GL.DeleteProgram(Handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user