This commit is contained in:
JacobTech 2023-01-06 22:32:41 -05:00
parent cd290e6fd0
commit 7d32666095
11 changed files with 270 additions and 62 deletions

View File

@ -10,7 +10,7 @@
<IncludeSymbols>False</IncludeSymbols> <IncludeSymbols>False</IncludeSymbols>
<RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl> <RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<Version>1.0.0-alpha99999999999999996</Version> <Version>1.0.0-beta1</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -11,6 +11,8 @@ public interface IRenderObject
public void LoadToParent(IParent Parent, Window Window); public void LoadToParent(IParent Parent, Window Window);
public void Draw(); public void Draw();
public void Clean(); public void Clean();
public void Focus();
public void UnFocus();
public Vector2i Size { get; set; } public Vector2i Size { get; set; }
public Vector2i Location { get; set; } public Vector2i Location { get; set; }
public Vector2 SizeAsFloat { get; } public Vector2 SizeAsFloat { get; }

View File

@ -29,8 +29,8 @@ public class FlowLayout : IRenderObject, IParent
public void ReportSizeUpdate(IRenderObject Control) public void ReportSizeUpdate(IRenderObject Control)
{ {
if (isrole) return; if (BlockDraw) return;
isrole = true; BlockDraw = true;
bool notfount = true; bool notfount = true;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
@ -47,7 +47,7 @@ public class FlowLayout : IRenderObject, IParent
} }
} }
isrole = false; BlockDraw = false;
} }
private Task ControlsOnControlRemoved() private Task ControlsOnControlRemoved()
@ -63,7 +63,6 @@ public class FlowLayout : IRenderObject, IParent
private Task ControlsOnControlAdded(IRenderObject arg) 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); 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); else arg.Location = new(0, 0);
arg.Size = new(Size.X, arg.Size.Y); arg.Size = new(Size.X, arg.Size.Y);
@ -94,37 +93,65 @@ public class FlowLayout : IRenderObject, IParent
public ControlList Controls { get; } = new(); public ControlList Controls { get; } = new();
public ObjectAnchor Anchor { get => _bounds.Anchor; set => _bounds.Anchor = value; } public ObjectAnchor Anchor { get => _bounds.Anchor; set => _bounds.Anchor = value; }
public Color4 BackgroundColor { get => _bounds.BackgroundColor; set => _bounds.BackgroundColor = value; } public Color4 BackgroundColor { get => _bounds.BackgroundColor; set => _bounds.BackgroundColor = value; }
public bool Visible { get => _bounds.Visible; set => _bounds.Visible = value; } public bool Visible
{
get => _bounds.Visible;
set
{
BlockDraw = true;
_bounds.Visible = value;
for (int i = 0; i < Controls.Length; i++)
Controls[i].Visible = value;
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
}
}
public Vector2i Size public Vector2i Size
{ {
get => _bounds.Size; get => _bounds.Size;
set set
{ {
BlockDraw = true;
_bounds.Size = value; _bounds.Size = value;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
Controls[i].Size = Controls[i].Size; Controls[i].Size = new(value.X, Controls[i].Size.Y);
} }
ParentResize(new());
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
} }
} }
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; } public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
public void Focus()
{
}
public void UnFocus()
{
}
public Vector2i Location public Vector2i Location
{ {
get => _bounds.Location; get => _bounds.Location;
set set
{ {
BlockDraw = true;
_bounds.Location = value; _bounds.Location = value;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
Controls[i].Location = Controls[i].Location; Controls[i].Location = Controls[i].Location;
} }
ParentResize(new());
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
} }
} }
public Vector2i Position => Location; public Vector2i Position => Location;
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; } public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
public Vector2i Distance { get => _bounds.Distance; } public Vector2i Distance { get => _bounds.Distance; internal set => _bounds.Distance = value; }
public event Func<IRenderObject, Task>? Clicked; public event Func<IRenderObject, Task>? Clicked;
public event Action<MouseButtonEventArgs> MouseDown; public event Action<MouseButtonEventArgs> MouseDown;
public event Action<KeyboardKeyEventArgs> KeyDown; public event Action<KeyboardKeyEventArgs> KeyDown;
@ -143,19 +170,19 @@ public class FlowLayout : IRenderObject, IParent
if (Loaded) return; if (Loaded) return;
this.Parent = Parent; this.Parent = Parent;
this.Window = Window; this.Window = Window;
isrole = true; BlockDraw = true;
Loaded = true; Loaded = true;
_bounds.LoadToParent(Parent, Window); _bounds.LoadToParent(Parent, Window);
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
Controls[i].LoadToParent(this, Window); Controls[i].LoadToParent(this, Window);
} }
isrole = false; BlockDraw = false;
Window.MouseWheel += WindowOnMouseWheel; Window.MouseWheel += WindowOnMouseWheel;
if (WindowLoaded is not null) WindowLoaded.Invoke(this); if (WindowLoaded is not null) WindowLoaded.Invoke(this);
} }
private bool isrole = false; public bool BlockDraw { get; set; } = false;
private MouseWheelEventArgs dis; private MouseWheelEventArgs dis;
Timer t; Timer t;
private Queue<Action> scrols = new(); private Queue<Action> scrols = new();
@ -163,14 +190,14 @@ public class FlowLayout : IRenderObject, IParent
public void TryDraw() public void TryDraw()
{ {
if (!isrole) Parent!.TryDraw(); if (!BlockDraw) Parent!.TryDraw();
} }
private void WindowOnMouseWheel(MouseWheelEventArgs obj) private void WindowOnMouseWheel(MouseWheelEventArgs obj)
{ {
try try
{ {
if (!inside) return; if (!inside) return;
isrole = true; BlockDraw = true;
dis = obj; dis = obj;
if (scrols.Any()) if (scrols.Any())
{ {
@ -193,7 +220,7 @@ public class FlowLayout : IRenderObject, IParent
{ {
try try
{ {
if (isrole) if (BlockDraw)
{ {
scrols.Enqueue(new Action(() => scrols.Enqueue(new Action(() =>
{ {
@ -229,7 +256,7 @@ public class FlowLayout : IRenderObject, IParent
})); }));
} }
isrole = false; BlockDraw = false;
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -270,7 +297,7 @@ public class FlowLayout : IRenderObject, IParent
public void ParentResize(ResizeEventArgs e) public void ParentResize(ResizeEventArgs e)
{ {
if (e.Width == 0 && e.Height == 0) return; if (e.Width == 0 && e.Height == 0) return;
isrole = true; BlockDraw = true;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
if (!Controls[i].Loaded) continue; if (!Controls[i].Loaded) continue;
@ -292,7 +319,7 @@ public class FlowLayout : IRenderObject, IParent
} }
} }
Parent!.TryDraw(); Parent!.TryDraw();
isrole = false; BlockDraw = false;
} }
#region Cool Math Things #region Cool Math Things

View File

@ -48,6 +48,15 @@ public class Label : IRenderObject
public static readonly Dictionary<IGLFWGraphicsContext, Dictionary<Font, Dictionary<uint, Character>>> _characters = new(); public static readonly Dictionary<IGLFWGraphicsContext, Dictionary<Font, Dictionary<uint, Character>>> _characters = new();
private string text = string.Empty; private string text = string.Empty;
public int VAO { get; private set; } public int VAO { get; private set; }
public void Focus()
{
}
public void UnFocus()
{
}
public int VBO { get; private set; } public int VBO { get; private set; }
public Vector2 DIR { get; set; } = new Vector2(1f, 0f); public Vector2 DIR { get; set; } = new Vector2(1f, 0f);
public string Text public string Text
@ -83,7 +92,7 @@ public class Label : IRenderObject
if (Loaded) if (Loaded)
{ {
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
if (Window is not null && Window.CanControleUpdate && Loaded) Parent!.TryDraw(); if (Window is not null && Window.CanControleUpdate) Parent!.TryDraw();
} }
} }
} }
@ -91,7 +100,7 @@ public class Label : IRenderObject
public Font Font { get; set; } = DefaultFont; public Font Font { get; set; } = DefaultFont;
public float Scale { get; set; } = 1.0f; public float Scale { get; set; } = 1.0f;
public Color4 Color { get; set; } = new Color4(255, 255, 255, 255); public Color4 Color { get; set; } = new Color4(255, 255, 255, 255);
public Vector2i Distance { get; private set; } public Vector2i Distance { get; internal set; }
private Vector2i loc_ = new(); private Vector2i loc_ = new();
public Vector2i Location public Vector2i Location
{ {
@ -234,7 +243,8 @@ public class Label : IRenderObject
private bool mouseinside = false; private bool mouseinside = false;
private void WindowOnMouseMove(MouseMoveEventArgs obj) private void WindowOnMouseMove(MouseMoveEventArgs obj)
{ {
if (Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) && if (Visible &&
Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) && Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Window?.MousePosition.Y!, true) && Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Window?.MousePosition.Y!, true) &&
Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true)) Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true))

