This commit is contained in:
JacobTech 2024-11-18 10:12:57 -05:00
parent a2250893d4
commit 5c0ea7cc90
20 changed files with 889 additions and 681 deletions

View File

@ -67,15 +67,40 @@ public class FPSWindow : GameWindow , IWindow
{ {
TextureManager = TextureManager.GetTextureManager(Context, this); TextureManager = TextureManager.GetTextureManager(Context, this);
Context.MakeCurrent(); Context.MakeCurrent();
if (!Texture.TextureShader.ContainsKey(Context)) Texture.TextureShader.Add(Context, new("RectangleTexture", true, Texture:true)); if (!Texture.TextureShader.ContainsKey(Context)) Texture.TextureShader.Add(Context, new("RectangleTexture", true, Texture:true){CanBlend = true});
if (!Rectangle.DefaultShader.ContainsKey(Context)) Rectangle.DefaultShader.Add(Context, new("Rectangle", true)); if (!Rectangle.DefaultShader.ContainsKey(Context)) Rectangle.DefaultShader.Add(Context, new("Rectangle", true));
if (!Rectangle.DefaultAlphaShader.ContainsKey(Context)) Rectangle.DefaultAlphaShader.Add(Context, new("AlphaChannel", true, Texture:true)); if (!Rectangle.DefaultAlphaShader.ContainsKey(Context)) Rectangle.DefaultAlphaShader.Add(Context, new("AlphaChannel", true, Texture:true){CanBlend = true});
if (!Rectangle.DefaultAlphaTextureShader.ContainsKey(Context)) Rectangle.DefaultAlphaTextureShader.Add(Context, new("AlphaChannelTexture", true, Texture:true)); if (!Rectangle.DefaultAlphaTextureShader.ContainsKey(Context))
if (!Label.DefaultTextShader.ContainsKey(Context)) Label.DefaultTextShader.Add(Context, new("Label", true)); {
Rectangle.DefaultAlphaTextureShader.Add(Context, new("AlphaChannelTexture", true, Texture:true){CanBlend = true});
Rectangle.DefaultAlphaTextureShader[Context].Use();
Rectangle.DefaultAlphaTextureShader[Context].SetInt("bob", 0);
Rectangle.DefaultAlphaTextureShader[Context].SetInt("smith", 1);
}
if (!Label.DefaultTextShader.ContainsKey(Context))
{
Label.DefaultTextShader.Add(Context, new("Label", true){CanBlend = true});
Label.DefaultTextShader[Context].Use();
Label.DefaultTextShader[Context].SetInt("u_texture", Label.DefaultTextShader[Context].GetUniformLocation("u_texture"));
}
if (!Label._characters.ContainsKey(Context)) Label._characters.Add(Context, new()); if (!Label._characters.ContainsKey(Context)) Label._characters.Add(Context, new());
last = WindowState; last = WindowState;
WindowSizeMatrix = Matrix4.CreateOrthographicOffCenter(0.0f, Size.X, Size.Y, 0, 1, -1);
KeyDown += OnKeyDownn; KeyDown += OnKeyDownn;
TextInput += OnTextInputEvent;
FileDrop += OnFileDrop;
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.ScissorTest);
} }
private void OnTextInputEvent(TextInputEventArgs obj)
{
if (focused is not null)
{
focused.SendClipEvent(obj.AsString);
}
}
private WindowState last; private WindowState last;
private bool fs = false; private bool fs = false;
@ -125,9 +150,11 @@ public class FPSWindow : GameWindow , IWindow
public FPSWindow() : this(new NativeWindowSettings(), new GameWindowSettings()) public FPSWindow() : this(new NativeWindowSettings(), new GameWindowSettings())
{ {
} }
public Vector3i Position { get; } = new(0); public Vector2i Position { get; } = new(0);
public Color4 BackgroundColor { get; set; } = new Color4(0, 0, 0, 255); public Color4 BackgroundColor { get; set; } = new Color4(0, 0, 0, 255);
public bool LastFrameIsResize { get; private set; }
public ControlList Controls { get; } = new(); public ControlList Controls { get; } = new();
#region Cool Math Things #region Cool Math Things
public float[] RctToFloat(int x, int y, int Width, int Height, bool hasTexture = false, float z = 0.0f) public float[] RctToFloat(int x, int y, int Width, int Height, bool hasTexture = false, float z = 0.0f)
@ -209,7 +236,7 @@ public class FPSWindow : GameWindow , IWindow
} }
#endregion #endregion
public void ForceUpdate() public virtual void ForceUpdate(bool resize = false)
{ {
BlockDraw = true; BlockDraw = true;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
@ -221,23 +248,136 @@ public class FPSWindow : GameWindow , IWindow
bool bottom = (Controls[i].Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom; bool bottom = (Controls[i].Anchor & ObjectAnchor.Bottom) == ObjectAnchor.Bottom;
if (!top && !bottom) { Controls[i].Anchor |= ObjectAnchor.Top; top = true; } if (!top && !bottom) { Controls[i].Anchor |= ObjectAnchor.Top; top = true; }
if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; } if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; }
int lx = (left ? Controls[i].Location.X : Size.X - Controls[i].Distance.X - Controls[i].Size.X);
int ly = (top ? Controls[i].Location.Y : Size.Y - Controls[i].Distance.Y - Controls[i].Size.Y); int lx, ly, sy, sx;
int sy = (bottom ? Size.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y); bool UpdateDistance = false, SizeChanged = false;
int sx = (right ? Size.X - Controls[i].Distance.X - lx : Controls[i].Size.X); if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange)
Controls[i].Size = new(sx, sy); {
Controls[i].Location = new(lx, ly, Controls[i].Location.Z); UpdateDistance = true;
if (Controls[i] is IParent parent) lx = Controls[i].Location.X + ((CS.X - Controls[i].Distance.X - Controls[i].Size.X - Controls[i].Location.X) / 2);
sx = Controls[i].Size.X;
}
else
{
SizeChanged = true;
lx = (left ? Controls[i].Location.X : CS.X - Controls[i].Distance.X - Controls[i].Size.X);
sx = (right ? CS.X - Controls[i].Distance.X - lx : Controls[i].Size.X);
}
if ((Controls[i].Anchor & ObjectAnchor.PreventHeightChange) == ObjectAnchor.PreventHeightChange)
{
ly = Controls[i].Location.Y + ((CS.Y - Controls[i].Distance.Y - Controls[i].Size.Y - Controls[i].Location.Y) / 2);
sy = Controls[i].Size.Y;
}
else
{
ly = (top ? Controls[i].Location.Y : CS.Y - Controls[i].Distance.Y - Controls[i].Size.Y);
sy = (bottom ? CS.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y);
}
if (Controls[i].Size.X != sx && Controls[i].Size.Y != sy)
{
SizeChanged = true;
}
Controls[i].SetSize(sx, sy);
Controls[i].SetLocation(lx, ly);
if (UpdateDistance)
{
Controls[i].ForceDistanceUpdate(this);
}
if (Controls[i] is IParent parent && SizeChanged)
{ {
parent.ParentResize(); parent.ParentResize();
} }
} }
if (resize) ResizeFrameP1();
else FrameP1();
CheckParent(this);
LastFrameIsResize = true;
BlockDraw = false; BlockDraw = false;
} }
public virtual void ResizeFrameP1()
{
Context.MakeCurrent();
Frame++;
if (LogFrames) Console.WriteLine($"Drawing Frame: {Frame}");
SubFrameCount = 0;
DrawNewResizeFrameToBackBuffer();
Context.SwapBuffers();
}
public virtual void DrawNewResizeFrameToBackBuffer()
{
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.ClearColor(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
LastSW = CS.X;
LastSH = CS.Y;
GL.Scissor(0,0,CS.X, CS.Y);
GL.Clear(ClearBufferMask.ColorBufferBit);
for (int i = 0; i < Controls.Length; i++)
{
if (!Controls[i].Loaded)
{
BlockDraw = true;
Controls[i].LoadToParent(this, this);
BlockDraw = false;
}
if (Controls[i].Location.X >= CS.X ||
Controls[i].Location.Y >= CS.Y ||
Controls[i].Location.X + Controls[i].Size.X < 0 ||
Controls[i].Location.Y + Controls[i].Size.Y < 0) continue;
if (Controls[i] is IParent pp)
{
pp.ResizeDraw(0,0,0,0,CS.X, CS.Y);
GL.Scissor(0, 0, CS.X, CS.Y);
}
else
{
Controls[i].Draw(0,0,0,0,CS.X, CS.Y);
}
}
}
public void ParentResize() public void ParentResize()
{ {
ForceUpdate(); ForceUpdate(true);
}
public virtual void ResizeDraw(int x, int y, int sx, int sy, int sw, int sh)
{
}
public int OldWidth { get; }
public int OldHeight { get; }
public void CopyFromFrontToBack()
{
CopyFromFrontToBack(0, 0, CS.X, CS.Y, 0, 0);
}
public virtual void CopyFromFrontToBack(int x, int y, int width, int height, int NewX, int NewY)
{
int sourceY1 = CS.Y - y - height;
int sourceX2 = x + width;
int sourceY2 = CS.Y - y;
int destY1 = CS.Y - NewY - height;
int destX2 = NewX + width;
int destY2 = destY1 + height;
GL.ReadBuffer(ReadBufferMode.Front);
GL.DrawBuffer(DrawBufferMode.Back);
GL.BlitFramebuffer(
x, sourceY1, sourceX2, sourceY2,
NewX, destY1, destX2, destY2,
ClearBufferMask.ColorBufferBit,
BlitFramebufferFilter.Nearest
);
} }
private int frame = 0; private int frame = 0;
@ -247,12 +387,21 @@ public class FPSWindow : GameWindow , IWindow
} }
public void SetWindowSize(Vector2i s)
{
WindowSizeMatrix = Matrix4.CreateOrthographicOffCenter(0.0f, s.X, s.Y, 0, 1, -1);
GL.Viewport(0, 0, s.X, s.Y);
CS = s;
ClientSize = CS;
ParentResize();
}
protected override void OnResize(ResizeEventArgs e) protected override void OnResize(ResizeEventArgs e)
{ {
base.OnResize(e); base.OnResize(e);
if (e.Width == 0 && e.Height == 0 && WindowState != WindowState.Fullscreen) return; WindowSizeMatrix = Matrix4.CreateOrthographicOffCenter(0.0f, e.Width, e.Height, 0, 1, -1);
GL.Viewport(0, 0, e.Width, e.Height); GL.Viewport(0, 0, e.Width, e.Height);
Matrix4.CreateOrthographicOffCenter(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f); CS = e.Size;
ParentResize(); ParentResize();
} }
@ -282,8 +431,14 @@ public class FPSWindow : GameWindow , IWindow
public IRenderObject? HoveringControl { get; set; } public IRenderObject? HoveringControl { get; set; }
private void WhenMouseMove(MouseMoveEventArgs obj) private void WhenMouseMove(MouseMoveEventArgs obj)
{
HoverCheck(obj);
}
protected virtual void HoverCheck(MouseMoveEventArgs obj)
{ {
IRenderObject? cb = null; IRenderObject? cb = null;
SubHitBox? cbhb = null;
IRenderObject? checkcontrol(IRenderObject render, int add_x = 0, int addy = 0, IRenderObject? CurrentBest = null) IRenderObject? checkcontrol(IRenderObject render, int add_x = 0, int addy = 0, IRenderObject? CurrentBest = null)
{ {
void ClearHoverChain(IRenderObject ChainObject) void ClearHoverChain(IRenderObject ChainObject)
@ -296,7 +451,17 @@ public class FPSWindow : GameWindow , IWindow
} }
} }
if (ChainObject.AllowHoverFromBehind) ChainObject.MouseInside = false; if (ChainObject.AllowHoverFromBehind)
{
ChainObject.MouseInside = false;
if (ChainObject.SubHitBoxes.Count > 0)
{
foreach (SubHitBox shb in ChainObject.SubHitBoxes)
{
shb.MouseInside = false;
}
}
}
} }
if (!render.Visible || if (!render.Visible ||
@ -317,13 +482,27 @@ public class FPSWindow : GameWindow , IWindow
CurrentBest = checkcontrol(p.Controls._internal[i], add_x + render.Location.X, addy + render.Location.Y, CurrentBest); CurrentBest = checkcontrol(p.Controls._internal[i], add_x + render.Location.X, addy + render.Location.Y, CurrentBest);
} }
} }
if (CurrentBest is null) if (CurrentBest is null)
{ {
cbhb = null;
CurrentBest = render; CurrentBest = render;
} }
else
if (render == CurrentBest && CurrentBest.SubHitBoxes.Count > 0)
{ {
if (CurrentBest.Location.Z < render.Location.Z) CurrentBest = render; foreach (SubHitBox hb in CurrentBest.SubHitBoxes)
{
if (render.Location.X + hb.Location.X + add_x > obj.X ||
render.Location.Y + hb.Location.Y + addy > obj.Y ||
render.Location.X + hb.Location.X + hb.Size.X + add_x < obj.X ||
render.Location.Y + hb.Location.Y + hb.Size.Y + addy < obj.Y)
{
continue;
}
cbhb = hb;
}
} }
return CurrentBest; return CurrentBest;
@ -345,8 +524,23 @@ public class FPSWindow : GameWindow , IWindow
else Cursor = HoverMouse; else Cursor = HoverMouse;
if (old is not null) old.MouseInside = false; if (old is not null) old.MouseInside = false;
} }
if (cbhb != HoveringHitBox)
{
SubHitBox? old = HoveringHitBox;
HoveringHitBox = cbhb;
if (cbhb is not null)
{
cbhb.MouseInside = true;
Cursor = cbhb.HoverMouse;
}
else Cursor = HoverMouse;
if (old is not null) old.MouseInside = false;
}
} }
public SubHitBox? HoveringHitBox { get; set; }
public bool BlockDraw { get; set; } public bool BlockDraw { get; set; }
public void TryDraw(int depth = 0) public void TryDraw(int depth = 0)
@ -355,15 +549,16 @@ public class FPSWindow : GameWindow , IWindow
} }
public bool IgnoreVisForChildren { get; set; } public bool IgnoreVisForChildren { get; set; }
public const float alpha = 254f / byte.MaxValue;
public virtual void CheckParent(IParent p, IRenderObject c, int xx, Vector3i di) public virtual void CheckParent(IParent p, IRenderObject c, int xx, Vector2i di)
{ {
if (p.Controls.Length <= 1 || xx >= p.Controls.Length || !c.Visible || c is ILabel) return; if (p.IgnoreVisForChildren || p.Controls.Length <= 1 || xx >= p.Controls.Length || !c.Visible || c is ILabel || (c is Rectangle r && r.BackgroundColor.A <= alpha)) return;
for (int i = xx; i > 0; i--) for (int i = xx; i > 0; i--)
{ {
if (!p.Controls[i].IsVisible || if (!p.Controls[i].IsVisible ||
(p.Controls[i].Location.X + di.X >= c.Location.X && p.Controls[i].Location.X + p.Controls[i].Size.X + di.X - c.Size.X <= c.Location.X) || ((p.Controls[i].Location.X + di.X >= c.Location.X && p.Controls[i].Location.X + p.Controls[i].Size.X + di.X - c.Size.X <= c.Location.X) &&
(p.Controls[i].Location.Y + di.Y >= c.Location.Y && p.Controls[i].Location.Y + p.Controls[i].Size.Y + di.X - c.Size.Y <= c.Location.Y)) (p.Controls[i].Location.Y + di.Y >= c.Location.Y && p.Controls[i].Location.Y + p.Controls[i].Size.Y + di.X - c.Size.Y <= c.Location.Y)))
{ {
p.Controls[i].NotifiNotVisible(); p.Controls[i].NotifiNotVisible();
continue; continue;
@ -374,9 +569,10 @@ public class FPSWindow : GameWindow , IWindow
public virtual void CheckParent(IParent p) public virtual void CheckParent(IParent p)
{ {
for (int i = p.Controls.Length - 1; i > 0; i++) for (int i = p.Controls.Length - 1; i > 0; i--)
{ {
CheckParent(p, p.Controls[i], i-1, new()); CheckParent(p, p.Controls[i], i-1, new());
if (p.Controls[i] is IParent pp) CheckParent(pp);
} }
} }
@ -404,42 +600,56 @@ public class FPSWindow : GameWindow , IWindow
invokes.Enqueue(A); invokes.Enqueue(A);
} }
protected override void OnRenderFrame(FrameEventArgs args) public virtual void DrawNewFrameToBackBuffer()
{ {
Context.MakeCurrent();
frame++;
Console.WriteLine($"Drawing Frame: {frame}");
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.Enable(EnableCap.ScissorTest); GL.ClearColor(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
LastSW = CS.X;
LastSH = CS.Y;
GL.Scissor(0,0,CS.X, CS.Y);
GL.Clear(ClearBufferMask.ColorBufferBit);
for (int i = 0; i < Controls.Length; i++)
{
if (!Controls[i].Loaded)
{
BlockDraw = true;
Controls[i].LoadToParent(this, this);
BlockDraw = false;
}
if (Controls[i].Location.X >= CS.X ||
Controls[i].Location.Y >= CS.Y ||
Controls[i].Location.X + Controls[i].Size.X < 0 ||
Controls[i].Location.Y + Controls[i].Size.Y < 0) continue;
Controls[i].Draw(0,0,0,0,CS.X, CS.Y);
if (Controls[i] is IParent) GL.Scissor(0, 0, CS.X, CS.Y);
}
}
GL.ClearColor(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, (BackgroundColor.A * -1) + 1); public virtual void FrameP1()
{
Context.MakeCurrent();
Frame++;
if (LogFrames) Console.WriteLine($"Drawing Frame: {Frame}");
SubFrameCount = 0;
DrawNewFrameToBackBuffer();
Context.SwapBuffers();
}
public bool UseSubFrames { get; set; } = false;
protected override void OnRenderFrame(FrameEventArgs args)
{
if (invokes.Any()) if (invokes.Any())
{ {
for (int i = 0; i < invokes.Count; i++) invokes.Dequeue().Invoke(); for (int i = 0; i < invokes.Count; i++) invokes.Dequeue().Invoke();
} }
IEnumerable<IRenderObject> needload = Controls.Where(a => a.Loaded == false); FrameP1();
if (LastFrameIsResize)
if (needload.Any())
{ {
BlockDraw = true; DrawNewFrameToBackBuffer();
foreach (IRenderObject obj in needload) LastFrameIsResize = false;
{
obj.LoadToParent(this, this);
}
BlockDraw = false;
} }
CheckParent(this);
GL.Scissor(0, 0, Size.X, Size.Y);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
for (int i = 0; i < Controls.Length; i++)
{
if (!Controls[i].Loaded) continue;
GL.Scissor(0, 0, Size.X, Size.Y);
Controls[i].Draw(0,0,0,0,Size.X, Size.Y);
}
Context.SwapBuffers();
base.OnRenderFrame(args);
} }
} }

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.1.0-alpha98</Version> <Version>1.1.1-alpha29</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

View File

@ -15,7 +15,7 @@ public interface IParent
public float IntToWindow(float p, bool Y = false); public float IntToWindow(float p, bool Y = false);
public void TryDraw(int depth = 0); public void TryDraw(int depth = 0);
public void ReportSizeUpdate(IRenderObject Control); public void ReportSizeUpdate(IRenderObject Control);
public Vector3i Position { get; } public Vector2i Position { get; }
public MouseCursor HoverMouse { get; set; } public MouseCursor HoverMouse { get; set; }
public int LastX { get; } public int LastX { get; }
public int LastY { get; } public int LastY { get; }
@ -25,4 +25,7 @@ public interface IParent
public int LastSH { get; } public int LastSH { get; }
public bool BlockDraw { get; set; } public bool BlockDraw { get; set; }
public bool IgnoreVisForChildren { get; set; } public bool IgnoreVisForChildren { get; set; }
public void ResizeDraw(int x, int y, int sx, int sy, int sw, int sh);
public int OldWidth { get; }
public int OldHeight { get; }
} }

View File

@ -21,13 +21,13 @@ public interface IRenderObject
public bool AllowHoverFromBehind { get; set; } public bool AllowHoverFromBehind { get; set; }
public bool Loaded { get; } public bool Loaded { get; }
public void LoadToParent(IParent Parent, IWindow Window); public void LoadToParent(IParent Parent, IWindow Window);
public void UpdateOpenGLCords(bool draw = false);
public void Draw(int x, int y, int sx, int sy, int sw, int sh); public void Draw(int x, int y, int sx, int sy, int sw, int sh);
public MouseCursor HoverMouse { get; set; } public MouseCursor HoverMouse { get; set; }
public void SetSize(int wh); public void SetSize(int wh);
public void SetSize(int w, int h); public void SetSize(int w, int h);
public void SetLocation(int xy); public void SetLocation(int xy);
public void SetLocation(int x, int y); public void SetLocation(int x, int y);
public void SetLocation(int x, int y, int z);
public void Clean(); public void Clean();
public void Focus(); public void Focus();
public void UnFocus(); public void UnFocus();
@ -36,7 +36,7 @@ public interface IRenderObject
public void SendClipEvent(string Text); public void SendClipEvent(string Text);
public void SendFilesEvent(string[] Files); public void SendFilesEvent(string[] Files);
public Vector2i Size { get; set; } public Vector2i Size { get; set; }
public Vector3i Location { get; set; } public Vector2i Location { get; set; }
public Vector2 SizeAsFloat { get; } public Vector2 SizeAsFloat { get; }
public Vector2 LocationAsFloat { get; } public Vector2 LocationAsFloat { get; }
public Vector2i Distance { get; set; } public Vector2i Distance { get; set; }

View File

@ -13,7 +13,10 @@ public interface IWindow : IParent
public Matrix4 WindowSizeMatrix { get; } public Matrix4 WindowSizeMatrix { get; }
public Vector2i CS { get; } public Vector2i CS { get; }
public void CheckParent(IParent p, IRenderObject c, int xx, Vector3i di); public bool LastFrameIsResize { get; }
public bool UseSubFrames { get; set; }
public void CheckParent(IParent p, IRenderObject c, int xx, Vector2i di);
public void CheckParent(IParent p); public void CheckParent(IParent p);
public event Action<MouseButtonEventArgs> MouseDown; public event Action<MouseButtonEventArgs> MouseDown;
@ -47,4 +50,6 @@ public interface IWindow : IParent
public bool LogFrames { get; set; } public bool LogFrames { get; set; }
public int SubFrameCount { get; } public int SubFrameCount { get; }
public int Frame { get; } public int Frame { get; }
public void CopyFromFrontToBack(int x, int y, int width, int height, int NewX, int NewY);
public void CopyFromFrontToBack();
} }

