diff --git a/GraphicsManager/GraphicsManager.csproj b/GraphicsManager/GraphicsManager.csproj
index 3f37cf3..2fcac57 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-alpha999991
+ 1.0.0-alpha99999991
diff --git a/GraphicsManager/Interfaces/IParent.cs b/GraphicsManager/Interfaces/IParent.cs
index 062ea74..cac7e48 100755
--- a/GraphicsManager/Interfaces/IParent.cs
+++ b/GraphicsManager/Interfaces/IParent.cs
@@ -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 MouseDown;
public event Action KeyDown;
diff --git a/GraphicsManager/Objects/Core/ControlList.cs b/GraphicsManager/Objects/Core/ControlList.cs
index e760ada..d0385c3 100644
--- a/GraphicsManager/Objects/Core/ControlList.cs
+++ b/GraphicsManager/Objects/Core/ControlList.cs
@@ -12,14 +12,19 @@ public class ControlList
public int Length => _internal.Count;
+ internal event Func? ControlAdded;
+ internal event Func? 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();
}
}
\ No newline at end of file
diff --git a/GraphicsManager/Objects/FlowLayout.cs b/GraphicsManager/Objects/FlowLayout.cs
index 88c53d8..4a64dc9 100644
--- a/GraphicsManager/Objects/FlowLayout.cs
+++ b/GraphicsManager/Objects/FlowLayout.cs
@@ -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
diff --git a/GraphicsManager/Objects/Label.cs b/GraphicsManager/Objects/Label.cs
index 797f0d3..59d7f64 100755
--- a/GraphicsManager/Objects/Label.cs
+++ b/GraphicsManager/Objects/Label.cs
@@ -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> _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());
+ 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());
- 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();
}
}
diff --git a/GraphicsManager/Objects/Rectangle.cs b/GraphicsManager/Objects/Rectangle.cs
index 4319bb6..2fffa5f 100755
--- a/GraphicsManager/Objects/Rectangle.cs
+++ b/GraphicsManager/Objects/Rectangle.cs
@@ -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);
@@ -190,7 +201,7 @@ public class Rectangle : ITextureObject
public event Func? MouseLeave;
public object? Tag { get; set; } = null;
public Vector2i Distance { get; private set; }
-
+
public Vector2i Size
{
get
@@ -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;
diff --git a/GraphicsManager/Objects/RoundedButton.cs b/GraphicsManager/Objects/RoundedButton.cs
index 3de1545..35e8a29 100755
--- a/GraphicsManager/Objects/RoundedButton.cs
+++ b/GraphicsManager/Objects/RoundedButton.cs
@@ -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? Clicked;
public void Clean()
diff --git a/GraphicsManager/Objects/RoundedRectangle.cs b/GraphicsManager/Objects/RoundedRectangle.cs
index 6f9d1e9..e5998ad 100755
--- a/GraphicsManager/Objects/RoundedRectangle.cs
+++ b/GraphicsManager/Objects/RoundedRectangle.cs
@@ -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));
}
diff --git a/GraphicsManager/Objects/Textbox.cs b/GraphicsManager/Objects/Textbox.cs
index a0d4578..3983f3e 100755
--- a/GraphicsManager/Objects/Textbox.cs
+++ b/GraphicsManager/Objects/Textbox.cs
@@ -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? Clicked;
public void Clean()
diff --git a/GraphicsManager/Objects/UserControl.cs b/GraphicsManager/Objects/UserControl.cs
index 1eec56a..1f940ed 100755
--- a/GraphicsManager/Objects/UserControl.cs
+++ b/GraphicsManager/Objects/UserControl.cs
@@ -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
diff --git a/GraphicsManager/Window.cs b/GraphicsManager/Window.cs
index f573459..792040f 100755
--- a/GraphicsManager/Window.cs
+++ b/GraphicsManager/Window.cs
@@ -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)
@@ -178,25 +188,29 @@ public class Window : NativeWindow , IParent
Thread.Sleep(8);
}
}
-
+
+ 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 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++)
{