View File

@ -17,6 +17,7 @@ public class Rectangle : ITextureObject
public Texture? Texture { get; private set; } public Texture? Texture { get; private set; }
public ContextMenu? ContextMenu { get; set; } = null; public ContextMenu? ContextMenu { get; set; } = null;
public event Func<string[], Task>? FilesDroped;
public Rectangle(Texture? texture = null) public Rectangle(Texture? texture = null)
{ {
@ -34,8 +35,26 @@ public class Rectangle : ITextureObject
} }
} }
} }
public void Focus()
{
public Color4 BackgroundColor { get; set; } = new(0, 0, 0, 255); }
public void UnFocus()
{
}
public Color4 _BackgroundColor { get; set; } = new(0, 0, 0, 255);
public Color4 BackgroundColor
{
get => _BackgroundColor;
set
{
_BackgroundColor = value;
if (Parent is not null) Parent.TryDraw();
}
}
private bool _Visible = true; private bool _Visible = true;
public bool Visible public bool Visible
@ -108,15 +127,23 @@ public class Rectangle : ITextureObject
Loaded = true; Loaded = true;
Window.MouseDown += Window_MouseDown; Window.MouseDown += Window_MouseDown;
Window.MouseMove += WindowOnMouseMove; Window.MouseMove += WindowOnMouseMove;
Window.FileDrop += WindowOnFileDrop;
Location = Location; Location = Location;
Distance = new(Parent.Size.X - Size.X - Location.X, Parent.Size.Y - Size.Y - Location.Y); Distance = new(Parent.Size.X - Size.X - Location.X, Parent.Size.Y - Size.Y - Location.Y);
if (WindowLoaded is not null) WindowLoaded.Invoke(this); if (WindowLoaded is not null) WindowLoaded.Invoke(this);
} }
private void WindowOnFileDrop(FileDropEventArgs obj)
{
if (!mouseinside) return;
if (FilesDroped is not null) _ = FilesDroped.Invoke(obj.FileNames);
}
private bool mouseinside = false; private bool mouseinside = false;
private void WindowOnMouseMove(MouseMoveEventArgs e) private void WindowOnMouseMove(MouseMoveEventArgs e)
{ {
if (Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) && if (Visible &&
Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) && Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Window?.MousePosition.Y!, true) && Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Window?.MousePosition.Y!, true) &&
Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true)) Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true))
@ -202,7 +229,7 @@ public class Rectangle : ITextureObject
public event Func<IRenderObject, Task>? MouseEnter; public event Func<IRenderObject, Task>? MouseEnter;
public event Func<IRenderObject, Task>? MouseLeave; public event Func<IRenderObject, Task>? MouseLeave;
public object? Tag { get; set; } = null; public object? Tag { get; set; } = null;
public Vector2i Distance { get; private set; } public Vector2i Distance { get; internal set; }
public Vector2i Size public Vector2i Size
{ {

View File

@ -75,7 +75,7 @@ public class RoundedButton : IRenderObject
} }
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; } public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; } public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
public Vector2i Distance { get => _bounds.Distance; } public Vector2i Distance { get => _bounds.Distance; internal set => _bounds.Distance = value;}
public IParent? Parent { get; private set; } = null; public IParent? Parent { get; private set; } = null;
public Window? Window { get; private set; } = null; public Window? Window { get; private set; } = null;
public Color4 InsideColor { get => _inside.BackgroundColor; set => _inside.BackgroundColor = value; } public Color4 InsideColor { get => _inside.BackgroundColor; set => _inside.BackgroundColor = value; }
@ -84,7 +84,20 @@ public class RoundedButton : IRenderObject
public bool Visible public bool Visible
{ {
get => _bounds.Visible; get => _bounds.Visible;
set => _bounds.Visible = value; set
{
_bounds.Visible = value;
_inside.Visible = value;
_label.Visible = value;
}
}
public void Focus()
{
}
public void UnFocus()
{
} }
public event Func<IRenderObject, Task>? Clicked; public event Func<IRenderObject, Task>? Clicked;

