I can't remember what's new
This commit is contained in:
parent
38e418e3c6
commit
1d3e319638
@ -10,7 +10,7 @@
|
||||
<IncludeSymbols>False</IncludeSymbols>
|
||||
<RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Version>1.0.0-alpha999991</Version>
|
||||
<Version>1.0.0-alpha99999991</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -13,6 +13,7 @@ public interface IParent
|
||||
public Vector3 PointToVector(float x, float y, float z = 0.0f);
|
||||
public float IntToFloat(float p, bool Invert = false);
|
||||
public void TryDraw();
|
||||
public void ReportSizeUpdate(IRenderObject Control);
|
||||
public float FloatToInt(float p, bool Invert = false);
|
||||
public event Action<MouseButtonEventArgs> MouseDown;
|
||||
public event Action<KeyboardKeyEventArgs> KeyDown;
|
||||
|
@ -12,14 +12,19 @@ public class ControlList
|
||||
|
||||
public int Length => _internal.Count;
|
||||
|
||||
internal event Func<IRenderObject, Task>? ControlAdded;
|
||||
internal event Func<Task>? ControlRemoved;
|
||||
|
||||
public void Remove(IRenderObject item)
|
||||
{
|
||||
_internal.Remove(item);
|
||||
item.Clean();
|
||||
if (ControlRemoved is not null) _ = ControlRemoved.Invoke();
|
||||
}
|
||||
|
||||
public void Add(IRenderObject item)
|
||||
{
|
||||
if (ControlAdded is not null) ControlAdded.Invoke(item).Wait();
|
||||
_internal.Add(item);
|
||||
}
|
||||
|
||||
@ -30,5 +35,6 @@ public class ControlList
|
||||
con.Clean();
|
||||
}
|
||||
_internal.Clear();
|
||||
if (ControlRemoved is not null) _ = ControlRemoved.Invoke();
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ using System.Timers;
|
||||
using GraphicsManager.Enums;
|
||||
using GraphicsManager.Interfaces;
|
||||
using GraphicsManager.Objects.Core;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Mathematics;
|
||||
using OpenTK.Windowing.Common;
|
||||
using Timer = System.Timers.Timer;
|
||||
@ -20,6 +21,58 @@ public class FlowLayout : IRenderObject, IParent
|
||||
t.Enabled = true;
|
||||
t.Elapsed += TOnElapsed;
|
||||
t.Start();
|
||||
Controls.ControlAdded += ControlsOnControlAdded;
|
||||
Controls.ControlRemoved += ControlsOnControlRemoved;
|
||||
}
|
||||
|
||||
public void ReportSizeUpdate(IRenderObject Control)
|
||||
{
|
||||
if (isrole) return;
|
||||
isrole = true;
|
||||
bool notfount = true;
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
if (Controls[i] != Control && notfount) continue;
|
||||
else
|
||||
{
|
||||
if (notfount)
|
||||
{
|
||||
notfount = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
Controls[i].Location = new(0, Controls[i - 1].Location.Y + Controls[i - 1].Size.Y);
|
||||
}
|
||||
}
|
||||
|
||||
lasty = Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y;
|
||||
isrole = false;
|
||||
}
|
||||
|
||||
private Task ControlsOnControlRemoved()
|
||||
{
|
||||
Console.WriteLine("reset");
|
||||
lasty = 0;
|
||||
Controls[0].Location = new(0, 0);
|
||||
lasty += Controls[0].Size.Y;
|
||||
for (int i = 1; i < Controls.Length; i++)
|
||||
{
|
||||
lasty += Controls[i].Size.Y;
|
||||
Controls[i].Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private int lasty = 0;
|
||||
private Task ControlsOnControlAdded(IRenderObject arg)
|
||||
{
|
||||
|
||||
if (Controls.Length > 0) arg.Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y);
|
||||
else arg.Location = new(0, 0);
|
||||
lasty += arg.Size.Y;
|
||||
arg.Size = new(Size.X, arg.Size.Y);
|
||||
arg.Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task _bounds_Clicked(IRenderObject arg)
|
||||
@ -48,9 +101,33 @@ public class FlowLayout : IRenderObject, IParent
|
||||
}
|
||||
}
|
||||
public bool Visible { get => _bounds.Visible; set => _bounds.Visible = value; }
|
||||
public Vector2i Size { get => _bounds.Size; set => _bounds.Size = value; }
|
||||
public Vector2i Size
|
||||
{
|
||||
get => _bounds.Size;
|
||||
set
|
||||
{
|
||||
_bounds.Size = value;
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].Size = Controls[i].Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
|
||||
public Vector2i Location { get => _bounds.Location; set => _bounds.Location = value; }
|
||||
public Vector2i Location
|
||||
{
|
||||
get => _bounds.Location;
|
||||
set
|
||||
{
|
||||
_bounds.Location = value;
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].Location = Controls[i].Location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2i Position => Location;
|
||||
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
|
||||
public Vector2i Distance { get => _bounds.Distance; }
|
||||
@ -72,12 +149,14 @@ public class FlowLayout : IRenderObject, IParent
|
||||
if (Loaded) return;
|
||||
this.Parent = Parent;
|
||||
this.Window = Window;
|
||||
isrole = true;
|
||||
Loaded = true;
|
||||
_bounds.LoadToParent(Parent, Window);
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].LoadToParent(this, Window);
|
||||
}
|
||||
isrole = false;
|
||||
Window.MouseWheel += WindowOnMouseWheel;
|
||||
if (WindowLoaded is not null) WindowLoaded.Invoke(this);
|
||||
}
|
||||
@ -122,11 +201,29 @@ public class FlowLayout : IRenderObject, IParent
|
||||
{
|
||||
scrols.Enqueue(new Action(() =>
|
||||
{
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
if (Controls.Length < 1) return;
|
||||
bool down = dis.OffsetY < 0;//scrole wheel dir
|
||||
if (down && ((Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y) > Size.Y)) //can go down
|
||||
{
|
||||
Controls[i].Location = new((int)(Controls[i].Location.X),
|
||||
(int)(Controls[i].Location.Y - (dis.OffsetY * HScrollPixels)));
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].Location = new((int)(Controls[i].Location.X),
|
||||
(int)(Controls[i].Location.Y - (dis.OffsetY * HScrollPixels)));
|
||||
}
|
||||
}
|
||||
if (!down && (Controls[0].Location.Y < 0)) // can go up
|
||||
{
|
||||
float newy = Controls[0].Location.Y - (dis.OffsetY * HScrollPixels);
|
||||
if (newy > 0) newy = 0;
|
||||
Controls[0].Location = new(0, (int)newy);
|
||||
for (int i = 1; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].Location = new(0,
|
||||
(int)(Controls[i - 1].Location.Y + Controls[i - 1].Size.Y));
|
||||
}
|
||||
}
|
||||
|
||||
lasty = Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y;
|
||||
}));
|
||||
}
|
||||
|
||||
@ -171,6 +268,7 @@ public class FlowLayout : IRenderObject, IParent
|
||||
public void ParentResize(ResizeEventArgs e)
|
||||
{
|
||||
if (e.Width == 0 && e.Height == 0) return;
|
||||
isrole = true;
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
if (!Controls[i].Loaded) continue;
|
||||
@ -191,6 +289,8 @@ public class FlowLayout : IRenderObject, IParent
|
||||
parent.ParentResize(e);
|
||||
}
|
||||
}
|
||||
Parent!.TryDraw();
|
||||
isrole = false;
|
||||
}
|
||||
|
||||
#region Cool Math Things
|
||||
|
@ -19,7 +19,16 @@ public class Label : IRenderObject
|
||||
|
||||
public Vector2 LocationAsFloat { get { return laf; } }
|
||||
public Vector2 SizeAsFloat { get { return saf; } }
|
||||
public bool Visible { get; set; } = true;
|
||||
private bool _Visible = true;
|
||||
public bool Visible
|
||||
{
|
||||
get => _Visible;
|
||||
set
|
||||
{
|
||||
_Visible = value;
|
||||
if (Parent is not null) Parent.TryDraw();
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly Dictionary<Font, Dictionary<uint, Character>> _characters = new();
|
||||
private string text = string.Empty;
|
||||
@ -32,31 +41,31 @@ public class Label : IRenderObject
|
||||
set
|
||||
{
|
||||
text = value;
|
||||
if (!_characters.ContainsKey(Font)) _characters.Add(Font, new Dictionary<uint, Character>());
|
||||
float addy = Font.PixelHeight * Scale, addx = 0F, char_x = 0F, hhh = 0F;
|
||||
foreach (char character in value)
|
||||
{
|
||||
if (!_characters[Font].ContainsKey(character))
|
||||
{
|
||||
var f = Texture.TextureForChar(Font, character, Font.Faces.ToArray());
|
||||
f.LoadText();
|
||||
}
|
||||
float w = _characters[Font][character].Size.X * Scale;
|
||||
float xrel = char_x + _characters[Font][character].Bearing.X * Scale;
|
||||
if (character == '\n')
|
||||
{
|
||||
hhh += Font.PixelHeight;
|
||||
char_x = 0f;
|
||||
addy += Font.PixelHeight * Scale;
|
||||
}
|
||||
char_x += (_characters[Font][character].Advance >> 6) * Scale;
|
||||
if (xrel + w > addx) addx = xrel + w;
|
||||
}
|
||||
|
||||
Size = new((int)addx, (int)addy);
|
||||
if (Loaded)
|
||||
{
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
if (!_characters.ContainsKey(Font)) _characters.Add(Font, new Dictionary<uint, Character>());
|
||||
float addy = Font.PixelHeight * Scale, addx = 0F, char_x = 0F, hhh = 0F;
|
||||
foreach (char character in value)
|
||||
{
|
||||
if (!_characters[Font].ContainsKey(character))
|
||||
{
|
||||
var f = Texture.TextureForChar(Font, character, Font.Faces.ToArray());
|
||||
f.LoadText();
|
||||
}
|
||||
float w = _characters[Font][character].Size.X * Scale;
|
||||
float xrel = char_x + _characters[Font][character].Bearing.X * Scale;
|
||||
if (character == '\n')
|
||||
{
|
||||
hhh += Font.PixelHeight;
|
||||
char_x = 0f;
|
||||
addy += Font.PixelHeight * Scale;
|
||||
}
|
||||
char_x += (_characters[Font][character].Advance >> 6) * Scale;
|
||||
if (xrel + w > addx) addx = xrel + w;
|
||||
}
|
||||
|
||||
Size = new((int)addx, (int)addy);
|
||||
if (Window is not null && Window.CanControleUpdate && Loaded) Parent!.TryDraw();
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,17 @@ public class Rectangle : ITextureObject
|
||||
|
||||
public Uniforms Uniforms { get; } = new() { Uniform4 = new() { new() { Location = 0, Value = new(0,0,0,1) } } };
|
||||
|
||||
public bool Visible { get; set; } = true;
|
||||
//public bool Visible { get; set; } = true;
|
||||
private bool _Visible = true;
|
||||
public bool Visible
|
||||
{
|
||||
get => _Visible;
|
||||
set
|
||||
{
|
||||
_Visible = value;
|
||||
if (Parent is not null) Parent.TryDraw();
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
@ -157,6 +167,7 @@ public class Rectangle : ITextureObject
|
||||
{
|
||||
if (Loaded)
|
||||
{
|
||||
Distance = new(Parent!.Size.X - Size.X - Location.X, Parent.Size.Y - Size.Y - Location.Y);
|
||||
int add = 3;
|
||||
if (Texture is not null) add = 5;
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
||||
@ -201,6 +212,7 @@ public class Rectangle : ITextureObject
|
||||
{
|
||||
size_ = value;
|
||||
if (Window is null || Parent is null) return;
|
||||
Parent.ReportSizeUpdate(this);
|
||||
float[] temp = Points;
|
||||
saf = new Vector2(Parent.IntToFloat(value.X + loc_.X, false), Parent.IntToFloat(value.Y + loc_.Y, true));
|
||||
temp[0] = saf.X;
|
||||
|
@ -91,7 +91,11 @@ public class RoundedButton : IRenderObject
|
||||
_bounds.Uniforms.Uniform4.Add(u4);
|
||||
}
|
||||
}
|
||||
public bool Visible { get; set; } = true;
|
||||
public bool Visible
|
||||
{
|
||||
get => _bounds.Visible;
|
||||
set => _bounds.Visible = value;
|
||||
}
|
||||
public event Func<IRenderObject, Task>? Clicked;
|
||||
|
||||
public void Clean()
|
||||
|
@ -89,7 +89,16 @@ public class RoundedRectangle : IRenderObject
|
||||
}
|
||||
}
|
||||
|
||||
public bool Visible { get; set; } = true;
|
||||
private bool _Visible = true;
|
||||
public bool Visible
|
||||
{
|
||||
get => _Visible;
|
||||
set
|
||||
{
|
||||
_Visible = value;
|
||||
if (Parent is not null) Parent.TryDraw();
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
@ -196,6 +205,7 @@ public class RoundedRectangle : IRenderObject
|
||||
{
|
||||
if (Loaded)
|
||||
{
|
||||
Distance = new(Parent!.Size.X - Size.X - Location.X, Parent.Size.Y - Size.Y - Location.Y);
|
||||
int add = 3;
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
|
||||
GL.BindVertexArray(ArrayObject);
|
||||
@ -254,6 +264,7 @@ public class RoundedRectangle : IRenderObject
|
||||
{
|
||||
size_ = value;
|
||||
if (Window is null || Parent is null) return;
|
||||
Parent.ReportSizeUpdate(this);
|
||||
Location = Location;
|
||||
saf = new Vector2(Parent.IntToFloat(value.X + loc_.X, false), Parent.IntToFloat(value.Y + loc_.Y, true));
|
||||
}
|
||||
|
@ -90,7 +90,11 @@ public class Textbox : IRenderObject
|
||||
_bounds.Uniforms.Uniform4.Add(u4);
|
||||
}
|
||||
}
|
||||
public bool Visible { get; set; } = true;
|
||||
public bool Visible
|
||||
{
|
||||
get => _bounds.Visible;
|
||||
set => _bounds.Visible = value;
|
||||
}
|
||||
public event Func<IRenderObject, Task>? Clicked;
|
||||
|
||||
public void Clean()
|
||||
|
@ -18,7 +18,7 @@ public class UserControl : IRenderObject, IParent
|
||||
|
||||
public void TryDraw()
|
||||
{
|
||||
Parent!.TryDraw();
|
||||
if (!res && Parent is not null) Parent.TryDraw();
|
||||
}
|
||||
|
||||
private Task _bounds_Clicked(IRenderObject arg)
|
||||
@ -47,9 +47,39 @@ public class UserControl : IRenderObject, IParent
|
||||
}
|
||||
}
|
||||
public bool Visible { get => _bounds.Visible; set => _bounds.Visible = value; }
|
||||
public Vector2i Size { get => _bounds.Size; set => _bounds.Size = value; }
|
||||
private bool res = false;
|
||||
public Vector2i Size
|
||||
{
|
||||
get => _bounds.Size;
|
||||
set
|
||||
{
|
||||
_bounds.Size = value;
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].Size = Controls[i].Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReportSizeUpdate(IRenderObject Control)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
|
||||
public Vector2i Location { get => _bounds.Location; set => _bounds.Location = value; }
|
||||
public Vector2i Location
|
||||
{
|
||||
get => _bounds.Location;
|
||||
set
|
||||
{
|
||||
_bounds.Location = value;
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].Location = Controls[i].Location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2i Position => Location;
|
||||
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
|
||||
public Vector2i Distance { get => _bounds.Distance; }
|
||||
@ -71,12 +101,15 @@ public class UserControl : IRenderObject, IParent
|
||||
if (Loaded) return;
|
||||
this.Parent = Parent;
|
||||
this.Window = Window;
|
||||
res = true;
|
||||
Loaded = true;
|
||||
_bounds.LoadToParent(Parent, Window);
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
Controls[i].LoadToParent(this, Window);
|
||||
}
|
||||
|
||||
res = false;
|
||||
if (WindowLoaded is not null) WindowLoaded.Invoke(this);
|
||||
}
|
||||
|
||||
@ -112,6 +145,7 @@ public class UserControl : IRenderObject, IParent
|
||||
|
||||
public void ParentResize(ResizeEventArgs e)
|
||||
{
|
||||
res = true;
|
||||
if (e.Width == 0 && e.Height == 0) return;
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
@ -133,6 +167,8 @@ public class UserControl : IRenderObject, IParent
|
||||
parent.ParentResize(e);
|
||||
}
|
||||
}
|
||||
Parent!.TryDraw();
|
||||
res = false;
|
||||
}
|
||||
|
||||
#region Cool Math Things
|
||||
|
@ -118,6 +118,7 @@ public class Window : NativeWindow , IParent
|
||||
public void ParentResize(ResizeEventArgs e)
|
||||
{
|
||||
if (e.Width == 0 && e.Height == 0) return;
|
||||
res = true;
|
||||
base.OnResize(e);
|
||||
GL.Viewport(0, 0, e.Width, e.Height);
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
@ -140,6 +141,15 @@ public class Window : NativeWindow , IParent
|
||||
parent.ParentResize(e);
|
||||
}
|
||||
}
|
||||
DrawFrame();
|
||||
res = false;
|
||||
}
|
||||
|
||||
private int frame = 0;
|
||||
|
||||
public void ReportSizeUpdate(IRenderObject Control)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnResize(ResizeEventArgs e)
|
||||
@ -179,24 +189,28 @@ public class Window : NativeWindow , IParent
|
||||
}
|
||||
}
|
||||
|
||||
private bool res = false;
|
||||
public void TryDraw()
|
||||
{
|
||||
DrawFrame();
|
||||
if (!res) DrawFrame();
|
||||
}
|
||||
|
||||
public void DrawFrame()
|
||||
{
|
||||
frame++;
|
||||
Console.WriteLine($"Drawing Frame: {frame}");
|
||||
GL.ClearColor(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, (BackgroundColor.A * -1) + 1);
|
||||
IEnumerable<IRenderObject> needload = Controls.Where(a => a.Loaded == false);
|
||||
|
||||
if (needload.Any())
|
||||
{
|
||||
res = true;
|
||||
foreach (IRenderObject obj in needload)
|
||||
{
|
||||
obj.LoadToParent(this, this);
|
||||
}
|
||||
res = false;
|
||||
}
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
for (int i = 0; i < Controls.Length; i++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user