View File

@ -16,7 +16,7 @@ public class BetterContextMenu : UserControl
{ {
mg = value; mg = value;
BlockDraw = true; BlockDraw = true;
fl.Location = new(mg.W, mg.X, Location.Z); fl.Location = new(mg.W, mg.X);
if (AutoSizeWidth || AutoSizeHeight) if (AutoSizeWidth || AutoSizeHeight)
{ {
int x = 0, y = 0; int x = 0, y = 0;
@ -82,8 +82,8 @@ public class BetterContextMenu : UserControl
LoadToParent(ParentWindow, ParentWindow); LoadToParent(ParentWindow, ParentWindow);
} }
} }
if (Size.Y + (int)ParentWindow.MousePosition.Y > ParentWindow.Size.Y) Location = new((int)ParentWindow.MousePosition.X, ParentWindow.Size.Y - Size.Y, Location.Z); if (Size.Y + (int)ParentWindow.MousePosition.Y > ParentWindow.Size.Y) Location = new((int)ParentWindow.MousePosition.X, ParentWindow.Size.Y - Size.Y);
else Location = new((int)ParentWindow.MousePosition.X, (int)ParentWindow.MousePosition.Y, Location.Z); else Location = new((int)ParentWindow.MousePosition.X, (int)ParentWindow.MousePosition.Y);
Visible = true; Visible = true;
TryDraw(); TryDraw();
} }

View File

