New Features & Fixes
Fixed some events not triggering correctly Added TabControl render object
This commit is contained in:
parent
f7af843d6f
commit
42c66ce696
@ -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-alpha99999999999996</Version>
|
<Version>1.0.0-alpha99999999999999996</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -15,9 +15,5 @@ public interface IParent
|
|||||||
public void TryDraw();
|
public void TryDraw();
|
||||||
public void ReportSizeUpdate(IRenderObject Control);
|
public void ReportSizeUpdate(IRenderObject Control);
|
||||||
public float FloatToInt(float p, bool Invert = false);
|
public float FloatToInt(float p, bool Invert = false);
|
||||||
public event Action<MouseButtonEventArgs> MouseDown;
|
|
||||||
public event Action<KeyboardKeyEventArgs> KeyDown;
|
|
||||||
public Vector2 MousePosition { get; }
|
|
||||||
|
|
||||||
public Vector2i Position { get; }
|
public Vector2i Position { get; }
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ public class ControlList
|
|||||||
private List<IRenderObject> _internal = new();
|
private List<IRenderObject> _internal = new();
|
||||||
|
|
||||||
public IRenderObject this[int Index] => _internal[Index];
|
public IRenderObject this[int Index] => _internal[Index];
|
||||||
|
public IRenderObject this[uint Index] => _internal[(int)Index];
|
||||||
|
|
||||||
public IEnumerable<IRenderObject> Where(Func<IRenderObject, bool> func) => _internal.Where(func);
|
public IEnumerable<IRenderObject> Where(Func<IRenderObject, bool> func) => _internal.Where(func);
|
||||||
|
|
||||||
|
@ -53,14 +53,14 @@ public class Texture
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
faces[i].SetPixelSizes(0, l.PixelHeight);
|
faces[i].SetPixelSizes(0, l.PixelHeight);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
faces[i].SelectCharmap(Encoding.Unicode);
|
faces[i].SelectCharmap(Encoding.Unicode);
|
||||||
ushort temp = ((ushort)charter);
|
ushort temp = ((ushort)charter);
|
||||||
if (faces[i].GetCharIndex(temp) == 0) continue;
|
if (faces[i].GetCharIndex(temp) == 0) continue;
|
||||||
@ -72,8 +72,9 @@ catch (Exception e)
|
|||||||
{
|
{
|
||||||
Size = new Vector2(bitmap.Width, bitmap.Rows),
|
Size = new Vector2(bitmap.Width, bitmap.Rows),
|
||||||
Bearing = new Vector2(glyph.BitmapLeft, glyph.BitmapTop),
|
Bearing = new Vector2(glyph.BitmapLeft, glyph.BitmapTop),
|
||||||
Advance = (int)glyph.Advance.X.Value,
|
Advance = glyph.Advance.X.Value,
|
||||||
};
|
};
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ public class Label : IRenderObject
|
|||||||
{
|
{
|
||||||
if (value is null) value = string.Empty;
|
if (value is null) value = string.Empty;
|
||||||
text = value;
|
text = value;
|
||||||
float addy = Font.PixelHeight * Scale, addx = 0F, char_x = 0F, hhh = 0F;
|
float addy = Font.PixelHeight * Scale, addx = 0F, char_x = 0F;
|
||||||
for (int i = 0; i < value.Length; i++)
|
for (int i = 0; i < value.Length; i++)
|
||||||
{
|
{
|
||||||
char character;
|
char character;
|
||||||
@ -66,16 +66,17 @@ public class Label : IRenderObject
|
|||||||
else
|
else
|
||||||
character = PasswordChar.Value;
|
character = PasswordChar.Value;
|
||||||
Character cha = Texture.GetChar(Font, character, Font.Faces.ToArray());
|
Character cha = Texture.GetChar(Font, character, Font.Faces.ToArray());
|
||||||
float w = cha.Size.X * Scale;
|
|
||||||
float xrel = char_x + cha.Bearing.X * Scale;
|
|
||||||
if (character == '\n')
|
if (character == '\n')
|
||||||
{
|
{
|
||||||
hhh += Font.PixelHeight;
|
|
||||||
char_x = 0f;
|
char_x = 0f;
|
||||||
addy += Font.PixelHeight * Scale;
|
addy += Font.PixelHeight * Scale;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
float w = cha.Size.X * Scale;
|
||||||
|
float xrel = char_x + cha.Bearing.X * Scale;
|
||||||
char_x += (cha.Advance >> 6) * Scale;
|
char_x += (cha.Advance >> 6) * Scale;
|
||||||
if (xrel + w > addx) addx = xrel + w;
|
if ((xrel + w) >= addx) addx = (xrel + w);
|
||||||
}
|
}
|
||||||
|
|
||||||
Size = new((int)addx, (int)addy);
|
Size = new((int)addx, (int)addy);
|
||||||
@ -150,12 +151,10 @@ public class Label : IRenderObject
|
|||||||
}
|
}
|
||||||
Character ch = _characters[Window!.Context][Font][c];
|
Character ch = _characters[Window!.Context][Font][c];
|
||||||
int maxx = 0;
|
int maxx = 0;
|
||||||
int maxy = (int)Font.PixelHeight;
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
{
|
{
|
||||||
hhh += Font.PixelHeight;
|
hhh += Font.PixelHeight;
|
||||||
char_x = 0f;
|
char_x = 0f;
|
||||||
maxy += (int)Font.PixelHeight;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -165,7 +164,6 @@ public class Label : IRenderObject
|
|||||||
float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale;
|
float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale;
|
||||||
yrel += hhh;
|
yrel += hhh;
|
||||||
char_x += (ch.Advance >> 6) * Scale;
|
char_x += (ch.Advance >> 6) * Scale;
|
||||||
if (xrel + w > maxx) maxx = (int)(xrel + w);
|
|
||||||
Matrix4 scaleM = Matrix4.CreateScale(new Vector3(w, h, 1.0f));
|
Matrix4 scaleM = Matrix4.CreateScale(new Vector3(w, h, 1.0f));
|
||||||
Matrix4 transRelM = Matrix4.CreateTranslation(new Vector3(xrel, yrel, 0.0f));
|
Matrix4 transRelM = Matrix4.CreateTranslation(new Vector3(xrel, yrel, 0.0f));
|
||||||
|
|
||||||
@ -236,10 +234,10 @@ 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)Parent?.MousePosition.X!) &&
|
if (Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
|
||||||
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Parent?.MousePosition.X!) &&
|
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
|
||||||
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Parent?.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)Parent?.MousePosition.Y!, true))
|
Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true))
|
||||||
{
|
{
|
||||||
if (MouseEnter is not null && !mouseinside) _ = MouseEnter.Invoke(this);
|
if (MouseEnter is not null && !mouseinside) _ = MouseEnter.Invoke(this);
|
||||||
mouseinside = true;
|
mouseinside = true;
|
||||||
|
@ -116,10 +116,10 @@ public class Rectangle : ITextureObject
|
|||||||
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)Parent?.MousePosition.X!) &&
|
if (Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
|
||||||
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Parent?.MousePosition.X!) &&
|
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
|
||||||
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Parent?.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)Parent?.MousePosition.Y!, true))
|
Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true))
|
||||||
{
|
{
|
||||||
if (MouseEnter is not null && !mouseinside) _ = MouseEnter.Invoke(this);
|
if (MouseEnter is not null && !mouseinside) _ = MouseEnter.Invoke(this);
|
||||||
mouseinside = true;
|
mouseinside = true;
|
||||||
|
@ -10,7 +10,7 @@ namespace GraphicsManager.Objects;
|
|||||||
public class RoundedButton : IRenderObject
|
public class RoundedButton : IRenderObject
|
||||||
{
|
{
|
||||||
private RoundedRectangle _bounds, _inside;
|
private RoundedRectangle _bounds, _inside;
|
||||||
private Label _label;
|
internal Label _label;
|
||||||
public RoundedButton()
|
public RoundedButton()
|
||||||
{
|
{
|
||||||
_bounds = new RoundedRectangle();
|
_bounds = new RoundedRectangle();
|
||||||
@ -18,6 +18,13 @@ public class RoundedButton : IRenderObject
|
|||||||
_label = new Label();
|
_label = new Label();
|
||||||
_bounds.MouseEnter += BoundsOnMouseEnter;
|
_bounds.MouseEnter += BoundsOnMouseEnter;
|
||||||
_bounds.MouseLeave += BoundsOnMouseLeave;
|
_bounds.MouseLeave += BoundsOnMouseLeave;
|
||||||
|
_bounds.Clicked += BoundsOnClicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task BoundsOnClicked(IRenderObject arg)
|
||||||
|
{
|
||||||
|
if (Clicked is not null) _ = Clicked.Invoke(this);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task BoundsOnMouseLeave(IRenderObject arg)
|
private Task BoundsOnMouseLeave(IRenderObject arg)
|
||||||
@ -73,6 +80,7 @@ public class RoundedButton : IRenderObject
|
|||||||
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; }
|
||||||
public Color4 BorderColor { get => _bounds.BackgroundColor; set => _bounds.BackgroundColor = value; }
|
public Color4 BorderColor { get => _bounds.BackgroundColor; set => _bounds.BackgroundColor = value; }
|
||||||
|
public Color4 FontColor { get => _label.Color; set => _label.Color = value; }
|
||||||
public bool Visible
|
public bool Visible
|
||||||
{
|
{
|
||||||
get => _bounds.Visible;
|
get => _bounds.Visible;
|
||||||
@ -100,7 +108,6 @@ public class RoundedButton : IRenderObject
|
|||||||
if (Loaded) return;
|
if (Loaded) return;
|
||||||
this.Parent = Parent;
|
this.Parent = Parent;
|
||||||
this.Window = Window;
|
this.Window = Window;
|
||||||
this.Window.MouseDown += Window_MouseDown;
|
|
||||||
Loaded = true;
|
Loaded = true;
|
||||||
_bounds.LoadToParent(Parent, Window);
|
_bounds.LoadToParent(Parent, Window);
|
||||||
_inside.LoadToParent(Parent, Window);
|
_inside.LoadToParent(Parent, Window);
|
||||||
@ -108,16 +115,4 @@ public class RoundedButton : IRenderObject
|
|||||||
Location = Location;
|
Location = Location;
|
||||||
if (WindowLoaded is not null) WindowLoaded.Invoke(this);
|
if (WindowLoaded is not null) WindowLoaded.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_MouseDown(OpenTK.Windowing.Common.MouseButtonEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Button == MouseButton.Button1 &&
|
|
||||||
Parent?.IntToFloat(Location.X) <= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
|
||||||
Parent?.IntToFloat(Size.X + Location.X) >= Parent?.IntToFloat((int)Parent?.MousePosition.X!) &&
|
|
||||||
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true) &&
|
|
||||||
Parent?.IntToFloat(Location.Y, true) >= Parent?.IntToFloat((int)Parent?.MousePosition.Y!, true))
|
|
||||||
{
|
|
||||||
if (Clicked is not null) Clicked.Invoke(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -158,10 +158,10 @@ public class RoundedRectangle : 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)Parent?.MousePosition.X!) &&
|
if (Parent?.IntToFloat(Location.X) <= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
|
||||||
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Parent?.MousePosition.X!) &&
|
Parent?.IntToFloat(Size.X + Location.X) >= Window?.IntToFloat((float)Window?.MousePosition.X!) &&
|
||||||
Parent?.IntToFloat(Location.Y + Size.Y, true) <= Window?.IntToFloat((float)Parent?.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)Parent?.MousePosition.Y!, true))
|
Parent?.IntToFloat(Location.Y, true) >= Window?.IntToFloat((float)Window?.MousePosition.Y!, true))
|
||||||
{
|
{
|
||||||
if (MouseEnter is not null && !mouseinside) _ = MouseEnter.Invoke(this);
|
if (MouseEnter is not null && !mouseinside) _ = MouseEnter.Invoke(this);
|
||||||
mouseinside = true;
|
mouseinside = true;
|
||||||
|
282
GraphicsManager/Objects/TabControl.cs
Normal file
282
GraphicsManager/Objects/TabControl.cs
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
using GraphicsManager.Enums;
|
||||||
|
using GraphicsManager.Interfaces;
|
||||||
|
using GraphicsManager.Objects.Core;
|
||||||
|
using OpenTK.Mathematics;
|
||||||
|
using OpenTK.Windowing.Common;
|
||||||
|
using SixLabors.ImageSharp.Processing;
|
||||||
|
|
||||||
|
namespace GraphicsManager.Objects;
|
||||||
|
|
||||||
|
public class TabControl : IRenderObject, IParent
|
||||||
|
{
|
||||||
|
public Rectangle _bounds;
|
||||||
|
|
||||||
|
public TabControl()
|
||||||
|
{
|
||||||
|
_bounds = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ControlList Buttonts = new();
|
||||||
|
private ControlList Controls = new();
|
||||||
|
|
||||||
|
public void AddPage(string Title, UserControl page)
|
||||||
|
{
|
||||||
|
RoundedButton tmp;
|
||||||
|
uint loc = (uint)Buttonts.Length;
|
||||||
|
int locc = 0, loccc = 0;
|
||||||
|
if (loc != 0)
|
||||||
|
{
|
||||||
|
locc = Buttonts[loc - 1].Location.X;
|
||||||
|
loccc = Buttonts[loc - 1].Size.X;
|
||||||
|
}
|
||||||
|
Buttonts.Add(tmp = new RoundedButton()
|
||||||
|
{
|
||||||
|
Location = new( locc+ loccc + (TabSpace * (int)loc) + Border, Border),
|
||||||
|
Font = TitleFont,
|
||||||
|
Text = Title,
|
||||||
|
Tag = loc,
|
||||||
|
BorderColor = this.BorderColor,
|
||||||
|
InsideColor = this.InsideColor,
|
||||||
|
FontColor = this.TextColor
|
||||||
|
});
|
||||||
|
|
||||||
|
if (loc == PageIndex) tmp.BorderColor = this.SelectedColor;
|
||||||
|
tmp.Clicked += TmpOnClicked;
|
||||||
|
tmp.Size = new(tmp._label.Size.X + ((TextBorder + 4) * 2), tmp._label.Size.Y + ((TextBorder + 4) * 2));
|
||||||
|
page.Anchor = ObjectAnchor.All;
|
||||||
|
page.Location = new(Border, tmp.Location.Y + tmp.Size.Y + TabSpace);
|
||||||
|
page.Size = new(Size.X - Border - Border, Size.Y - page.Location.Y - Border);
|
||||||
|
if (PageIndex != loc) page.Visible = false;
|
||||||
|
Controls.Add(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task TmpOnClicked(IRenderObject arg)
|
||||||
|
{
|
||||||
|
PageIndex = (uint)arg.Tag!;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color4 TextColor { get; set; } = new(255, 255, 255, 255);
|
||||||
|
public Color4 BorderColor { get; set; } = new(40, 40, 40, 255);
|
||||||
|
public Color4 SelectedColor { get; set; } = Color4.DarkCyan;
|
||||||
|
public Color4 InsideColor { get; set; } = new(0, 0, 0, 255);
|
||||||
|
public Color4 BackgroundColor { get => _bounds.BackgroundColor; set => _bounds.BackgroundColor = value; }
|
||||||
|
public int TextBorder { get; set; } = 5;
|
||||||
|
public int TabSpace { get; set; } = 5;
|
||||||
|
public int Border { get; set; } = 10;
|
||||||
|
public IParent? Parent { get; private set; } = null;
|
||||||
|
public Font TitleFont { get; set; } = Label.DefaultFont;
|
||||||
|
public Window? Window { get; private set; } = null;
|
||||||
|
public bool Visible { get => _bounds.Visible; set => _bounds.Visible = value; }
|
||||||
|
public ObjectAnchor Anchor { get => _bounds.Anchor; set => _bounds.Anchor = value; }
|
||||||
|
public object? Tag { get => _bounds.Tag; set => _bounds.Tag = value; }
|
||||||
|
public Vector2i Size { get => _bounds.Size; set => _bounds.Size = value; }
|
||||||
|
public Vector2i Location { get => _bounds.Location; set => _bounds.Location = value; }
|
||||||
|
public ContextMenu? ContextMenu { get => _bounds.ContextMenu; set => _bounds.ContextMenu = value; }
|
||||||
|
public Vector2i Distance { get => _bounds.Distance; }
|
||||||
|
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
|
||||||
|
public Vector2 SizeAsFloat { get => _bounds.SizeAsFloat; }
|
||||||
|
private uint pgi = 0;
|
||||||
|
public uint PageIndex
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return pgi;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
pgi = value;
|
||||||
|
res = true;
|
||||||
|
for (int i = 0; i < Buttonts.Length; i++)
|
||||||
|
((RoundedButton)Buttonts[i]).BorderColor = BorderColor;
|
||||||
|
((RoundedButton)Buttonts[value]).BorderColor = SelectedColor;
|
||||||
|
if (Parent is not null) Parent.TryDraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Vector2i Position => Location;
|
||||||
|
public bool Loaded { get; private set; } = false;
|
||||||
|
|
||||||
|
public void TryDraw()
|
||||||
|
{
|
||||||
|
if (!res) Parent!.TryDraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReportSizeUpdate(IRenderObject Control)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ParentResize(ResizeEventArgs e)
|
||||||
|
{
|
||||||
|
res = true;
|
||||||
|
if (e.Width == 0 && e.Height == 0) return;
|
||||||
|
if (Controls.Length >= PageIndex) return;
|
||||||
|
if (!Controls[PageIndex].Loaded) return;
|
||||||
|
bool top = (Controls[PageIndex].Anchor & ObjectAnchor.Top) == ObjectAnchor.Top;
|
||||||
|
bool left = (Controls[PageIndex].Anchor & ObjectAnchor.Left) == ObjectAnchor.Left;
|
||||||
|
bool right = (Controls[PageIndex].Anchor & ObjectAnchor.Right) == ObjectAnchor.Right;
|
||||||
|
bool bottom = (Controls[PageIndex].Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom;
|
||||||
|
if (!top && !bottom) { Controls[PageIndex].Anchor |= ObjectAnchor.Top; top = true; }
|
||||||
|
if (!left && !right) { Controls[PageIndex].Anchor |= ObjectAnchor.Left; left = true; }
|
||||||
|
int lx = (left ? Controls[PageIndex].Location.X : Size.X - Controls[PageIndex].Distance.X - Controls[PageIndex].Size.X);
|
||||||
|
int ly = (top ? Controls[PageIndex].Location.Y : Size.Y - Controls[PageIndex].Distance.Y - Controls[PageIndex].Size.Y);
|
||||||
|
int sy = (bottom ? Size.Y - Controls[PageIndex].Distance.Y - ly : Controls[PageIndex].Size.Y);
|
||||||
|
int sx = (right ? Size.X - Controls[PageIndex].Distance.X - lx : Controls[PageIndex].Size.X);
|
||||||
|
Controls[PageIndex].Size = new(sx, sy);
|
||||||
|
Controls[PageIndex].Location = new(lx, ly);
|
||||||
|
if (Controls[PageIndex] is IParent parent)
|
||||||
|
{
|
||||||
|
parent.ParentResize(e);
|
||||||
|
}
|
||||||
|
Parent!.TryDraw();
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool res = false;
|
||||||
|
public void LoadToParent(IParent Parent, Window Window)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < Buttonts.Length; i++)
|
||||||
|
{
|
||||||
|
Buttonts[i].LoadToParent(this, Window);
|
||||||
|
}
|
||||||
|
|
||||||
|
res = false;
|
||||||
|
if (WindowLoaded is not null) WindowLoaded.Invoke(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw()
|
||||||
|
{
|
||||||
|
if (Loaded && Visible)
|
||||||
|
{
|
||||||
|
_bounds.Draw();
|
||||||
|
if (!(Controls.Length >= (PageIndex))) return;
|
||||||
|
if (!Controls[PageIndex].Loaded) return;
|
||||||
|
Controls[PageIndex].Draw();
|
||||||
|
for (int i = 0; i < Buttonts.Length; i++)
|
||||||
|
Buttonts[i].Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clean()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Controls.Length; i++)
|
||||||
|
{
|
||||||
|
Controls[i].Clean();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < Buttonts.Length; i++)
|
||||||
|
{
|
||||||
|
Buttonts[i].Clean();
|
||||||
|
}
|
||||||
|
_bounds.Clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Func<IRenderObject, Task>? Clicked;
|
||||||
|
public event Func<IRenderObject, Task>? MouseLeave;
|
||||||
|
public event Func<IRenderObject, Task>? MouseEnter;
|
||||||
|
public event Func<IRenderObject, Task>? WindowLoaded;
|
||||||
|
|
||||||
|
#region Cool Math Things
|
||||||
|
public float[] RctToFloat(int x, int y, int Width, int Height, bool hastexture = false, float z = 0.0f)
|
||||||
|
{
|
||||||
|
if (hastexture)
|
||||||
|
{
|
||||||
|
return new float[20] {
|
||||||
|
IntToFloat(x + Width), IntToFloat(y, true), z, 1.0f, 1.0f,// top r
|
||||||
|
IntToFloat(x + Width), IntToFloat(y + Height, true), z, 1.0f, 0.0f,//b r
|
||||||
|
IntToFloat(x), IntToFloat(y + Height, true), z, 0.0f, 0.0f,//bot l
|
||||||
|
IntToFloat(x), IntToFloat(y, true), z, 0.0f, 1.0f// top l
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new float[12] {
|
||||||
|
IntToFloat(x + Width), IntToFloat(y, true), z,// top r
|
||||||
|
IntToFloat(x + Width), IntToFloat(y + Height, true), z, //b r
|
||||||
|
IntToFloat(x), IntToFloat(y + Height, true), z, //bot l
|
||||||
|
IntToFloat(x), IntToFloat(y, true), z,// top l
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 PointToVector(float x, float y, float z = 0.0f)
|
||||||
|
{
|
||||||
|
return new Vector3(IntToFloat(x), IntToFloat(y, true), z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float IntToFloat(float p, bool Invert = false)
|
||||||
|
{
|
||||||
|
p += (Invert ? Location.Y : Location.X);
|
||||||
|
IParent? tempp = Parent;
|
||||||
|
while (tempp is not null)
|
||||||
|
{
|
||||||
|
p += (Invert ? tempp.Position.Y : tempp.Position.X);
|
||||||
|
tempp = tempp.Parent;
|
||||||
|
}
|
||||||
|
float Size = (Invert ? Window!.Size.Y : Window!.Size.X);
|
||||||
|
double half = Math.Round((double)Size / (double)2, 1);
|
||||||
|
double Per = Math.Round((double)1 / half, 15);
|
||||||
|
if (p == half) return 0.0f;
|
||||||
|
if (Invert)
|
||||||
|
{
|
||||||
|
if (p > half) return (float)(((double)(p - half) * Per) * -1);
|
||||||
|
else return (float)(1 - (p * Per));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (p > half) return (float)((double)(p - half) * Per);
|
||||||
|
else return (float)((1 - (p * Per)) * -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float FloatToInt(float p, bool Invert = false)
|
||||||
|
{
|
||||||
|
p += (Invert ? LocationAsFloat.Y : LocationAsFloat.X);
|
||||||
|
IParent? tempp = Parent;
|
||||||
|
while (tempp is not null)
|
||||||
|
{
|
||||||
|
p += (Invert ? tempp.LocationAsFloat.Y : tempp.LocationAsFloat.X);
|
||||||
|
tempp = tempp.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Size = (Invert ? Window!.Size.Y : Window!.Size.X);
|
||||||
|
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)(half * p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (float)(half - (p * half));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (p < 0)
|
||||||
|
{
|
||||||
|
p *= -1;
|
||||||
|
p++;
|
||||||
|
return (float)(Size - (half * p));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (float)(p * half + half);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
@ -72,8 +72,6 @@ public class UserControl : IRenderObject, IParent
|
|||||||
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
|
public Vector2 LocationAsFloat { get => _bounds.LocationAsFloat; }
|
||||||
public Vector2i Distance { get => _bounds.Distance; }
|
public Vector2i Distance { get => _bounds.Distance; }
|
||||||
public event Func<IRenderObject, Task>? Clicked;
|
public event Func<IRenderObject, Task>? Clicked;
|
||||||
public event Action<MouseButtonEventArgs> MouseDown;
|
|
||||||
public event Action<KeyboardKeyEventArgs> KeyDown;
|
|
||||||
public event Func<IRenderObject, Task>? WindowLoaded;
|
public event Func<IRenderObject, Task>? WindowLoaded;
|
||||||
public event Func<IRenderObject, Task>? MouseEnter;
|
public event Func<IRenderObject, Task>? MouseEnter;
|
||||||
public event Func<IRenderObject, Task>? MouseLeave;
|
public event Func<IRenderObject, Task>? MouseLeave;
|
||||||
@ -82,9 +80,7 @@ public class UserControl : IRenderObject, IParent
|
|||||||
public IParent? Parent { get; private set; }
|
public IParent? Parent { get; private set; }
|
||||||
public Window? Window { get; private set; }
|
public Window? Window { get; private set; }
|
||||||
public bool Loaded { get; private set; } = false;
|
public bool Loaded { get; private set; } = false;
|
||||||
|
|
||||||
public Vector2 MousePosition => Window!.MousePosition;
|
|
||||||
|
|
||||||
public void LoadToParent(IParent Parent, Window Window)
|
public void LoadToParent(IParent Parent, Window Window)
|
||||||
{
|
{
|
||||||
if (Loaded) return;
|
if (Loaded) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user