View File

@ -25,7 +25,17 @@ public class RoundedRectangle : IRenderObject
public event Func<IRenderObject, Task>? MouseLeave; public event Func<IRenderObject, Task>? MouseLeave;
public object? Tag { get; set; } = null; public object? Tag { get; set; } = null;
public Color4 BackgroundColor { get; set; } = new(0, 0, 0, 255); public Color4 _BackgroundColor { get; set; } = new(0, 0, 0, 255);
public Color4 BackgroundColor
{
get => _BackgroundColor;
set
{
_BackgroundColor = value;
if (Parent is not null) Parent.TryDraw();
}
}
public int Radius public int Radius
{ {
get get
@ -156,9 +166,18 @@ public class RoundedRectangle : IRenderObject
} }
private bool mouseinside = false; private bool mouseinside = false;
public void Focus()
{
}
public void UnFocus()
{
}
private void WindowOnMouseMove(MouseMoveEventArgs obj) private void WindowOnMouseMove(MouseMoveEventArgs obj)
{ {
if (Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) && if (Visible &&
Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) && Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Window?.MousePosition.Y!, true) && Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Window?.MousePosition.Y!, true) &&
Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true)) Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true))
@ -256,7 +275,7 @@ public class RoundedRectangle : IRenderObject
public event Func<IRenderObject, Task>? Clicked; public event Func<IRenderObject, Task>? Clicked;
public bool Loaded { get; private set; } = false; public bool Loaded { get; private set; } = false;
public Vector2i Distance { get; private set; } public Vector2i Distance { get; internal set; }
public Vector2i Size public Vector2i Size
{ {

View File

@ -68,7 +68,8 @@ public class TabControl : IRenderObject, IParent
Tag = loc, Tag = loc,
BorderColor = this.BorderColor, BorderColor = this.BorderColor,
InsideColor = this.InsideColor, InsideColor = this.InsideColor,
FontColor = this.TextColor FontColor = this.TextColor,
Anchor = ObjectAnchor.Top | ObjectAnchor.Left
}); });
if (loc == PageIndex) tmp.BorderColor = this.SelectedColor; if (loc == PageIndex) tmp.BorderColor = this.SelectedColor;
@ -98,13 +99,32 @@ public class TabControl : IRenderObject, IParent
public IParent? Parent { get; private set; } = null; public IParent? Parent { get; private set; } = null;
public Font TitleFont { get; set; } = Label.DefaultFont; public Font TitleFont { get; set; } = Label.DefaultFont;
public Window? Window { get; private set; } = null; public Window? Window { get; private set; } = null;
public bool Visible { get => _bounds.Visible; set => _bounds.Visible = value; }
public bool Visible
{
get => _bounds.Visible;
set
{
BlockDraw = true;
_bounds.Visible = value;
for (int i = 0; i < Buttonts.Length; i++)
Buttonts[i].Visible = value;
if (value) PageIndex = PageIndex;
else
{
for (int i = 0; i < Controls.Length; i++)
Controls[i].Visible = value;
}
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
}
}
public ObjectAnchor Anchor { get => _bounds.Anchor; set => _bounds.Anchor = value; } public ObjectAnchor Anchor { get => _bounds.Anchor; set => _bounds.Anchor = value; }
public object? Tag { get => _bounds.Tag; set => _bounds.Tag = value; } public object? Tag { get => _bounds.Tag; set => _bounds.Tag = value; }
public Vector2i Size { get => _bounds.Size; set => _bounds.Size = value; } public Vector2i Size { get => _bounds.Size; set => _bounds.Size = value; }
public Vector2i Location { get => _bounds.Location; set => _bounds.Location = value; } public Vector2i Location { get => _bounds.Location; set => _bounds.Location = value; }
public ContextMenu? ContextMenu { get => _bounds.ContextMenu; set => _bounds.ContextMenu = value; } public ContextMenu? ContextMenu { get => _bounds.ContextMenu; set => _bounds.ContextMenu = value; }
public Vector2i Distance { get => _bounds.Distance; } public Vector2i Distance { get => _bounds.Distance; internal set => _bounds.Distance = value; }
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; } public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; } public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
private uint pgi = 0; private uint pgi = 0;
@ -117,19 +137,35 @@ public class TabControl : IRenderObject, IParent
set set
{ {
pgi = value; pgi = value;
res = true; BlockDraw = true;
if (_bounds.Visible)
{
for (int i = 0; i < Buttonts.Length; i++) for (int i = 0; i < Buttonts.Length; i++)
((RoundedButton)Buttonts[i]).BorderColor = BorderColor; ((RoundedButton)Buttonts[i]).BorderColor = BorderColor;
((RoundedButton)Buttonts[value]).BorderColor = SelectedColor; ((RoundedButton)Buttonts[value]).BorderColor = SelectedColor;
if (Parent is not null) Parent.TryDraw(); for (int i = 0; i < Controls.Length; i++)
Controls[i].Visible = false;
Controls[value].Visible = true;
} }
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
}
}
public void Focus()
{
}
public void UnFocus()
{
} }
public Vector2i Position => Location; public Vector2i Position => Location;
public bool Loaded { get; private set; } = false; public bool Loaded { get; private set; } = false;
public void TryDraw() public void TryDraw()
{ {
if (!res) Parent!.TryDraw(); if (!BlockDraw) Parent!.TryDraw();
} }
public void ReportSizeUpdate(IRenderObject Control) public void ReportSizeUpdate(IRenderObject Control)
@ -139,9 +175,9 @@ public class TabControl : IRenderObject, IParent
public void ParentResize(ResizeEventArgs e) public void ParentResize(ResizeEventArgs e)
{ {
res = true; BlockDraw = true;
if (e.Width == 0 && e.Height == 0) return; if (e.Width == 0 && e.Height == 0) return;
if (Controls.Length >= PageIndex) return; if (!(Controls.Length >= PageIndex)) return;
if (!Controls[PageIndex].Loaded) return; if (!Controls[PageIndex].Loaded) return;
bool top = (Controls[PageIndex].Anchor & ObjectAnchor.Top) == ObjectAnchor.Top; bool top = (Controls[PageIndex].Anchor & ObjectAnchor.Top) == ObjectAnchor.Top;
bool left = (Controls[PageIndex].Anchor & ObjectAnchor.Left) == ObjectAnchor.Left; bool left = (Controls[PageIndex].Anchor & ObjectAnchor.Left) == ObjectAnchor.Left;
@ -159,17 +195,37 @@ public class TabControl : IRenderObject, IParent
{ {
parent.ParentResize(e); parent.ParentResize(e);
} }
for (int i = 0; i < Buttonts.Length; i++)
{
if (!Buttonts[i].Loaded) continue;
top = (Buttonts[i].Anchor & ObjectAnchor.Top) == ObjectAnchor.Top;
left = (Buttonts[i].Anchor & ObjectAnchor.Left) == ObjectAnchor.Left;
right = (Buttonts[i].Anchor & ObjectAnchor.Right) == ObjectAnchor.Right;
bottom = (Buttonts[i].Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom;
if (!top && !bottom) { Buttonts[i].Anchor |= ObjectAnchor.Top; top = true; }
if (!left && !right) { Buttonts[i].Anchor |= ObjectAnchor.Left; left = true; }
lx = (left ? Buttonts[i].Location.X : Size.X - Buttonts[i].Distance.X - Buttonts[i].Size.X);
ly = (top ? Buttonts[i].Location.Y : Size.Y - Buttonts[i].Distance.Y - Buttonts[i].Size.Y);
sy = (bottom ? Size.Y - Buttonts[i].Distance.Y - ly : Buttonts[i].Size.Y);
sx = (right ? Size.X - Buttonts[i].Distance.X - lx : Buttonts[i].Size.X);
Buttonts[i].Size = new(sx, sy);
Buttonts[i].Location = new(lx, ly);
if (Buttonts[i] is IParent parent2)
{
parent2.ParentResize(e);
}
}
Parent!.TryDraw(); Parent!.TryDraw();
res = false; BlockDraw = false;
} }
private bool res = false; public bool BlockDraw { get; set; } = false;
public void LoadToParent(IParent Parent, Window Window) public void LoadToParent(IParent Parent, Window Window)
{ {
if (Loaded) return; if (Loaded) return;
this.Parent = Parent; this.Parent = Parent;
this.Window = Window; this.Window = Window;
res = true; BlockDraw = true;
Loaded = true; Loaded = true;
_bounds.LoadToParent(Parent, Window); _bounds.LoadToParent(Parent, Window);
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
@ -181,7 +237,7 @@ public class TabControl : IRenderObject, IParent
Buttonts[i].LoadToParent(this, Window); Buttonts[i].LoadToParent(this, Window);
} }
res = false; BlockDraw = false;
if (WindowLoaded is not null) WindowLoaded.Invoke(this); if (WindowLoaded is not null) WindowLoaded.Invoke(this);
} }