@ -281,8 +281,8 @@ public class LabelBase : ILabel
public FontInteraction Font { get; protected set; } public FontInteraction Font { get; protected set; }
public virtual float Scale { get; set; } = 1.0f; public virtual float Scale { get; set; } = 1.0f;
public virtual Vector2i Distance { get; set; } public virtual Vector2i Distance { get; set; }
protected Vector3i loc_; protected Vector2i loc_;
public virtual Vector3i Location public virtual Vector2i Location
{ {
get get
{ {
@ -290,25 +290,19 @@ public class LabelBase : ILabel
} }
set set
{ {
SetLocation(value.X, value.Y, value.Z); SetLocation(value.X, value.Y);
} }
} }
public virtual void SetLocation(int xy) public virtual void SetLocation(int xy)
{ {
SetLocation(xy, xy, 0); SetLocation(xy, xy);
} }
public virtual void SetLocation(int x, int y) public virtual void SetLocation(int x, int y)
{
SetLocation(x, y, 0);
}
public virtual void SetLocation(int x, int y, int z)
{ {
loc_.X = x; loc_.X = x;
loc_.Y = y; loc_.Y = y;
loc_.Z = z;
if (Window is null || Parent is null) return; if (Window is null || Parent is null) return;
if (Window.CanControleUpdate && Loaded) if (Window.CanControleUpdate && Loaded)
{ {
@ -317,6 +311,11 @@ public class LabelBase : ILabel
} }
} }
public virtual void UpdateOpenGLCords(bool draw = false)
{
}
public virtual void SetSize(int wh) public virtual void SetSize(int wh)
{ {
SetSize(wh, wh); SetSize(wh, wh);
@ -432,7 +431,9 @@ public class LabelBase : ILabel
float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X); float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X);
Matrix4 rotateM = Matrix4.CreateRotationZ(angle_rad); Matrix4 rotateM = Matrix4.CreateRotationZ(angle_rad);
Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(loc_.X + Parent!.IntToWindow(0), loc_.Y + (Font.PixelHeight * Scale) + Parent!.IntToWindow(0, true), 0f)); Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(loc_.X + Parent!.IntToWindow(0), loc_.Y + (Font.PixelHeight * Scale) + Parent!.IntToWindow(0, true), 0f));
float char_x = 0.0f; float char_x = 0.0f;
Matrix4 staticTransform = rotateM * transOriginM;
GL.UniformMatrix4(0, false, ref staticTransform);
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
GL.ActiveTexture((Shader.GetUniformLocation("u_texture") switch GL.ActiveTexture((Shader.GetUniformLocation("u_texture") switch
@ -480,11 +481,9 @@ public class LabelBase : ILabel
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;
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; GL.Uniform2(Shader.GetUniformLocation("scale"), w, h);
GL.UniformMatrix4(0, false, ref modelM); GL.Uniform2(Shader.GetUniformLocation("offset"), xrel, yrel);
ch.Texture.Use(); ch.Texture.Use();

View File

@ -14,16 +14,16 @@ public abstract class ParentBase : Rectangle, IParent
} }
public ControlList Controls { get; } = new(); public ControlList Controls { get; } = new();
public int LastX { get; private set; } public int LastX { get; protected set; }
public int LastY { get; private set; } public int LastY { get; protected set; }
public int LastSX { get; private set; } public int LastSX { get; protected set; }
public int LastSY { get; private set; } public int LastSY { get; protected set; }
public int LastSW { get; private set; } public int LastSW { get; protected set; }
public int LastSH { get; private set; } public int LastSH { get; protected set; }
public Vector3i Position => Location; public Vector2i Position => Location;
public virtual void ParentResize() public void BaseParentResize()
{ {
BlockDraw = true; BlockDraw = true;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
@ -37,7 +37,7 @@ public abstract class ParentBase : Rectangle, IParent
if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; } if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; }
int lx, ly, sy, sx; int lx, ly, sy, sx;
bool UpdateDistance = false; bool UpdateDistance = false, SizeChanged = false;
if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange) if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange)
{ {
UpdateDistance = true; UpdateDistance = true;
@ -61,22 +61,20 @@ public abstract class ParentBase : Rectangle, IParent
sy = (bottom ? Size.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y); sy = (bottom ? Size.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y);
} }
bool mooved = false;
if (sx != Controls[i].Size.X || sy != Controls[i].Size.Y) if (sx != Controls[i].Size.X || sy != Controls[i].Size.Y)
{ {
mooved = true; SizeChanged = true;
Controls[i].SetSize(sx, sy); Controls[i].SetSize(sx, sy);
} }
if (lx != Controls[i].Location.X || ly != Controls[i].Location.Y) if (lx != Controls[i].Location.X || ly != Controls[i].Location.Y)
{ {
mooved = true;
Controls[i].SetLocation(lx, ly); Controls[i].SetLocation(lx, ly);
} }
if (UpdateDistance) if (UpdateDistance)
{ {
Controls[i].ForceDistanceUpdate(this); Controls[i].ForceDistanceUpdate(this);
} }
if (mooved && Controls[i] is IParent parent) if (SizeChanged && Controls[i] is IParent parent)
{ {
parent.ParentResize(); parent.ParentResize();
} }
@ -85,6 +83,27 @@ public abstract class ParentBase : Rectangle, IParent
BlockDraw = false; BlockDraw = false;
} }
public virtual void ParentResize()
{
BaseParentResize();
}
public override void SetLocation(int x, int y)
{
base.SetLocation(x, y);
for (int i = 0; i < Controls.Length; i++)
{
Controls[i].UpdateOpenGLCords();
}
}
public override void SetSize(int w, int h)
{
OldHeight = Size.Y;
OldWidth = Size.X;
base.SetSize(w, h);
}
public virtual void ReportSizeUpdate(IRenderObject Control) public virtual void ReportSizeUpdate(IRenderObject Control)
{ {
@ -94,75 +113,106 @@ public abstract class ParentBase : Rectangle, IParent
{ {
if (Loaded && Visible && Location.X > 0 - Size.X && Location.Y > 0 - Size.Y) if (Loaded && Visible && Location.X > 0 - Size.X && Location.Y > 0 - Size.Y)
{ {
if (Location.X - sx + x > sw || Location.Y - sy + y > sh) DrawBase();
if (!UpdateScissorBox(ref x, ref y, ref sx, ref sy, ref sw, ref sh)) return;
for (int i = 0; i < Controls.Length; i++)
{ {
NotifiNotVisible(); if (!Controls[i].Loaded)
return; {
BlockDraw = true;
Controls[i].LoadToParent(this, Window!);
if (this is IFlow flow) flow.ForceScrollUpdate();
BlockDraw = false;
}
if (Controls[i].Location.X >= Size.X ||
Controls[i].Location.Y >= Size.Y ||
Controls[i].Location.X + Controls[i].Size.X < 0 ||
Controls[i].Location.Y + Controls[i].Size.Y < 0) continue;
Controls[i].Draw(x,y,sx,sy,sw,sh);
if (Controls[i] is IParent) GL.Scissor(sx, Window!.CS.Y - sy - sh, sw, sh);
} }
}
}
if (Location.X - sx + x > -1) public virtual bool UpdateScissorBox(ref int x, ref int y, ref int sx, ref int sy, ref int sw, ref int sh, int xx = 0, int xy = 0, int lw = 0, int lh = 0, bool UpdateBoxInfo = true)
{ {
int add = Location.X - sx + x;
sx += add;
sw -= add;
if (Size.X < sw)
sw = Size.X;
}
else
{
if (Size.X + Location.X - sx + x < sw)
sw = Size.X + Location.X - sx + x;
}
if (Location.Y - sy + y > -1)
{
int add = Location.Y - sy + y;
sy += add;
sh -= add;
if (Size.Y < sh)
sh = Size.Y;
}
else
{
if (Size.Y + Location.Y - sy + y < sh)
sh = Size.Y + Location.Y - sy + y;
}
x += Location.X; int nw = Size.X - xx - lw,
y += Location.Y; nh = Size.Y - xy - lh,
nx = Location.X + xx,
ny = Location.Y + xy;
if (sw <= 0 || sh <= 0) if (nx - sx + x > sw || ny - sy + y > sh)
{ {
NotifiNotVisible(); if (UpdateBoxInfo) NotifiNotVisible();
return; return false;
} }
base.Draw(x,y,sx,sy,sw,sh);
if (nx - sx + x > -1)
{
int add = nx - sx + x;
sx += add;
sw -= add;
if (nw < sw)
sw = nw;
}
else
{
if (nw + nx - sx + x < sw)
sw = nw + nx - sx + x;
}
if (ny - sy + y > -1)
{
int add = ny - sy + y;
sy += add;
sh -= add;
if (nh < sh)
sh = nh;
}
else
{
if (nh + ny - sy + y < sh)
sh = nh + ny - sy + y;
}
x += nx;
y += ny;
if (sw <= 0 || sh <= 0)
{
if (UpdateBoxInfo) NotifiNotVisible();
return false;
}
if (UpdateBoxInfo)
{
LastX = x; LastX = x;
LastY = y; LastY = y;
LastSX = sx; LastSX = sx;
LastSY = sy; LastSY = sy;
LastSW = sw; LastSW = sw;
LastSH = sh; LastSH = sh;
IEnumerable<IRenderObject> needload = Controls.Where(a => a.Loaded == false);
if (needload.Any())
{
BlockDraw = true;
foreach (IRenderObject Control in needload)
{
Control.LoadToParent(this, Window!);
}
if (this is IFlow flow) flow.ForceScrollUpdate();
BlockDraw = false;
}
for (int i = 0; i < Controls.Length; i++)
{
if (Controls[i].Location.X > Size.X || Controls[i].Location.Y > Size.Y) continue;
GL.Scissor(sx, Window!.CS.Y - sy - sh, sw, sh);
Controls[i].Draw(x,y,sx,sy,sw,sh);
}
} }
return true;
} }
public virtual void ResizeDraw(int x, int y, int sx, int sy, int sw, int sh)
{
if (Anchor == (ObjectAnchor.Top | ObjectAnchor.Left))
{
int nw = Math.Min(OldWidth, Size.X),
nh = Math.Min(OldHeight, Size.Y);
if (!UpdateScissorBox(ref x, ref y, ref sx, ref sy, ref sw, ref sh)) return;
Window!.CopyFromFrontToBack(x, y, Size.X, Size.Y, x, y);
}
else Draw(x,y,sx,sy,sw,sh);
}
public int OldWidth { get; protected set; }
public int OldHeight { get; protected set; }
public bool IgnoreVisForChildren { get; set; } public bool IgnoreVisForChildren { get; set; }
@ -199,22 +249,6 @@ public abstract class ParentBase : Rectangle, IParent
BlockDraw = PastBlockState; BlockDraw = PastBlockState;
} }
public override Vector3i Location
{
get => base.Location;
set
{
BlockDraw = true;
base.Location = value;
for (int i = 0; i < Controls.Length; i++)
{
Controls[i].Location = Controls[i].Location;
}
ParentResize();
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
}
}
public float IntToWindow(float p, bool Y = false) public float IntToWindow(float p, bool Y = false)
{ {

View File

@ -30,16 +30,16 @@ public class RoundedButton : Rectangle
set set
{ {
base.Size = value; base.Size = value;
_label.Location = new(Location.X + (((value.X) / 2) - (_label.Size.X / 2)), Location.Y + (((value.Y) / 2) - (_label.Size.Y / 2)), Location.Z); _label.Location = new(Location.X + (((value.X) / 2) - (_label.Size.X / 2)), Location.Y + (((value.Y) / 2) - (_label.Size.Y / 2)));
} }
} }
public override Vector3i Location { public override Vector2i Location {
get => base.Location; get => base.Location;
set set
{ {
base.Location = value; base.Location = value;
_label.Location = new(value.X + (((Size.X) / 2) - (_label.Size.X / 2)), value.Y + (((Size.Y) / 2) - (_label.Size.Y / 2)), value.Z); _label.Location = new(value.X + (((Size.X) / 2) - (_label.Size.X / 2)), value.Y + (((Size.Y) / 2) - (_label.Size.Y / 2)));
} }
} }

View File