View File

@ -56,7 +56,7 @@ public class Textbox : IRenderObject
} }
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; } public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; } public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
public Vector2i Distance { get => _bounds.Distance; } public Vector2i Distance { get => _bounds.Distance; internal set => _bounds.Distance = value; }
public IParent? Parent { get; private set; } = null; public IParent? Parent { get; private set; } = null;
public Window? Window { get; private set; } = null; public Window? Window { get; private set; } = null;
public Color4 InsideColor { get => _inside.BackgroundColor; set => _inside.BackgroundColor = value; } public Color4 InsideColor { get => _inside.BackgroundColor; set => _inside.BackgroundColor = value; }
@ -65,7 +65,12 @@ public class Textbox : IRenderObject
public bool Visible public bool Visible
{ {
get => _bounds.Visible; get => _bounds.Visible;
set => _bounds.Visible = value; set
{
_bounds.Visible = value;
_inside.Visible = value;
_label.Visible = value;
}
} }
public event Func<IRenderObject, Task>? Clicked; public event Func<IRenderObject, Task>? Clicked;
private Task BoundsOnMouseLeave(IRenderObject arg) private Task BoundsOnMouseLeave(IRenderObject arg)
@ -119,6 +124,26 @@ public class Textbox : IRenderObject
private bool use = false; private bool use = false;
public event Func<KeyboardKeyEventArgs, Task>? KeyPress; public event Func<KeyboardKeyEventArgs, Task>? KeyPress;
public void UnFocus()
{
use = false;
if (Window is not null && Window.focused == this)
Window.focused = null;
}
public void Focus()
{
if (Window is not null)
{
if (Window.focused is not null)
{
Window.focused.UnFocus();
}
Window.focused = this;
use = true;
}
}
private void Window_KeyDown(OpenTK.Windowing.Common.KeyboardKeyEventArgs obj) private void Window_KeyDown(OpenTK.Windowing.Common.KeyboardKeyEventArgs obj)
{ {
if (!use) return; if (!use) return;
@ -129,18 +154,21 @@ public class Textbox : IRenderObject
Text = Text.Remove(Text.Length - 1, 1); Text = Text.Remove(Text.Length - 1, 1);
} }
if (obj.Key == Keys.V && obj.Control && Window is not null) Text += Window.ClipboardString;
if (KeyPress is not null) _ = KeyPress.Invoke(obj); if (KeyPress is not null) _ = KeyPress.Invoke(obj);
} }
private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e) private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e)
{ {
if (e.Button == MouseButton.Button1 && if (Visible &&
e.Button == MouseButton.Button1 &&
Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((int)Window?.MousePosition.X!) && Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((int)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((int)Window?.MousePosition.X!) && Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((int)Window?.MousePosition.X!) &&
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((int)Window?.MousePosition.Y!, true) && Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((int)Window?.MousePosition.Y!, true) &&
Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((int)Window?.MousePosition.Y!, true)) Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((int)Window?.MousePosition.Y!, true))
{ {
use = true; use = true;
Focus();
if (Clicked is not null) Clicked.Invoke(this); if (Clicked is not null) Clicked.Invoke(this);
} }
else use = false; else use = false;

View File

@ -20,7 +20,7 @@ public class UserControl : IRenderObject, IParent
public void TryDraw() public void TryDraw()
{ {
if (!res && Parent is not null) Parent.TryDraw(); if (!BlockDraw && Parent is not null) Parent.TryDraw();
} }
private Task _bounds_Clicked(IRenderObject arg) private Task _bounds_Clicked(IRenderObject arg)
@ -34,18 +34,37 @@ public class UserControl : IRenderObject, IParent
public Color4 BackgroundColor { get => _bounds.BackgroundColor; set => _bounds.BackgroundColor = value; } public Color4 BackgroundColor { get => _bounds.BackgroundColor; set => _bounds.BackgroundColor = value; }
public bool Visible { get => _bounds.Visible; set => _bounds.Visible = value; } public bool Visible { get => _bounds.Visible;
private bool res = false; set
{
BlockDraw = true;
_bounds.Visible = value;
for (int i = 0; i < Controls.Length; i++)
Controls[i].Visible = value;
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
}
}
public bool BlockDraw { get; set; } = false;
public void Focus()
{
}
public void UnFocus()
{
}
public Vector2i Size public Vector2i Size
{ {
get => _bounds.Size; get => _bounds.Size;
set set
{ {
BlockDraw = true;
_bounds.Size = value; _bounds.Size = value;
for (int i = 0; i < Controls.Length; i++) ParentResize(new());
{ if (Parent is not null) Parent.TryDraw();
Controls[i].Size = Controls[i].Size; BlockDraw = false;
}
} }
} }
@ -60,11 +79,15 @@ public class UserControl : IRenderObject, IParent
get => _bounds.Location; get => _bounds.Location;
set set
{ {
BlockDraw = true;
_bounds.Location = value; _bounds.Location = value;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
Controls[i].Location = Controls[i].Location; Controls[i].Location = Controls[i].Location;
} }
ParentResize(new());
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
} }
} }
@ -86,7 +109,7 @@ public class UserControl : IRenderObject, IParent
if (Loaded) return; if (Loaded) return;
this.Parent = Parent; this.Parent = Parent;
this.Window = Window; this.Window = Window;
res = true; BlockDraw = true;
Loaded = true; Loaded = true;
_bounds.LoadToParent(Parent, Window); _bounds.LoadToParent(Parent, Window);
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
@ -94,7 +117,7 @@ public class UserControl : IRenderObject, IParent
Controls[i].LoadToParent(this, Window); Controls[i].LoadToParent(this, Window);
} }
res = false; BlockDraw = false;
if (WindowLoaded is not null) WindowLoaded.Invoke(this); if (WindowLoaded is not null) WindowLoaded.Invoke(this);
} }
@ -141,7 +164,7 @@ public class UserControl : IRenderObject, IParent
public void ParentResize(ResizeEventArgs e) public void ParentResize(ResizeEventArgs e)
{ {
res = true; BlockDraw = true;
if (e.Width == 0 && e.Height == 0) return; if (e.Width == 0 && e.Height == 0) return;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
@ -164,7 +187,7 @@ public class UserControl : IRenderObject, IParent
} }
} }
Parent!.TryDraw(); Parent!.TryDraw();
res = false; BlockDraw = false;
} }
#region Cool Math Things #region Cool Math Things