@ -65,7 +65,7 @@ public class FlowLayout : ParentBase, IFlow
for (int i = Controls.Length - 1; i >= 0; i--) for (int i = Controls.Length - 1; i >= 0; i--)
{ {
start -= Controls[i].Size.Y; start -= Controls[i].Size.Y;
Controls[i].Location = new(Controls[i].Location.X, start, Controls[i].Location.Z); Controls[i].Location = new(Controls[i].Location.X, start);
} }
} }
else else
@ -77,7 +77,7 @@ public class FlowLayout : ParentBase, IFlow
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
start += Controls[i].Size.Y; start += Controls[i].Size.Y;
Controls[i].Location = new(Controls[i].Location.X, start, Controls[i].Location.Z); Controls[i].Location = new(Controls[i].Location.X, start);
} }
} }
@ -117,10 +117,14 @@ public class FlowLayout : ParentBase, IFlow
if (index < Controls.Length - 1) if (index < Controls.Length - 1)
{ {
int dif = Control.Location.Y + Control.Size.Y - Controls[index + 1].Location.Y; int dif = Control.Location.Y + Control.Size.Y - Controls[index + 1].Location.Y;
Vector3i v3i = new(0, dif, 0); Vector2i v3i = new(0, dif);
for (int i = index + 1; i < Controls.Length; i++) for (int i = index + 1; i < Controls.Length; i++)
{ {
Controls[i].Location += v3i; Controls[i].Location += v3i;
if (Controls[i] is IParent p)
{
p.ParentResize();
}
} }
} }
else else
@ -138,7 +142,7 @@ public class FlowLayout : ParentBase, IFlow
bool top = false; bool top = false;
for (int i = 1; i < Controls.Length; i++) for (int i = 1; i < Controls.Length; i++)
{ {
Controls[i].Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y, Controls[i].Location.Z); Controls[i].Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y);
if (Controls[i].Location.Y >= 0 && !top) if (Controls[i].Location.Y >= 0 && !top)
{ {
top = true; top = true;
@ -158,13 +162,13 @@ public class FlowLayout : ParentBase, IFlow
if (index < Controls.Length) if (index < Controls.Length)
{ {
arg.Location = Controls[index].Location; arg.Location = Controls[index].Location;
Controls[index].Location = new(arg.Location.X, Controls[index].Location.Y + arg.Size.Y, arg.Location.Z); Controls[index].Location = new(arg.Location.X, Controls[index].Location.Y + arg.Size.Y);
for (int i = index + 1; i < Controls.Length; i++) for (int i = index + 1; i < Controls.Length; i++)
{ {
Controls[i].Location = new(0, Controls[i - 1].Location.Y + Controls[i - 1].Size.Y, arg.Location.Z); Controls[i].Location = new(0, Controls[i - 1].Location.Y + Controls[i - 1].Size.Y);
} }
} }
else arg.Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + SpaceBetweenObjects, arg.Location.Z); else arg.Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y + SpaceBetweenObjects);
} }
else arg.Location = new(0); else arg.Location = new(0);
if (arg is IParent par2) if (arg is IParent par2)
@ -193,17 +197,75 @@ public class FlowLayout : ParentBase, IFlow
int sy = (bottom ? Size.Y - par.Controls[i].Distance.Y - ly : par.Controls[i].Size.Y); int sy = (bottom ? Size.Y - par.Controls[i].Distance.Y - ly : par.Controls[i].Size.Y);
int sx = (right ? Size.X - par.Controls[i].Distance.X - lx : par.Controls[i].Size.X); int sx = (right ? Size.X - par.Controls[i].Distance.X - lx : par.Controls[i].Size.X);
par.Controls[i].Size = new(sx, sy); par.Controls[i].Size = new(sx, sy);
par.Controls[i].Location = new(lx, ly, par.Controls[i].Location.Z); par.Controls[i].Location = new(lx, ly);
} }
} }
if (arg is not ILabel) arg.Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top; if (arg is not ILabel) arg.Anchor = ObjectAnchor.Left | ObjectAnchor.Right | ObjectAnchor.Top;
return Task.CompletedTask; return Task.CompletedTask;
} }
public override void ParentResize()
{ public override void ResizeDraw(int x, int y, int sx, int sy, int sw, int sh)
//Child objects dont need to be updated {
} if (Anchor == (ObjectAnchor.Top | ObjectAnchor.Bottom | ObjectAnchor.Left))
{
if (OldHeight == Size.Y)
{
if (!UpdateScissorBox(ref x, ref y, ref sx, ref sy, ref sw, ref sh)) return;
Window!.CopyFromFrontToBack(x, y, Size.X, Size.Y, x, y);
}
else if (OldHeight < Size.Y)
{
if (Visible && Location.X > 0 - Size.X && Location.Y > 0 - Size.Y)
{
if (!UpdateScissorBox(ref x, ref y, ref sx, ref sy, ref sw, ref sh)) return;
Window!.CopyFromFrontToBack(x, y, OldWidth, OldHeight, x, y);
int nsh = sh - OldHeight+1;
if (nsh <= 0) return;
GL.Scissor(sx, Window!.CS.Y - sy - sh, sw, nsh);
DrawBase();
GL.Scissor(sx, Window!.CS.Y - sy - sh, sw, sh);
for (int i = 0; i < Controls.Length; i++)
{
if (!Controls[i].Loaded)
{
BlockDraw = true;
Controls[i].LoadToParent(this, Window!);
if (this is IFlow flow) flow.ForceScrollUpdate();
BlockDraw = false;
}
if (Controls[i].Location.X >= Size.X ||
Controls[i].Location.Y >= Size.Y ||
Controls[i].Location.X + Controls[i].Size.X < OldWidth ||
Controls[i].Location.Y + Controls[i].Size.Y < OldHeight) continue;
if (Controls[i] is IParent pp)
{
pp.ResizeDraw(x,y,sx,sy,sw,sh);
GL.Scissor(sx, Window!.CS.Y - sy - sh, sw, sh);
}
else
{
Controls[i].Draw(x,y,sx,sy,sw,sh);
}
}
}
}
else
{
if (!UpdateScissorBox(ref x, ref y, ref sx, ref sy, ref sw, ref sh)) return;
Window!.CopyFromFrontToBack(x, y, Size.X, Size.Y, x, y);
}
}
else if (Anchor == (ObjectAnchor.Top | ObjectAnchor.Left))
{
if (!UpdateScissorBox(ref x, ref y, ref sx, ref sy, ref sw, ref sh)) return;
Window!.CopyFromFrontToBack(x, y, Size.X, Size.Y, x, y);
}
else Draw(x,y,sx,sy,sw,sh);
}
public override void SetSize(int w, int h) public override void SetSize(int w, int h)
{ {
@ -213,7 +275,6 @@ public class FlowLayout : ParentBase, IFlow
{ {
Controls[i].SetSize(w, Controls[i].Size.Y); Controls[i].SetSize(w, Controls[i].Size.Y);
} }
ParentResize();
if (Parent is not null) Parent.TryDraw(); if (Parent is not null) Parent.TryDraw();
BlockDraw = false; BlockDraw = false;
} }
@ -259,7 +320,7 @@ public class FlowLayout : ParentBase, IFlow
public event Func<bool, uint, uint, Task>? FlowUpdate; public event Func<bool, uint, uint, Task>? FlowUpdate;
public uint ScrollValue public virtual uint ScrollValue
{ {
get => ScrollValueBackEnd; get => ScrollValueBackEnd;
set set
@ -271,7 +332,7 @@ public class FlowLayout : ParentBase, IFlow
return; return;
} }
BlockDraw = true; BlockDraw = true;
Vector3i v3i = new(0, (int)(value - ScrollValueBackEnd), 0); Vector2i v3i = new(0, (int)(value - ScrollValueBackEnd));
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
{ {
Controls[i].Location -= v3i; Controls[i].Location -= v3i;
@ -284,6 +345,20 @@ public class FlowLayout : ParentBase, IFlow
} }
} }
public override void ParentResize()
{
BlockDraw = true;
for (int i = 0; i < Controls.Length; i++)
{
if (Controls[i] is IParent parent)
{
parent.ParentResize();
}
}
if (Parent is not null) Parent.TryDraw();
BlockDraw = false;
}
public uint MaxScrollValue public uint MaxScrollValue
{ {
get get

View File

@ -43,7 +43,9 @@ public class Label : LabelBase
float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X); float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X);
Matrix4 rotateM = Matrix4.CreateRotationZ(angle_rad); Matrix4 rotateM = Matrix4.CreateRotationZ(angle_rad);
Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(loc_.X + Parent!.IntToWindow(0), loc_.Y + (Font.PixelHeight * Scale) + Parent!.IntToWindow(0, true), 0f)); Matrix4 transOriginM = Matrix4.CreateTranslation(new Vector3(loc_.X + Parent!.IntToWindow(0), loc_.Y + (Font.PixelHeight * Scale) + Parent!.IntToWindow(0, true), 0f));
float char_x = 0.0f; float char_x = 0.0f;
Matrix4 staticTransform = rotateM * transOriginM;
GL.UniformMatrix4(0, false, ref staticTransform);
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
GL.ActiveTexture((Shader.GetUniformLocation("u_texture") switch GL.ActiveTexture((Shader.GetUniformLocation("u_texture") switch
@ -74,34 +76,33 @@ public class Label : LabelBase
_ = Texture.TextureForChar(Window!.Context, Font, c, Shader); _ = Texture.TextureForChar(Window!.Context, Font, c, Shader);
} }
if (n) if (n)
{ {
hhh += LineHeight; hhh += LineHeight;
hhh += Font.ExtraLinePixels; hhh += Font.ExtraLinePixels;
char_x = 0f; char_x = 0f;
} }
else else
{ {
if (!_characters[Window!.Context][Font].ContainsKey(c)) continue; if (!_characters[Window!.Context][Font].ContainsKey(c)) continue;
Character ch = _characters[Window!.Context][Font][c]; Character ch = _characters[Window!.Context][Font][c];
float w = ch.Size.X * Scale; float w = ch.Size.X * Scale;
float h = ch.Size.Y * Scale; float h = ch.Size.Y * Scale;
float xrel = char_x + ch.Bearing.X * Scale; float xrel = char_x + ch.Bearing.X * Scale;
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;
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; GL.Uniform2(Shader.GetUniformLocation("scale"), w, h);
GL.UniformMatrix4(0, false, ref modelM); GL.Uniform2(Shader.GetUniformLocation("offset"), xrel, yrel);
ch.Texture.Use();
GL.DrawArrays(PrimitiveType.Triangles, 0, 6); ch.Texture.Use();
}
GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
}
} }
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices;
using GraphicsManager.Enums; using GraphicsManager.Enums;
using GraphicsManager.Objects.Core; using GraphicsManager.Objects.Core;
using OpenTK.Mathematics; using OpenTK.Mathematics;
@ -27,7 +28,7 @@ public class ProgressBar<TNumber> : ParentBase where TNumber : INumber<TNumber>
{ {
ProgresRct = new() ProgresRct = new()
{ {
Location = new(DrawingGap.X, DrawingGap.Y, 0), Location = new(DrawingGap.X, DrawingGap.Y),
IgnoreHover = true, IgnoreHover = true,
BackgroundColor = Color4.Green, BackgroundColor = Color4.Green,
Anchor = ObjectAnchor.All Anchor = ObjectAnchor.All
@ -40,7 +41,7 @@ public class ProgressBar<TNumber> : ParentBase where TNumber : INumber<TNumber>
{ {
ProgresRct = new(Progress) ProgresRct = new(Progress)
{ {
Location = new(DrawingGap.X, DrawingGap.Y, 0), Location = new(DrawingGap.X, DrawingGap.Y),
IgnoreHover = true, IgnoreHover = true,
BackgroundColor = Color4.Green, BackgroundColor = Color4.Green,
TextureDisplay = TextureDisplay.ProgressHorizontalCenter, TextureDisplay = TextureDisplay.ProgressHorizontalCenter,
@ -55,7 +56,7 @@ public class ProgressBar<TNumber> : ParentBase where TNumber : INumber<TNumber>
{ {
ProgresRct = new(Background) ProgresRct = new(Background)
{ {
Location = new(DrawingGap.X, DrawingGap.Y, 0), Location = new(DrawingGap.X, DrawingGap.Y),
IgnoreHover = true, IgnoreHover = true,
BackgroundColor = Color4.Green, BackgroundColor = Color4.Green,
TextureDisplay = TextureDisplay.ProgressHorizontalCenter, TextureDisplay = TextureDisplay.ProgressHorizontalCenter,
@ -90,7 +91,7 @@ public class ProgressBar<TNumber> : ParentBase where TNumber : INumber<TNumber>
} }
} }
public override Vector3i Location public override Vector2i Location
{ {
get get
{ {
@ -98,13 +99,13 @@ public class ProgressBar<TNumber> : ParentBase where TNumber : INumber<TNumber>
} }
set set
{ {
Vector3i diff = value - base.Location; Vector2i diff = value - base.Location;
ProgresRct.Location -= diff; ProgresRct.Location -= diff;
base.Location = value; base.Location = value;
} }
} }
private TNumber mpv = TNumber.One, pv = TNumber.Zero; public TNumber mpv = TNumber.One, pv = TNumber.Zero;
public Vector2i ProgressGap = new(0); public Vector2i ProgressGap = new(0);
public Vector4i DrawingGap = new(0); public Vector4i DrawingGap = new(0);
@ -123,6 +124,16 @@ public class ProgressBar<TNumber> : ParentBase where TNumber : INumber<TNumber>
public bool DisallowAboveMax { get; set; } = true; public bool DisallowAboveMax { get; set; } = true;
public void AddAtomic(TNumber value)
{
if (DisallowAboveMax && value > MaxProgressValue) value = MaxProgressValue;
if (typeof(TNumber) == typeof(ulong))
{
Interlocked.Add(ref Unsafe.As<TNumber, ulong>(ref pv), (ulong)(object)value!);
}
if (!UpdateOnDraw) UpdateProgress();
}
public TNumber ProgressValue public TNumber ProgressValue
{ {
get get
@ -186,7 +197,7 @@ public class ProgressBar<TNumber> : ParentBase where TNumber : INumber<TNumber>
var x = GetInternalocation(ProgressValue); var x = GetInternalocation(ProgressValue);
if (ProgresRct.Location.X != DrawingGap.X || ProgresRct.Location.Y != DrawingGap.Y) if (ProgresRct.Location.X != DrawingGap.X || ProgresRct.Location.Y != DrawingGap.Y)
{ {
ProgresRct.Location = new(DrawingGap.X, DrawingGap.Y, 0); ProgresRct.Location = new(DrawingGap.X, DrawingGap.Y);
ProgresRct.Size = new(x, Size.Y - DrawingGap.Y - DrawingGap.W); ProgresRct.Size = new(x, Size.Y - DrawingGap.Y - DrawingGap.W);
} }
else ProgresRct.Size = new(x, ProgresRct.Size.Y); else ProgresRct.Size = new(x, ProgresRct.Size.Y);

View File

@ -19,10 +19,10 @@ public class Rectangle : ITextureObject
public ObjectAnchor Anchor { get; set; } = ObjectAnchor.Left | ObjectAnchor.Top; public ObjectAnchor Anchor { get; set; } = ObjectAnchor.Left | ObjectAnchor.Top;
public Vector3i GetWindowLocation() public Vector2i GetWindowLocation()
{ {
if (!Loaded) return Location; if (!Loaded) return Location;
Vector3i loc = Location; Vector2i loc = Location;
IParent? p = Parent; IParent? p = Parent;
while (p is not null) while (p is not null)
{ {
@ -33,10 +33,10 @@ public class Rectangle : ITextureObject
return loc; return loc;
} }
public Vector3i GetParentLocation(IParent par) public Vector2i GetParentLocation(IParent par)
{ {
if (!Loaded) return Location; if (!Loaded) return Location;
Vector3i loc = Location; Vector2i loc = Location;
IParent? p = Parent; IParent? p = Parent;
while (p is not null && p != par) while (p is not null && p != par)
{ {
@ -101,7 +101,7 @@ public class Rectangle : ITextureObject
} }
public virtual void Draw(int x, int y, int sx, int sy, int sw, int sh) public virtual void DrawBase()
{ {
if (Visible && Loaded && Location.X > 0 - Size.X && Location.Y > 0 - Size.Y) if (Visible && Loaded && Location.X > 0 - Size.X && Location.Y > 0 - Size.Y)
{ {
@ -122,6 +122,11 @@ public class Rectangle : ITextureObject
} }
} }
public virtual void Draw(int x, int y, int sx, int sy, int sw, int sh)
{
DrawBase();
}
public virtual MouseCursor HoverMouse { get; set; } = MouseCursor.Default; public virtual MouseCursor HoverMouse { get; set; } = MouseCursor.Default;
public List<SubHitBox> SubHitBoxes { get; } = new(); public List<SubHitBox> SubHitBoxes { get; } = new();
public event Func<IRenderObject, string[], Task>? FilesDroped; public event Func<IRenderObject, string[], Task>? FilesDroped;
@ -172,7 +177,7 @@ public class Rectangle : ITextureObject
Loaded = true; Loaded = true;
Window.MouseDown += Window_MouseDown; Window.MouseDown += Window_MouseDown;
Window.FileDrop += WindowOnFileDrop; Window.FileDrop += WindowOnFileDrop;
SetLocation(loc_.X, loc_.Y, loc_.Z); SetLocation(loc_.X, loc_.Y);
if (Distance.X == 0 && Distance.Y == 0) ForceDistanceUpdate(Parent); if (Distance.X == 0 && Distance.Y == 0) ForceDistanceUpdate(Parent);
if (WindowLoaded is not null) WindowLoaded.Invoke(this); if (WindowLoaded is not null) WindowLoaded.Invoke(this);
} }
@ -269,8 +274,9 @@ public class Rectangle : ITextureObject
public int BufferObject { get; private set; } public int BufferObject { get; private set; }
public bool IgnoreHover { get; set; } public bool IgnoreHover { get; set; }
public int ArrayObject { get; private set; } public int ArrayObject { get; private set; }
private Vector2i size_ = new(); private Vector2i size_ = new(), loc_;
private Vector3i loc_ = new();
private bool UpdateOnCALL = true;
public float[] Points public float[] Points
{ {
@ -283,23 +289,21 @@ public class Rectangle : ITextureObject
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject); GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
GL.BindVertexArray(ArrayObject); GL.BindVertexArray(ArrayObject);
int add = 3; int NumberOfCords = 2;
if (Textures.Any()) if (Textures.Any())
{ {
add = 5; NumberOfCords = 4;
GL.EnableVertexAttribArray(Textures.First().Location); GL.EnableVertexAttribArray(Textures.First().Location);
GL.VertexAttribPointer(Textures.First().Location, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); GL.VertexAttribPointer(Textures.First().Location, 2, VertexAttribPointerType.Float, false, NumberOfCords * sizeof(float), 2 * sizeof(float));
if (PrintPoints) EXT.PrintArray(value, "Points", 5);
} }
else if (PrintPoints) EXT.PrintArray(value, "Points", 3); GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, NumberOfCords * sizeof(float), 0);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, add * sizeof(float), 0);
GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject); GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject);
GL.BufferData(BufferTarget.ArrayBuffer, value.Length * sizeof(float), value, Hint); GL.BufferData(BufferTarget.ArrayBuffer, value.Length * sizeof(float), value, Hint);
GL.BindVertexArray(ArrayObject); GL.BindVertexArray(ArrayObject);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject); GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(ushort), Indexs, Hint); GL.BufferData(BufferTarget.ElementArrayBuffer, Indexs.Length * sizeof(ushort), Indexs, Hint);
if (Window is not null && Window.CanControleUpdate && Loaded) Parent!.TryDraw(); if (Window is not null && Window.CanControleUpdate && Loaded && UpdateOnCALL) Parent!.TryDraw();
} }
} }
@ -352,6 +356,16 @@ public class Rectangle : ITextureObject
if (Parent is null) return; if (Parent is null) return;
if (!IsVisible) return; if (!IsVisible) return;
if (Window is null) return; if (Window is null) return;
if (!Window.UseSubFrames)
{
Parent.TryDraw();
return;
}
if (Window.LastFrameIsResize)
{
Window.TryDraw();
return;
}
if (BackgroundColor.A < 0.98 || !(BlendOverride || !Shader.CanBlend)) if (BackgroundColor.A < 0.98 || !(BlendOverride || !Shader.CanBlend))
{ {
Parent.TryDraw(deapth+1); Parent.TryDraw(deapth+1);
@ -415,10 +429,10 @@ public class Rectangle : ITextureObject
case TextureDisplay.Clamped: case TextureDisplay.Clamped:
Points = new float[] Points = new float[]
{ {
saf.X, laf.Y, 0, Textures[0].MaxText.X, Textures[0].MaxText.Y, saf.X, laf.Y, Textures[0].MaxText.X, Textures[0].MaxText.Y,
saf.X, saf.Y, 0, Textures[0].MaxText.X, 0, saf.X, saf.Y, Textures[0].MaxText.X, 0,
laf.X, saf.Y, 0, 0, 0, laf.X, saf.Y, 0, 0,
laf.X, laf.Y, 0, 0, Textures[0].MaxText.Y, laf.X, laf.Y, 0, Textures[0].MaxText.Y,
}; };
break; break;
case TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter or TextureDisplay.TextureHorizontalCenter: case TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter or TextureDisplay.TextureHorizontalCenter:
@ -433,14 +447,14 @@ public class Rectangle : ITextureObject
} }
Points = new float[] Points = new float[]
{ {
saf.X, laf.Y, 0, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4 saf.X, laf.Y, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4
saf.X, saf.Y, 0, Textures[0].MaxText.X, 0, //9 saf.X, saf.Y, Textures[0].MaxText.X, 0, //9
laf.X, saf.Y, 0, 0, 0, //14 laf.X, saf.Y, 0, 0, //14
laf.X, laf.Y, 0, 0, Textures[0].MaxText.Y, //19 laf.X, laf.Y, 0, Textures[0].MaxText.Y, //19
saf.X - diff, laf.Y, 0, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24
saf.X - diff, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29
laf.X + diff, saf.Y, 0, per, 0, //34 laf.X + diff, saf.Y, per, 0, //34
laf.X + diff, laf.Y, 0, per, Textures[0].MaxText.Y, //39 laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39
}; };
Indexs = new ushort[] Indexs = new ushort[]
{ {
@ -465,22 +479,22 @@ public class Rectangle : ITextureObject
} }
Points = new float[] Points = new float[]
{ {
saf.X, laf.Y, 0, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4 saf.X, laf.Y, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4
saf.X, saf.Y, 0, Textures[0].MaxText.X, 0, //9 saf.X, saf.Y, Textures[0].MaxText.X, 0, //9
laf.X, saf.Y, 0, 0, 0, //14 laf.X, saf.Y, 0, 0, //14
laf.X, laf.Y, 0, 0, Textures[0].MaxText.Y, //19 laf.X, laf.Y, 0, Textures[0].MaxText.Y, //19
saf.X - diff, laf.Y, 0, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24
saf.X - diff, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29
laf.X + diff, saf.Y, 0, per, 0, //34 laf.X + diff, saf.Y, per, 0, //34
laf.X + diff, laf.Y, 0, per, Textures[0].MaxText.Y, //39 laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39
saf.X - diff, laf.Y, 0, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24
saf.X - diff, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29
laf.X + diff, saf.Y, 0, per, 0, //34 laf.X + diff, saf.Y, per, 0, //34
laf.X + diff, laf.Y, 0, per, Textures[0].MaxText.Y, //39 laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39
saf.X - diff, laf.Y, 0, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24
saf.X - diff, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29
laf.X + diff, saf.Y, 0, per, 0, //34 laf.X + diff, saf.Y, per, 0, //34
laf.X + diff, laf.Y, 0, per, Textures[0].MaxText.Y, //39 laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39
}; };
Indexs = new ushort[] Indexs = new ushort[]
{ {
@ -511,15 +525,12 @@ public class Rectangle : ITextureObject
} }
} }
public bool PrintPoints = false; private static void SetPoint(float[] temp, int start, float X, float Y, float Tx, float Ty)
private static void SetPoint(float[] temp, int start, float X, float Y, float Z, float Tx, float Ty)
{ {
temp[start] = X; temp[start] = X;
temp[start + 1] = Y; temp[start + 1] = Y;
temp[start + 2] = Z; temp[start + 2] = Tx;
temp[start + 3] = Tx; temp[start + 3] = Ty;
temp[start + 4] = Ty;
} }
public virtual Vector2i Size public virtual Vector2i Size
@ -542,267 +553,46 @@ public class Rectangle : ITextureObject
{ {
size_.X = w; size_.X = w;
size_.Y = h; size_.Y = h;
if (Window is null || Parent is null) return; UpdateOpenGLCords(true);
Parent.ReportSizeUpdate(this);
float[] temp = Textures.Count == 0
? new float[12]
: TextureDisplay switch
{
TextureDisplay.Clamped => new float[20],
TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter or TextureDisplay.TextureHorizontalCenter => new float[40],
TextureDisplay.Center => new float[80],
_ => new float[20]
};
saf.X = Parent.IntToWindow(w + loc_.X);
saf.Y = Parent.IntToWindow(h + loc_.Y, true);
temp[2] = Location.Z;
temp[(!Textures.Any() ? 5 : 7)] = Location.Z;
temp[(!Textures.Any() ? 8 : 12)] = Location.Z;
temp[(!Textures.Any() ? 11 : 17)] = Location.Z;
temp[0] = saf.X; // top r
temp[1] = laf.Y;
temp[(!Textures.Any()? 3 : 5)] = saf.X; // bot r
temp[(!Textures.Any() ? 4 : 6)] = saf.Y;
temp[(!Textures.Any() ? 6 : 10)] = laf.X;//bot l
temp[(!Textures.Any() ? 7 : 11)] = saf.Y;
temp[(!Textures.Any() ? 9 : 15)] = laf.X;//top l
temp[(!Textures.Any() ? 10 : 16)] = laf.Y;
if (Textures.Count > 0)
{
float diff = Window.IntToWindow(h) + 1;
float per = (float)Textures[0].RawSize!.Value.Y / Textures[0].RawSize!.Value.X;
if (TextureDisplay == TextureDisplay.TextureHorizontalCenter)
diff = Window.IntToWindow(Textures[0].RawSize!.Value.Y);
if (TextureDisplay == TextureDisplay.Center)
{
if (w> Textures[0].RawSize!.Value.X)
diff = (Window.IntToWindow(Textures[0].RawSize!.Value.X) + 1) / 3;
else
diff = (Window.IntToWindow(w) + 1) / 3;
per = Textures[0].MaxText.X / 3;
}
switch (TextureDisplay)
{
case TextureDisplay.Clamped:
temp[3] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y;
break;
case TextureDisplay.HorizontalCenter:
temp[3] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y;
temp[20] = saf.X - diff; // top r
temp[21] = laf.Y;
temp[22] = 0;
temp[23] = Textures[0].MaxText.X - per;
temp[24] = 1;
temp[25] = saf.X - diff; // bot r
temp[26] = saf.Y;
temp[27] = 0;
temp[28] = Textures[0].MaxText.X - per;
temp[29] = 0;
temp[30] = laf.X + diff; // bot l
temp[31] = saf.Y;
temp[32] = 0;
temp[33] = per;
temp[34] = 0;
temp[35] = laf.X + diff; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = per;
temp[39] = 1;
break;
case TextureDisplay.Center:
temp[3] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y;
int dy, dx;
if (h > Textures[0].RawSize!.Value.Y)
dy = Textures[0].RawSize!.Value.Y;
else
dy = h;
if (w > Textures[0].RawSize!.Value.X)
dx = Textures[0].RawSize!.Value.X;
else
dx = w;
if (dy > dx) dy = dx;
else dx = dy;
float diffy = (dy + 1) / (float)3;
diff = (dx + 1) / (float)3;
per = Textures[0].MaxText.X / 3;
SetPoint(temp, 20, temp[0], temp[1] + diffy, temp[2], temp[3], temp[4] - (temp[4]*per));
SetPoint(temp, 25, temp[0], temp[6] - diffy, temp[2], temp[3], temp[4] * per);
SetPoint(temp, 30, temp[5] - diff, temp[6], temp[2], temp[3] - (temp[3]*per), temp[9]);
SetPoint(temp, 35, temp[10] + diff, temp[6], temp[2], temp[3] * per, temp[9]);
SetPoint(temp, 40, temp[10], temp[26], temp[2], temp[13], temp[29]);
SetPoint(temp, 45, temp[10], temp[21], temp[2], temp[13], temp[24]);
SetPoint(temp, 50, temp[35], temp[1], temp[2], temp[38], temp[4]);
SetPoint(temp, 55, temp[30], temp[1], temp[2], temp[33], temp[4]);
SetPoint(temp, 60, temp[30], temp[21], temp[2], temp[33], temp[24]);
SetPoint(temp, 65, temp[30], temp[26], temp[2], temp[33], temp[29]);
SetPoint(temp, 70, temp[35], temp[26], temp[2], temp[38], temp[29]);
SetPoint(temp, 75, temp[35], temp[21], temp[2], temp[38], temp[24]);
break;
case TextureDisplay.ProgressHorizontalCenter:
if (w > h)
{
if (w > h+ h)
{
temp[3] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y;
temp[20] = saf.X - diff; // top r
temp[21] = laf.Y;
temp[22] = 0;
temp[23] = Textures[0].MaxText.X - per;
temp[24] = 1;
temp[25] = saf.X - diff; // bot r
temp[26] = saf.Y;
temp[27] = 0;
temp[28] = 1 - per;
temp[29] = 0;
temp[30] = laf.X + diff; // bot l
temp[31] = saf.Y;
temp[32] = 0;
temp[33] = per;
temp[34] = 0;
temp[35] = laf.X + diff; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = per;
temp[39] = 1;
}
else
{
temp[3] = (0.666666f + (((w - h) / (float)h)* per)) * Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y;
temp[8] = temp[3];
temp[19] = Textures[0].MaxText.Y;
//start last 33% of texture
temp[20] = saf.X; // top r
temp[21] = laf.Y;
temp[22] = 0;
temp[23] = temp[3];
temp[24] = 1;
temp[25] = saf.X; // bot r
temp[26] = saf.Y;
temp[27] = 0;
temp[28] = temp[3];
temp[29] = 0;
temp[30] = laf.X + diff; // bot l
temp[31] = saf.Y;
temp[32] = 0;
temp[33] = per;
temp[34] = 0;
temp[35] = laf.X + diff; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = per;
temp[39] = 1;
}
}
else
{
//first 33% of texture
temp[3] = ((w/(float)h)*per);
temp[4] = Textures[0].MaxText.Y;
temp[8] = temp[3];
temp[19] = Textures[0].MaxText.Y;
temp[20] = saf.X; // top r
temp[21] = laf.Y;
temp[22] = 0;
temp[23] = temp[3];
temp[24] = Textures[0].MaxText.Y;
temp[25] = saf.X; // bot r
temp[26] = saf.Y;
temp[27] = 0;
temp[28] = temp[3];
temp[29] = 0;
temp[30] = saf.X; // bot l
temp[31] = saf.Y;
temp[32] = 0;
temp[33] = temp[3];
temp[34] = 0;
temp[35] = saf.X; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = temp[3];
temp[39] = Textures[0].MaxText.Y;
}
break;
}
}
Points = temp;
temp = Array.Empty<float>();
if (SizeChanged is not null) SizeChanged.Invoke(this); if (SizeChanged is not null) SizeChanged.Invoke(this);
} }
public virtual void SetLocation(int x, int y)
{
SetLocation(x, y, Location.Z);
}
public virtual void SetLocation(int xy) public virtual void SetLocation(int xy)
{ {
SetLocation(xy, xy, 0); SetLocation(xy, xy);
} }
public virtual void SetLocation(int x, int y, int z) public virtual void SetLocation(int x, int y)
{ {
loc_.X = x; loc_.X = x;
loc_.Y = y; loc_.Y = y;
loc_.Z = z; UpdateOpenGLCords(true);
}
public virtual void UpdateOpenGLCords(bool draw = false)
{
if (Window is null || Parent is null) return; if (Window is null || Parent is null) return;
float[] temp = Textures.Count == 0 float[] temp = Textures.Count == 0
? new float[12] ? new float[8]
: TextureDisplay switch : TextureDisplay switch
{ {
TextureDisplay.Clamped => new float[20], TextureDisplay.Clamped => new float[16],
TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter => new float[40], TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter => new float[32],
TextureDisplay.Center => new float[80], TextureDisplay.Center => new float[64],
_ => new float[20] _ => new float[16]
}; };
laf.X = Parent.IntToWindow(x); laf.X = Parent.IntToWindow(loc_.X);
laf.Y = Parent.IntToWindow(y, true); laf.Y = Parent.IntToWindow(loc_.Y, true);
temp[2] = z;
temp[(!Textures.Any() ? 5 : 7)] = z;
temp[(!Textures.Any() ? 8 : 12)] = z;
temp[(!Textures.Any() ? 11 : 17)] = z;
temp[(!Textures.Any() ? 6 : 10)] = laf.X; temp[(!Textures.Any() ? 4 : 8)] = laf.X;
temp[(!Textures.Any() ? 9 : 15)] = laf.X; temp[(!Textures.Any() ? 6 : 12)] = laf.X;
temp[1] = laf.Y; temp[1] = laf.Y;
temp[(!Textures.Any() ? 10 : 16)] = laf.Y; temp[(!Textures.Any() ? 7 : 13)] = laf.Y;
saf.X = Parent.IntToWindow(Size.X + x); saf.X = Parent.IntToWindow(Size.X + loc_.X);
saf.Y = Parent.IntToWindow(Size.Y + y, true); saf.Y = Parent.IntToWindow(Size.Y + loc_.Y, true);
temp[0] = saf.X; temp[0] = saf.X;
temp[(!Textures.Any() ? 3 : 5)] = saf.X; temp[(!Textures.Any() ? 2 : 4)] = saf.X;
temp[(!Textures.Any() ? 4 : 6)] = saf.Y; temp[(!Textures.Any() ? 3 : 5)] = saf.Y;
temp[(!Textures.Any() ? 7 : 11)] = saf.Y; temp[(!Textures.Any() ? 5 : 9)] = saf.Y;
if (Textures.Count > 0) if (Textures.Count > 0)
{ {
Vector2i s = Size; Vector2i s = Size;
@ -819,45 +609,41 @@ public class Rectangle : ITextureObject
switch (TextureDisplay) switch (TextureDisplay)
{ {
case TextureDisplay.Clamped: case TextureDisplay.Clamped:
temp[3] = Textures[0].MaxText.X; temp[2] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y; temp[3] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X; temp[6] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y; temp[15] = Textures[0].MaxText.Y;
break; break;
case TextureDisplay.HorizontalCenter: case TextureDisplay.HorizontalCenter:
temp[3] = Textures[0].MaxText.X; temp[2] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y; temp[3] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X; temp[6] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y; temp[15] = Textures[0].MaxText.Y;
temp[20] = saf.X - diff; // top r temp[16] = saf.X - diff; // top r
temp[21] = laf.Y; temp[17] = laf.Y;
temp[22] = 0; temp[18] = Textures[0].MaxText.X - per;
temp[23] = Textures[0].MaxText.X - per; temp[19] = 1;
temp[24] = 1;
temp[25] = saf.X - diff; // bot r temp[20] = saf.X - diff; // bot r
temp[26] = saf.Y; temp[21] = saf.Y;
temp[22] = Textures[0].MaxText.X - per;
temp[23] = 0;
temp[24] = laf.X + diff; // bot l
temp[25] = saf.Y;
temp[26] = per;
temp[27] = 0; temp[27] = 0;
temp[28] = Textures[0].MaxText.X - per;
temp[29] = 0;
temp[30] = laf.X + diff; // bot l temp[28] = laf.X + diff; // top l
temp[31] = saf.Y; temp[29] = laf.Y;
temp[32] = 0; temp[30] = per;
temp[33] = per; temp[31] = 1;
temp[34] = 0;
temp[35] = laf.X + diff; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = per;
temp[39] = 1;
break; break;
case TextureDisplay.Center: case TextureDisplay.Center:
temp[3] = Textures[0].MaxText.X; temp[2] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y; temp[3] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X; temp[6] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y; temp[15] = Textures[0].MaxText.Y;
int dy, dx; int dy, dx;
if (s.Y > Textures[0].RawSize!.Value.Y) if (s.Y > Textures[0].RawSize!.Value.Y)
@ -875,123 +661,114 @@ public class Rectangle : ITextureObject
float diffy = (dy + 1) / (float)3; float diffy = (dy + 1) / (float)3;
diff = (dx + 1) / (float)3; diff = (dx + 1) / (float)3;
SetPoint(temp, 20, temp[0], temp[1] + diffy, temp[2], temp[3], temp[4] - (temp[4]*per)); SetPoint(temp, 16, temp[0], temp[1] + diffy, temp[2], temp[3] - (temp[3]*per));
SetPoint(temp, 25, temp[0], temp[6] - diffy, temp[2], temp[3], temp[4] * per); SetPoint(temp, 20, temp[0], temp[5] - diffy, temp[2], temp[3] * per);
SetPoint(temp, 30, temp[5] - diff, temp[6], temp[2], temp[3] - (temp[3]*per), temp[9]); SetPoint(temp, 24, temp[4] - diff, temp[5], temp[2] - (temp[2]*per), temp[7]);
SetPoint(temp, 35, temp[10] + diff, temp[6], temp[2], temp[3] * per, temp[9]); SetPoint(temp, 28, temp[8] + diff, temp[5], temp[2] * per, temp[7]);
SetPoint(temp, 40, temp[10], temp[26], temp[2], temp[13], temp[29]); SetPoint(temp, 32, temp[8], temp[21], temp[10], temp[23]);
SetPoint(temp, 45, temp[10], temp[21], temp[2], temp[13], temp[24]); SetPoint(temp, 36, temp[8], temp[17], temp[10], temp[19]);
SetPoint(temp, 50, temp[35], temp[1], temp[2], temp[38], temp[4]); SetPoint(temp, 40, temp[28], temp[1], temp[30], temp[3]);
SetPoint(temp, 55, temp[30], temp[1], temp[2], temp[33], temp[4]); SetPoint(temp, 44, temp[24], temp[1], temp[26], temp[3]);
SetPoint(temp, 60, temp[30], temp[21], temp[2], temp[33], temp[24]); SetPoint(temp, 48, temp[24], temp[17], temp[26], temp[19]);
SetPoint(temp, 65, temp[30], temp[26], temp[2], temp[33], temp[29]); SetPoint(temp, 52, temp[24], temp[21], temp[26], temp[23]);
SetPoint(temp, 70, temp[35], temp[26], temp[2], temp[38], temp[29]); SetPoint(temp, 56, temp[28], temp[21], temp[30], temp[23]);
SetPoint(temp, 75, temp[35], temp[21], temp[2], temp[38], temp[24]); SetPoint(temp, 60, temp[28], temp[17], temp[30], temp[19]);
break; break;
case TextureDisplay.ProgressHorizontalCenter: case TextureDisplay.ProgressHorizontalCenter:
if (s.X > s.Y) if (s.X > s.Y)
{ {
if (s.X > s.Y + s.Y) if (s.X > s.Y + s.Y)
{ {
temp[3] = Textures[0].MaxText.X; temp[2] = Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y; temp[3] = Textures[0].MaxText.Y;
temp[8] = Textures[0].MaxText.X; temp[6] = Textures[0].MaxText.X;
temp[19] = Textures[0].MaxText.Y; temp[15] = Textures[0].MaxText.Y;
temp[20] = saf.X - diff; // top r temp[16] = saf.X - diff; // top r
temp[21] = laf.Y; temp[17] = laf.Y;
temp[22] = 0; temp[18] = Textures[0].MaxText.X - per;
temp[23] = Textures[0].MaxText.X - per; temp[19] = 1;
temp[24] = 1;
temp[25] = saf.X - diff; // bot r temp[20] = saf.X - diff; // bot r
temp[26] = saf.Y; temp[21] = saf.Y;
temp[22] = 1 - per;
temp[23] = 0;
temp[24] = laf.X + diff; // bot l
temp[25] = saf.Y;
temp[26] = per;
temp[27] = 0; temp[27] = 0;
temp[28] = 1 - per;
temp[29] = 0;
temp[30] = laf.X + diff; // bot l temp[28] = laf.X + diff; // top l
temp[31] = saf.Y; temp[29] = laf.Y;
temp[32] = 0; temp[30] = per;
temp[33] = per; temp[31] = 1;
temp[34] = 0;
temp[35] = laf.X + diff; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = per;
temp[39] = 1;
} }
else else
{ {
temp[3] = (0.666666f + (((s.X - s.Y) / (float)s.Y)* per)) * Textures[0].MaxText.X; temp[2] = (0.666666f + (((s.X - s.Y) / (float)s.Y)* per)) * Textures[0].MaxText.X;
temp[4] = Textures[0].MaxText.Y; temp[3] = Textures[0].MaxText.Y;
temp[8] = temp[3]; temp[6] = temp[2];
temp[19] = Textures[0].MaxText.Y; temp[15] = Textures[0].MaxText.Y;
//start last 33% of texture //start last 33% of texture
temp[20] = saf.X; // top r temp[16] = saf.X; // top r
temp[21] = laf.Y; temp[17] = laf.Y;
temp[22] = 0; temp[18] = temp[2];
temp[23] = temp[3]; temp[19] = 1;
temp[24] = 1;
temp[25] = saf.X; // bot r temp[20] = saf.X; // bot r
temp[26] = saf.Y; temp[21] = saf.Y;
temp[22] = temp[2];
temp[23] = 0;
temp[24] = laf.X + diff; // bot l
temp[25] = saf.Y;
temp[26] = per;
temp[27] = 0; temp[27] = 0;
temp[28] = temp[3];
temp[29] = 0;
temp[30] = laf.X + diff; // bot l temp[28] = laf.X + diff; // top l
temp[31] = saf.Y; temp[29] = laf.Y;
temp[32] = 0; temp[30] = per;
temp[33] = per; temp[31] = 1;
temp[34] = 0;
temp[35] = laf.X + diff; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = per;
temp[39] = 1;
} }
} }
else else
{ {
//first 33% of texture //first 33% of texture
temp[3] = ((s.X/(float)s.Y)*per); temp[2] = ((s.X/(float)s.Y)*per);
temp[4] = Textures[0].MaxText.Y; temp[3] = Textures[0].MaxText.Y;
temp[8] = temp[3]; temp[6] = temp[2];
temp[15] = Textures[0].MaxText.Y;
temp[16] = saf.X; // top r
temp[17] = laf.Y;
temp[18] = temp[2];
temp[19] = Textures[0].MaxText.Y; temp[19] = Textures[0].MaxText.Y;
temp[20] = saf.X; // top r
temp[21] = laf.Y;
temp[22] = 0;
temp[23] = temp[3];
temp[24] = Textures[0].MaxText.Y;
temp[25] = saf.X; // bot r temp[20] = saf.X; // bot r
temp[26] = saf.Y; temp[21] = saf.Y;
temp[22] = temp[2];
temp[23] = 0;
temp[24] = saf.X; // bot l
temp[25] = saf.Y;
temp[26] = temp[2];
temp[27] = 0; temp[27] = 0;
temp[28] = temp[3];
temp[29] = 0;
temp[30] = saf.X; // bot l temp[28] = saf.X; // top l
temp[31] = saf.Y; temp[29] = laf.Y;
temp[32] = 0; temp[30] = temp[2];
temp[33] = temp[3]; temp[31] = Textures[0].MaxText.Y;
temp[34] = 0;
temp[35] = saf.X; // top l
temp[36] = laf.Y;
temp[37] = 0;
temp[38] = temp[3];
temp[39] = Textures[0].MaxText.Y;
} }
break; break;
} }
} }
UpdateOnCALL = draw;
Points = temp; Points = temp;
UpdateOnCALL = true;
temp = Array.Empty<float>(); temp = Array.Empty<float>();
} }
public virtual Vector3i Location public virtual Vector2i Location
{ {
get get
{ {
@ -999,7 +776,7 @@ public class Rectangle : ITextureObject
} }
set set
{ {
SetLocation(value.X, value.Y, value.Z); SetLocation(value.X, value.Y);
} }
} }

View File

@ -36,7 +36,7 @@ public class TabControl : ParentBase, IParent
} }
Buttonts.Add(tmp = new RoundedButton(t, TitleFont) Buttonts.Add(tmp = new RoundedButton(t, TitleFont)
{ {
Location = new(locc+ loccc + (TabSpace * (int)loc) + Border, Border, Location.Z), Location = new(locc+ loccc + (TabSpace * (int)loc) + Border, Border),
Text = Title, Text = Title,
Tag = loc, Tag = loc,
FontColor = this.TextColor FontColor = this.TextColor
@ -46,7 +46,7 @@ public class TabControl : ParentBase, IParent
tmp.Clicked += TmpOnClicked; tmp.Clicked += TmpOnClicked;
tmp.Size = new(tmp._label.Size.X + ((TextBorder + 4) * 2), tmp._label.Size.Y + ((TextBorder + 4) * 2)); tmp.Size = new(tmp._label.Size.X + ((TextBorder + 4) * 2), tmp._label.Size.Y + ((TextBorder + 4) * 2));
page.Anchor = ObjectAnchor.All; page.Anchor = ObjectAnchor.All;
page.Location = new(Border, tmp.Location.Y + tmp.Size.Y + TabSpace, page.Location.Z); page.Location = new(Border, tmp.Location.Y + tmp.Size.Y + TabSpace);
page.Size = new(Size.X - Border - Border, Size.Y - page.Location.Y - Border); page.Size = new(Size.X - Border - Border, Size.Y - page.Location.Y - Border);
if (PageIndex != loc) page.Visible = false; if (PageIndex != loc) page.Visible = false;
Controls.Add(page); Controls.Add(page);
@ -64,7 +64,7 @@ public class TabControl : ParentBase, IParent
} }
Buttonts.Add(tmp = new RoundedButton(t, TitleFont) Buttonts.Add(tmp = new RoundedButton(t, TitleFont)
{ {
Location = new(locc+ loccc + (TabSpace * (int)loc) + Border, Border, Location.Z), Location = new(locc+ loccc + (TabSpace * (int)loc) + Border, Border),
Text = Title, Text = Title,
Tag = loc, Tag = loc,
FontColor = this.TextColor, FontColor = this.TextColor,
@ -75,7 +75,7 @@ public class TabControl : ParentBase, IParent
tmp.Clicked += TmpOnClicked; tmp.Clicked += TmpOnClicked;
tmp.Size = new(tmp._label.Size.X + ((TextBorder + 4) * 2), tmp._label.Size.Y + ((TextBorder + 4) * 2)); tmp.Size = new(tmp._label.Size.X + ((TextBorder + 4) * 2), tmp._label.Size.Y + ((TextBorder + 4) * 2));
page.Anchor = ObjectAnchor.All; page.Anchor = ObjectAnchor.All;
page.Location = new(Border, tmp.Location.Y + tmp.Size.Y + TabSpace, page.Location.Z); page.Location = new(Border, tmp.Location.Y + tmp.Size.Y + TabSpace);
page.Size = new(Size.X - Border - Border, Size.Y - page.Location.Y - Border); page.Size = new(Size.X - Border - Border, Size.Y - page.Location.Y - Border);
if (PageIndex != loc) page.Visible = false; if (PageIndex != loc) page.Visible = false;
Controls.Add(page); Controls.Add(page);
@ -157,7 +157,7 @@ public class TabControl : ParentBase, IParent
int sy = (bottom ? Size.Y - Controls[PageIndex].Distance.Y - ly : 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); int sx = (right ? Size.X - Controls[PageIndex].Distance.X - lx : Controls[PageIndex].Size.X);
Controls[PageIndex].Size = new(sx, sy); Controls[PageIndex].Size = new(sx, sy);
Controls[PageIndex].Location = new(lx, ly, Controls[PageIndex].Location.Z); Controls[PageIndex].Location = new(lx, ly);
if (Controls[PageIndex] is IParent parent) if (Controls[PageIndex] is IParent parent)
{ {
parent.ParentResize(); parent.ParentResize();
@ -176,7 +176,7 @@ public class TabControl : ParentBase, IParent
sy = (bottom ? Size.Y - Buttonts[i].Distance.Y - ly : 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); sx = (right ? Size.X - Buttonts[i].Distance.X - lx : Buttonts[i].Size.X);
Buttonts[i].Size = new(sx, sy); Buttonts[i].Size = new(sx, sy);
Buttonts[i].Location = new(lx, ly, Buttonts[i].Location.Z); Buttonts[i].Location = new(lx, ly);
if (Buttonts[i] is IParent parent2) if (Buttonts[i] is IParent parent2)
{ {
parent2.ParentResize(); parent2.ParentResize();

View File

@ -1,5 +1,5 @@
#version 330 #version 330
layout(location = 0) in vec3 aPosition; layout(location = 0) in vec2 aPosition;
layout(location = 1) in vec2 aTexCoord; layout(location = 1) in vec2 aTexCoord;
out vec2 texCoord; out vec2 texCoord;
out vec4 vertexColor; out vec4 vertexColor;
@ -10,6 +10,6 @@ uniform mat4 windowMatrix;
void main(void) void main(void)
{ {
texCoord = aTexCoord; texCoord = aTexCoord;
gl_Position = vec4(aPosition, 1.0) * windowMatrix; gl_Position = vec4(aPosition, 0.0, 1.0) * windowMatrix;
vertexColor = objColor; vertexColor = objColor;
} }

View File

@ -1,5 +1,5 @@
#version 330 #version 330
layout(location = 0) in vec3 aPosition; layout(location = 0) in vec2 aPosition;
layout(location = 1) in vec2 aTexCoord; layout(location = 1) in vec2 aTexCoord;
out vec2 texCoord; out vec2 texCoord;
@ -8,5 +8,5 @@ uniform mat4 windowMatrix;
void main(void) void main(void)
{ {
texCoord = aTexCoord; texCoord = aTexCoord;
gl_Position = vec4(aPosition, 1.0) * windowMatrix; gl_Position = vec4(aPosition, 0.0, 1.0) * windowMatrix;
} }

View File

@ -7,9 +7,12 @@ out vec2 vUV;
uniform mat4 model; uniform mat4 model;
uniform mat4 projection; uniform mat4 projection;
uniform vec2 scale;
uniform vec2 offset;
void main() void main()
{ {
vUV = in_uv.xy; vUV = in_uv.xy;
gl_Position = projection * model * vec4(in_pos.xy, 0.0, 1.0); vec2 scaledPos = in_pos * scale + offset;
gl_Position = projection * model * vec4(scaledPos, 0.0, 1.0);
} }

View File

@ -1,5 +1,5 @@
#version 330 core #version 330 core
layout (location = 0) in vec3 aPos; layout (location = 0) in vec2 aPos;
uniform vec4 objColor; uniform vec4 objColor;
out vec4 vertexColor; out vec4 vertexColor;
@ -7,6 +7,6 @@ uniform mat4 windowMatrix;
void main() void main()
{ {
gl_Position = vec4(aPos, 1.0) * windowMatrix; gl_Position = vec4(aPos, 0.0, 1.0) * windowMatrix;
vertexColor = objColor; vertexColor = objColor;
} }

View File

@ -1,5 +1,5 @@
#version 330 #version 330
layout(location = 0) in vec3 aPosition; layout(location = 0) in vec2 aPosition;
layout(location = 1) in vec2 aTexCoord; layout(location = 1) in vec2 aTexCoord;
out vec2 texCoord; out vec2 texCoord;
@ -8,5 +8,5 @@ uniform mat4 windowMatrix;
void main(void) void main(void)
{ {
texCoord = aTexCoord; texCoord = aTexCoord;
gl_Position = vec4(aPosition, 1.0) * windowMatrix; gl_Position = vec4(aPosition, 0.0, 1.0) * windowMatrix;
} }

View File

@ -82,6 +82,8 @@ public class Window : NativeWindow , IWindow
GL.Enable(EnableCap.ScissorTest); GL.Enable(EnableCap.ScissorTest);
} }
public bool UseSubFrames { get; set; } = false;
private void OnTextInputEvent(TextInputEventArgs obj) private void OnTextInputEvent(TextInputEventArgs obj)
{ {
if (focused is not null) if (focused is not null)
@ -140,7 +142,7 @@ public class Window : NativeWindow , IWindow
} }
public Window() : this(new NativeWindowSettings()) { } public Window() : this(new NativeWindowSettings()) { }
public Vector3i Position { get; } = new(0); public Vector2i Position { get; } = new(0);
public Color4 BackgroundColor { get; set; } = new Color4(0, 0, 0, 255); public Color4 BackgroundColor { get; set; } = new Color4(0, 0, 0, 255);
public ControlList Controls { get; } = new(); public ControlList Controls { get; } = new();
@ -152,7 +154,9 @@ public class Window : NativeWindow , IWindow
return p; return p;
} }
public virtual void ForceUpdate() public bool LastFrameIsResize { get; private set; } = false;
public virtual void ForceUpdate(bool resize = false)
{ {
BlockDraw = true; BlockDraw = true;
for (int i = 0; i < Controls.Length; i++) for (int i = 0; i < Controls.Length; i++)
@ -166,7 +170,7 @@ public class Window : NativeWindow , IWindow
if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; } if (!left && !right) { Controls[i].Anchor |= ObjectAnchor.Left; left = true; }
int lx, ly, sy, sx; int lx, ly, sy, sx;
bool UpdateDistance = false; bool UpdateDistance = false, SizeChanged = false;
if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange) if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange)
{ {
UpdateDistance = true; UpdateDistance = true;
@ -175,12 +179,12 @@ public class Window : NativeWindow , IWindow
} }
else else
{ {
SizeChanged = true;
lx = (left ? Controls[i].Location.X : CS.X - Controls[i].Distance.X - Controls[i].Size.X); lx = (left ? Controls[i].Location.X : CS.X - Controls[i].Distance.X - Controls[i].Size.X);
sx = (right ? CS.X - Controls[i].Distance.X - lx : Controls[i].Size.X); sx = (right ? CS.X - Controls[i].Distance.X - lx : Controls[i].Size.X);
} }
if ((Controls[i].Anchor & ObjectAnchor.PreventHeightChange) == ObjectAnchor.PreventHeightChange) if ((Controls[i].Anchor & ObjectAnchor.PreventHeightChange) == ObjectAnchor.PreventHeightChange)
{ {
UpdateDistance = true;
ly = Controls[i].Location.Y + ((CS.Y - Controls[i].Distance.Y - Controls[i].Size.Y - Controls[i].Location.Y) / 2); ly = Controls[i].Location.Y + ((CS.Y - Controls[i].Distance.Y - Controls[i].Size.Y - Controls[i].Location.Y) / 2);
sy = Controls[i].Size.Y; sy = Controls[i].Size.Y;
} }
@ -190,26 +194,69 @@ public class Window : NativeWindow , IWindow
sy = (bottom ? CS.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y); sy = (bottom ? CS.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y);
} }
if (Controls[i].Size.X != sx && Controls[i].Size.Y != sy)
{
SizeChanged = true;
}
Controls[i].SetSize(sx, sy); Controls[i].SetSize(sx, sy);
Controls[i].SetLocation(lx, ly); Controls[i].SetLocation(lx, ly);
if (UpdateDistance) if (UpdateDistance)
{ {
Controls[i].ForceDistanceUpdate(this); Controls[i].ForceDistanceUpdate(this);
} }
if (Controls[i] is IParent parent) if (Controls[i] is IParent parent && SizeChanged)
{ {
parent.ParentResize(); parent.ParentResize();
} }
} }
DrawFrame();
if (resize) ResizeFrameP1();
else FrameP1();
CheckParent(this);
LastFrameIsResize = true;
BlockDraw = false; BlockDraw = false;
} }
public Matrix4 WindowSizeMatrix { get; set; } public Matrix4 WindowSizeMatrix { get; set; }
public void CopyFromFrontToBack()
{
CopyFromFrontToBack(0, 0, CS.X, CS.Y, 0, 0);
}
public virtual void CopyFromFrontToBack(int x, int y, int width, int height, int NewX, int NewY)
{
int sourceY1 = CS.Y - y - height;
int sourceX2 = x + width;
int sourceY2 = CS.Y - y;
int destY1 = CS.Y - NewY - height;
int destX2 = NewX + width;
int destY2 = destY1 + height;
GL.ReadBuffer(ReadBufferMode.Front);
GL.DrawBuffer(DrawBufferMode.Back);
GL.BlitFramebuffer(
x, sourceY1, sourceX2, sourceY2,
NewX, destY1, destX2, destY2,
ClearBufferMask.ColorBufferBit,
BlitFramebufferFilter.Nearest
);
}
public virtual void ResizeDraw(int x, int y, int sx, int sy, int sw, int sh)
{
}
public int OldHeight { get; }
public int OldWidth { get; }
public virtual void ParentResize() public virtual void ParentResize()
{ {
ForceUpdate(); ForceUpdate(true);
} }
public int Frame { get; protected set; } = 0; public int Frame { get; protected set; } = 0;
@ -290,7 +337,7 @@ public class Window : NativeWindow , IWindow
public IRenderObject? HoveringControl { get; set; } public IRenderObject? HoveringControl { get; set; }
public SubHitBox? HoveringHitBox { get; set; } public SubHitBox? HoveringHitBox { get; set; }
private void WhenMouseMove(MouseMoveEventArgs obj) protected virtual void HoverCheck(MouseMoveEventArgs obj)
{ {
IRenderObject? cb = null; IRenderObject? cb = null;
SubHitBox? cbhb = null; SubHitBox? cbhb = null;
@ -344,14 +391,6 @@ public class Window : NativeWindow , IWindow
cbhb = null; cbhb = null;
CurrentBest = render; CurrentBest = render;
} }
else
{
if (CurrentBest.Location.Z < render.Location.Z)
{
cbhb = null;
CurrentBest = render;
}
}
if (render == CurrentBest && CurrentBest.SubHitBoxes.Count > 0) if (render == CurrentBest && CurrentBest.SubHitBoxes.Count > 0)
{ {
@ -402,6 +441,11 @@ public class Window : NativeWindow , IWindow
} }
} }
private void WhenMouseMove(MouseMoveEventArgs obj)
{
HoverCheck(obj);
}
public void StartRenderAsync() public void StartRenderAsync()
{ {
Thread t = new Thread(_ => StartRender()); Thread t = new Thread(_ => StartRender());
@ -452,21 +496,6 @@ public class Window : NativeWindow , IWindow
invokes.Enqueue(A); invokes.Enqueue(A);
} }
public virtual void LoadControls()
{
IEnumerable<IRenderObject> needload = Controls.Where(a => a.Loaded == false);
if (needload.Any())
{
BlockDraw = true;
foreach (IRenderObject obj in needload)
{
obj.LoadToParent(this, this);
}
BlockDraw = false;
}
}
public virtual void DrawNewFrameToBackBuffer() public virtual void DrawNewFrameToBackBuffer()
{ {
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
@ -478,16 +507,59 @@ public class Window : NativeWindow , IWindow
GL.Clear(ClearBufferMask.ColorBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit);
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)
GL.Scissor(0, 0, CS.X, CS.Y); {
BlockDraw = true;
Controls[i].LoadToParent(this, this);
BlockDraw = false;
}
if (Controls[i].Location.X >= CS.X ||
Controls[i].Location.Y >= CS.Y ||
Controls[i].Location.X + Controls[i].Size.X < 0 ||
Controls[i].Location.Y + Controls[i].Size.Y < 0) continue;
Controls[i].Draw(0,0,0,0,CS.X, CS.Y); Controls[i].Draw(0,0,0,0,CS.X, CS.Y);
if (Controls[i] is IParent) GL.Scissor(0, 0, CS.X, CS.Y);
}
}
public virtual void DrawNewResizeFrameToBackBuffer()
{
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.ClearColor(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
LastSW = CS.X;
LastSH = CS.Y;
GL.Scissor(0,0,CS.X, CS.Y);
GL.Clear(ClearBufferMask.ColorBufferBit);
for (int i = 0; i < Controls.Length; i++)
{
if (!Controls[i].Loaded)
{
BlockDraw = true;
Controls[i].LoadToParent(this, this);
BlockDraw = false;
}
if (Controls[i].Location.X >= CS.X ||
Controls[i].Location.Y >= CS.Y ||
Controls[i].Location.X + Controls[i].Size.X < 0 ||
Controls[i].Location.Y + Controls[i].Size.Y < 0) continue;
if (Controls[i] is IParent pp)
{
pp.ResizeDraw(0,0,0,0,CS.X, CS.Y);
GL.Scissor(0, 0, CS.X, CS.Y);
}
else
{
Controls[i].Draw(0,0,0,0,CS.X, CS.Y);
}
} }
} }
public bool IgnoreVisForChildren { get; set; } public bool IgnoreVisForChildren { get; set; }
public const float alpha = 254f / byte.MaxValue; public const float alpha = 254f / byte.MaxValue;
public virtual void CheckParent(IParent p, IRenderObject c, int xx, Vector3i di) public virtual void CheckParent(IParent p, IRenderObject c, int xx, Vector2i di)
{ {
if (p.IgnoreVisForChildren || p.Controls.Length <= 1 || xx >= p.Controls.Length || !c.Visible || c is ILabel || (c is Rectangle r && r.BackgroundColor.A <= alpha)) return; if (p.IgnoreVisForChildren || p.Controls.Length <= 1 || xx >= p.Controls.Length || !c.Visible || c is ILabel || (c is Rectangle r && r.BackgroundColor.A <= alpha)) return;
for (int i = xx; i > 0; i--) for (int i = xx; i > 0; i--)
@ -512,16 +584,34 @@ public class Window : NativeWindow , IWindow
} }
} }
public virtual void FrameP1()
{
Context.MakeCurrent();
Frame++;
if (LogFrames) Console.WriteLine($"Drawing Frame: {Frame}");
SubFrameCount = 0;
DrawNewFrameToBackBuffer();
Context.SwapBuffers();
}
public virtual void ResizeFrameP1()
{
Context.MakeCurrent();
Frame++;
if (LogFrames) Console.WriteLine($"Drawing Frame: {Frame}");
SubFrameCount = 0;
DrawNewResizeFrameToBackBuffer();
Context.SwapBuffers();
}
public virtual void DrawFrame() public virtual void DrawFrame()
{ {
Context.MakeCurrent(); FrameP1();
Frame++; if (LastFrameIsResize)
if (LogFrames) Console.WriteLine($"Drawing Frame: {Frame}"); {
SubFrameCount = 0; DrawNewFrameToBackBuffer();
LoadControls(); LastFrameIsResize = false;
DrawNewFrameToBackBuffer(); }
Context.SwapBuffers();
DrawNewFrameToBackBuffer();
CheckParent(this); CheckParent(this);
} }
} }