View File

@ -22,6 +22,8 @@ public class Window : NativeWindow , IParent
base.Dispose(disposing); base.Dispose(disposing);
} }
internal IRenderObject? focused;
internal ContextMenu? ActiveMenu { get; set; } = null; internal ContextMenu? ActiveMenu { get; set; } = null;
public IParent? Parent { get; } = null; public IParent? Parent { get; } = null;
public Vector2 LocationAsFloat { get; } = new Vector2(0f, 0f); public Vector2 LocationAsFloat { get; } = new Vector2(0f, 0f);
@ -125,7 +127,7 @@ public class Window : NativeWindow , IParent
public void ParentResize(ResizeEventArgs e) public void ParentResize(ResizeEventArgs e)
{ {
if (e.Width == 0 && e.Height == 0) return; if (e.Width == 0 && e.Height == 0) return;
res = true; BlockDraw = true;
base.OnResize(e); base.OnResize(e);
GL.Viewport(0, 0, e.Width, e.Height); GL.Viewport(0, 0, e.Width, e.Height);
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
@ -149,7 +151,7 @@ public class Window : NativeWindow , IParent
} }
} }
DrawFrame(); DrawFrame();
res = false; BlockDraw = false;
} }
private int frame = 0; private int frame = 0;
@ -201,10 +203,11 @@ public class Window : NativeWindow , IParent
} }
} }
private bool res = false; public bool BlockDraw { get; set; } = false;
public void TryDraw() public void TryDraw()
{ {
if (!res) DrawFrame(); if (!BlockDraw) DrawFrame();
} }
private int initthread = 0; private int initthread = 0;
@ -234,12 +237,12 @@ public class Window : NativeWindow , IParent
if (needload.Any()) if (needload.Any())
{ {
res = true; BlockDraw = true;
foreach (IRenderObject obj in needload) foreach (IRenderObject obj in needload)
{ {
obj.LoadToParent(this, this); obj.LoadToParent(this, this);
} }
res = false; BlockDraw = false;
} }
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)