diff --git a/GraphicsManager/FPSWindow.cs b/GraphicsManager/FPSWindow.cs index 00f4282..85db3d0 100755 --- a/GraphicsManager/FPSWindow.cs +++ b/GraphicsManager/FPSWindow.cs @@ -67,15 +67,40 @@ public class FPSWindow : GameWindow , IWindow { TextureManager = TextureManager.GetTextureManager(Context, this); 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.DefaultAlphaShader.ContainsKey(Context)) Rectangle.DefaultAlphaShader.Add(Context, new("AlphaChannel", true, Texture:true)); - if (!Rectangle.DefaultAlphaTextureShader.ContainsKey(Context)) Rectangle.DefaultAlphaTextureShader.Add(Context, new("AlphaChannelTexture", true, Texture:true)); - if (!Label.DefaultTextShader.ContainsKey(Context)) Label.DefaultTextShader.Add(Context, new("Label", 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){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()); last = WindowState; + WindowSizeMatrix = Matrix4.CreateOrthographicOffCenter(0.0f, Size.X, Size.Y, 0, 1, -1); 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 bool fs = false; @@ -125,8 +150,10 @@ public class FPSWindow : GameWindow , IWindow 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 bool LastFrameIsResize { get; private set; } public ControlList Controls { get; } = new(); #region Cool Math Things @@ -209,7 +236,7 @@ public class FPSWindow : GameWindow , IWindow } #endregion - public void ForceUpdate() + public virtual void ForceUpdate(bool resize = false) { BlockDraw = true; 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; if (!top && !bottom) { Controls[i].Anchor |= ObjectAnchor.Top; top = 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 sy = (bottom ? Size.Y - Controls[i].Distance.Y - ly : Controls[i].Size.Y); - int sx = (right ? Size.X - Controls[i].Distance.X - lx : Controls[i].Size.X); - Controls[i].Size = new(sx, sy); - Controls[i].Location = new(lx, ly, Controls[i].Location.Z); - if (Controls[i] is IParent parent) + + int lx, ly, sy, sx; + bool UpdateDistance = false, SizeChanged = false; + if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange) + { + UpdateDistance = true; + 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(); } } + + if (resize) ResizeFrameP1(); + else FrameP1(); + CheckParent(this); + LastFrameIsResize = true; 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() { - 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; @@ -246,13 +386,22 @@ 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) { base.OnResize(e); - if (e.Width == 0 && e.Height == 0 && WindowState != WindowState.Fullscreen) return; - GL.Viewport(0, 0, e.Width, e.Height); - Matrix4.CreateOrthographicOffCenter(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f); + WindowSizeMatrix = Matrix4.CreateOrthographicOffCenter(0.0f, e.Width, e.Height, 0, 1, -1); + GL.Viewport(0, 0, e.Width, e.Height); + CS = e.Size; ParentResize(); } @@ -282,8 +431,14 @@ public class FPSWindow : GameWindow , IWindow public IRenderObject? HoveringControl { get; set; } private void WhenMouseMove(MouseMoveEventArgs obj) + { + HoverCheck(obj); + } + + protected virtual void HoverCheck(MouseMoveEventArgs obj) { IRenderObject? cb = null; + SubHitBox? cbhb = null; IRenderObject? checkcontrol(IRenderObject render, int add_x = 0, int addy = 0, IRenderObject? CurrentBest = null) { 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 || @@ -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); } } + + if (CurrentBest is null) { + cbhb = null; 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; @@ -345,8 +524,23 @@ public class FPSWindow : GameWindow , IWindow else Cursor = HoverMouse; 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 void TryDraw(int depth = 0) @@ -355,15 +549,16 @@ public class FPSWindow : GameWindow , IWindow } 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--) { 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.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.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].NotifiNotVisible(); continue; @@ -374,9 +569,10 @@ public class FPSWindow : GameWindow , IWindow 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()); + if (p.Controls[i] is IParent pp) CheckParent(pp); } } @@ -404,42 +600,56 @@ public class FPSWindow : GameWindow , IWindow 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(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); - GL.Enable(EnableCap.ScissorTest); - - GL.ClearColor(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, (BackgroundColor.A * -1) + 1); + 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); + } + } + + 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()) { for (int i = 0; i < invokes.Count; i++) invokes.Dequeue().Invoke(); } - IEnumerable needload = Controls.Where(a => a.Loaded == false); - - if (needload.Any()) + FrameP1(); + if (LastFrameIsResize) { - BlockDraw = true; - foreach (IRenderObject obj in needload) - { - obj.LoadToParent(this, this); - } - BlockDraw = false; + DrawNewFrameToBackBuffer(); + LastFrameIsResize = false; } - - 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); + CheckParent(this); } } \ No newline at end of file diff --git a/GraphicsManager/GraphicsManager.csproj b/GraphicsManager/GraphicsManager.csproj index d5acd64..c36affd 100644 --- a/GraphicsManager/GraphicsManager.csproj +++ b/GraphicsManager/GraphicsManager.csproj @@ -10,7 +10,7 @@ False https://git.jacobtech.com/JacobTech.com/GraphicsManager git - 1.1.0-alpha98 + 1.1.1-alpha29 diff --git a/GraphicsManager/Interfaces/IParent.cs b/GraphicsManager/Interfaces/IParent.cs index 8913fc8..8aba00d 100755 --- a/GraphicsManager/Interfaces/IParent.cs +++ b/GraphicsManager/Interfaces/IParent.cs @@ -15,7 +15,7 @@ public interface IParent public float IntToWindow(float p, bool Y = false); public void TryDraw(int depth = 0); public void ReportSizeUpdate(IRenderObject Control); - public Vector3i Position { get; } + public Vector2i Position { get; } public MouseCursor HoverMouse { get; set; } public int LastX { get; } public int LastY { get; } @@ -25,4 +25,7 @@ public interface IParent public int LastSH { get; } public bool BlockDraw { 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; } } diff --git a/GraphicsManager/Interfaces/IRenderObject.cs b/GraphicsManager/Interfaces/IRenderObject.cs index 5695e62..2c9c5c1 100755 --- a/GraphicsManager/Interfaces/IRenderObject.cs +++ b/GraphicsManager/Interfaces/IRenderObject.cs @@ -21,13 +21,13 @@ public interface IRenderObject public bool AllowHoverFromBehind { get; set; } public bool Loaded { get; } 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 MouseCursor HoverMouse { get; set; } public void SetSize(int wh); public void SetSize(int w, int h); public void SetLocation(int xy); public void SetLocation(int x, int y); - public void SetLocation(int x, int y, int z); public void Clean(); public void Focus(); public void UnFocus(); @@ -36,7 +36,7 @@ public interface IRenderObject public void SendClipEvent(string Text); public void SendFilesEvent(string[] Files); public Vector2i Size { get; set; } - public Vector3i Location { get; set; } + public Vector2i Location { get; set; } public Vector2 SizeAsFloat { get; } public Vector2 LocationAsFloat { get; } public Vector2i Distance { get; set; } diff --git a/GraphicsManager/Interfaces/IWindow.cs b/GraphicsManager/Interfaces/IWindow.cs index 2326cd4..706e08d 100644 --- a/GraphicsManager/Interfaces/IWindow.cs +++ b/GraphicsManager/Interfaces/IWindow.cs @@ -12,8 +12,11 @@ public interface IWindow : IParent public bool ShowMissingChar { get; } public Matrix4 WindowSizeMatrix { get; } public Vector2i CS { get; } + + public bool LastFrameIsResize { get; } + public bool UseSubFrames { get; set; } - public void CheckParent(IParent p, IRenderObject c, int xx, Vector3i di); + public void CheckParent(IParent p, IRenderObject c, int xx, Vector2i di); public void CheckParent(IParent p); public event Action MouseDown; @@ -47,4 +50,6 @@ public interface IWindow : IParent public bool LogFrames { get; set; } public int SubFrameCount { get; } public int Frame { get; } + public void CopyFromFrontToBack(int x, int y, int width, int height, int NewX, int NewY); + public void CopyFromFrontToBack(); } \ No newline at end of file diff --git a/GraphicsManager/Objects/BetterContextMenu.cs b/GraphicsManager/Objects/BetterContextMenu.cs index 9fe2cb2..06f86ca 100644 --- a/GraphicsManager/Objects/BetterContextMenu.cs +++ b/GraphicsManager/Objects/BetterContextMenu.cs @@ -16,7 +16,7 @@ public class BetterContextMenu : UserControl { mg = value; BlockDraw = true; - fl.Location = new(mg.W, mg.X, Location.Z); + fl.Location = new(mg.W, mg.X); if (AutoSizeWidth || AutoSizeHeight) { int x = 0, y = 0; @@ -82,8 +82,8 @@ public class BetterContextMenu : UserControl 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); - else Location = new((int)ParentWindow.MousePosition.X, (int)ParentWindow.MousePosition.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); Visible = true; TryDraw(); } diff --git a/GraphicsManager/Objects/Core/LabelBase.cs b/GraphicsManager/Objects/Core/LabelBase.cs index 7134fce..de45ac2 100644 --- a/GraphicsManager/Objects/Core/LabelBase.cs +++ b/GraphicsManager/Objects/Core/LabelBase.cs @@ -281,8 +281,8 @@ public class LabelBase : ILabel public FontInteraction Font { get; protected set; } public virtual float Scale { get; set; } = 1.0f; public virtual Vector2i Distance { get; set; } - protected Vector3i loc_; - public virtual Vector3i Location + protected Vector2i loc_; + public virtual Vector2i Location { get { @@ -290,25 +290,19 @@ public class LabelBase : ILabel } set { - SetLocation(value.X, value.Y, value.Z); + SetLocation(value.X, value.Y); } } public virtual void SetLocation(int xy) { - SetLocation(xy, xy, 0); + SetLocation(xy, xy); } - + 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_.Y = y; - loc_.Z = z; if (Window is null || Parent is null) return; if (Window.CanControleUpdate && Loaded) { @@ -316,6 +310,11 @@ public class LabelBase : ILabel if (!Window.Context.IsCurrent) Window.Context.MakeCurrent(); } } + + public virtual void UpdateOpenGLCords(bool draw = false) + { + + } public virtual void SetSize(int wh) { @@ -432,7 +431,9 @@ public class LabelBase : ILabel float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X); 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)); - 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.ActiveTexture((Shader.GetUniformLocation("u_texture") switch @@ -480,11 +481,9 @@ public class LabelBase : ILabel float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale; yrel += hhh; 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.UniformMatrix4(0, false, ref modelM); + + GL.Uniform2(Shader.GetUniformLocation("scale"), w, h); + GL.Uniform2(Shader.GetUniformLocation("offset"), xrel, yrel); ch.Texture.Use(); diff --git a/GraphicsManager/Objects/Core/ParentBase.cs b/GraphicsManager/Objects/Core/ParentBase.cs index 55b1714..cbfbe3b 100644 --- a/GraphicsManager/Objects/Core/ParentBase.cs +++ b/GraphicsManager/Objects/Core/ParentBase.cs @@ -14,16 +14,16 @@ public abstract class ParentBase : Rectangle, IParent } public ControlList Controls { get; } = new(); - public int LastX { get; private set; } - public int LastY { get; private set; } - public int LastSX { get; private set; } - public int LastSY { get; private set; } - public int LastSW { get; private set; } - public int LastSH { get; private set; } + public int LastX { get; protected set; } + public int LastY { get; protected set; } + public int LastSX { get; protected set; } + public int LastSY { get; protected set; } + public int LastSW { get; protected set; } + public int LastSH { get; protected set; } - public Vector3i Position => Location; - - public virtual void ParentResize() + public Vector2i Position => Location; + + public void BaseParentResize() { BlockDraw = true; 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; } int lx, ly, sy, sx; - bool UpdateDistance = false; + bool UpdateDistance = false, SizeChanged = false; if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange) { 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); } - bool mooved = false; if (sx != Controls[i].Size.X || sy != Controls[i].Size.Y) { - mooved = true; + SizeChanged = true; Controls[i].SetSize(sx, sy); } if (lx != Controls[i].Location.X || ly != Controls[i].Location.Y) { - mooved = true; Controls[i].SetLocation(lx, ly); } if (UpdateDistance) { Controls[i].ForceDistanceUpdate(this); } - if (mooved && Controls[i] is IParent parent) + if (SizeChanged && Controls[i] is IParent parent) { parent.ParentResize(); } @@ -85,6 +83,27 @@ public abstract class ParentBase : Rectangle, IParent 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) { @@ -94,74 +113,105 @@ public abstract class ParentBase : Rectangle, IParent { 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(); - return; + 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 < 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); } + } + } + + 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) + { - if (Location.X - sx + x > -1) - { - 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; - } + int nw = Size.X - xx - lw, + nh = Size.Y - xy - lh, + nx = Location.X + xx, + ny = Location.Y + xy; + + if (nx - sx + x > sw || ny - sy + y > sh) + { + if (UpdateBoxInfo) NotifiNotVisible(); + return false; + } - x += Location.X; - y += Location.Y; + 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; + } - if (sw <= 0 || sh <= 0) - { - NotifiNotVisible(); - return; - } - base.Draw(x,y,sx,sy,sw,sh); + x += nx; + y += ny; + + if (sw <= 0 || sh <= 0) + { + if (UpdateBoxInfo) NotifiNotVisible(); + return false; + } + + if (UpdateBoxInfo) + { LastX = x; LastY = y; LastSX = sx; LastSY = sy; LastSW = sw; LastSH = sh; - IEnumerable 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; } @@ -199,22 +249,6 @@ public abstract class ParentBase : Rectangle, IParent 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) { diff --git a/GraphicsManager/Objects/Core/RoundedButton.cs b/GraphicsManager/Objects/Core/RoundedButton.cs index 50b9e09..13f73cd 100644 --- a/GraphicsManager/Objects/Core/RoundedButton.cs +++ b/GraphicsManager/Objects/Core/RoundedButton.cs @@ -30,16 +30,16 @@ public class RoundedButton : Rectangle set { 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; set { 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))); } } diff --git a/GraphicsManager/Objects/FlowLayout.cs b/GraphicsManager/Objects/FlowLayout.cs index 19f5815..98b469a 100644 --- a/GraphicsManager/Objects/FlowLayout.cs +++ b/GraphicsManager/Objects/FlowLayout.cs @@ -65,7 +65,7 @@ public class FlowLayout : ParentBase, IFlow for (int i = Controls.Length - 1; i >= 0; i--) { 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 @@ -77,7 +77,7 @@ public class FlowLayout : ParentBase, IFlow for (int i = 0; i < Controls.Length; i++) { 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) { 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++) { Controls[i].Location += v3i; + if (Controls[i] is IParent p) + { + p.ParentResize(); + } } } else @@ -138,7 +142,7 @@ public class FlowLayout : ParentBase, IFlow bool top = false; 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) { top = true; @@ -158,13 +162,13 @@ public class FlowLayout : ParentBase, IFlow if (index < Controls.Length) { 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++) { - 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); 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 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].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; return Task.CompletedTask; } - public override void ParentResize() - { - //Child objects dont need to be updated - } + + public override void ResizeDraw(int x, int y, int sx, int sy, int sw, int sh) + { + 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) { @@ -213,7 +275,6 @@ public class FlowLayout : ParentBase, IFlow { Controls[i].SetSize(w, Controls[i].Size.Y); } - ParentResize(); if (Parent is not null) Parent.TryDraw(); BlockDraw = false; } @@ -259,7 +320,7 @@ public class FlowLayout : ParentBase, IFlow public event Func? FlowUpdate; - public uint ScrollValue + public virtual uint ScrollValue { get => ScrollValueBackEnd; set @@ -271,7 +332,7 @@ public class FlowLayout : ParentBase, IFlow return; } 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++) { 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 { get diff --git a/GraphicsManager/Objects/Label.cs b/GraphicsManager/Objects/Label.cs index 76d48f0..6b46c2d 100755 --- a/GraphicsManager/Objects/Label.cs +++ b/GraphicsManager/Objects/Label.cs @@ -43,7 +43,9 @@ public class Label : LabelBase float angle_rad = (float)Math.Atan2(DIR.Y, DIR.X); 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)); - 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.ActiveTexture((Shader.GetUniformLocation("u_texture") switch @@ -74,34 +76,33 @@ public class Label : LabelBase _ = Texture.TextureForChar(Window!.Context, Font, c, Shader); } - if (n) - { - hhh += LineHeight; + if (n) + { + hhh += LineHeight; hhh += Font.ExtraLinePixels; - char_x = 0f; - } - else - { + char_x = 0f; + } + else + { if (!_characters[Window!.Context][Font].ContainsKey(c)) continue; Character ch = _characters[Window!.Context][Font][c]; - float w = ch.Size.X * Scale; - float h = ch.Size.Y * Scale; - float xrel = char_x + ch.Bearing.X * Scale; - float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale; - yrel += hhh; - 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)); + float w = ch.Size.X * Scale; + float h = ch.Size.Y * Scale; + float xrel = char_x + ch.Bearing.X * Scale; + float yrel = (ch.Size.Y - ch.Bearing.Y) * Scale; + yrel += hhh; + char_x += (ch.Advance >> 6) * Scale; + + GL.Uniform2(Shader.GetUniformLocation("scale"), w, h); + GL.Uniform2(Shader.GetUniformLocation("offset"), xrel, yrel); + + + ch.Texture.Use(); - Matrix4 modelM = scaleM * transRelM * rotateM * transOriginM; - GL.UniformMatrix4(0, false, ref modelM); - - ch.Texture.Use(); - - GL.DrawArrays(PrimitiveType.Triangles, 0, 6); - } + GL.DrawArrays(PrimitiveType.Triangles, 0, 6); + } } - } + } } } diff --git a/GraphicsManager/Objects/ProgressBar.cs b/GraphicsManager/Objects/ProgressBar.cs index 9364f89..0620027 100644 --- a/GraphicsManager/Objects/ProgressBar.cs +++ b/GraphicsManager/Objects/ProgressBar.cs @@ -1,4 +1,5 @@ using System.Numerics; +using System.Runtime.CompilerServices; using GraphicsManager.Enums; using GraphicsManager.Objects.Core; using OpenTK.Mathematics; @@ -27,7 +28,7 @@ public class ProgressBar : ParentBase where TNumber : INumber { ProgresRct = new() { - Location = new(DrawingGap.X, DrawingGap.Y, 0), + Location = new(DrawingGap.X, DrawingGap.Y), IgnoreHover = true, BackgroundColor = Color4.Green, Anchor = ObjectAnchor.All @@ -40,7 +41,7 @@ public class ProgressBar : ParentBase where TNumber : INumber { ProgresRct = new(Progress) { - Location = new(DrawingGap.X, DrawingGap.Y, 0), + Location = new(DrawingGap.X, DrawingGap.Y), IgnoreHover = true, BackgroundColor = Color4.Green, TextureDisplay = TextureDisplay.ProgressHorizontalCenter, @@ -55,7 +56,7 @@ public class ProgressBar : ParentBase where TNumber : INumber { ProgresRct = new(Background) { - Location = new(DrawingGap.X, DrawingGap.Y, 0), + Location = new(DrawingGap.X, DrawingGap.Y), IgnoreHover = true, BackgroundColor = Color4.Green, TextureDisplay = TextureDisplay.ProgressHorizontalCenter, @@ -90,7 +91,7 @@ public class ProgressBar : ParentBase where TNumber : INumber } } - public override Vector3i Location + public override Vector2i Location { get { @@ -98,13 +99,13 @@ public class ProgressBar : ParentBase where TNumber : INumber } set { - Vector3i diff = value - base.Location; + Vector2i diff = value - base.Location; ProgresRct.Location -= diff; 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 Vector4i DrawingGap = new(0); @@ -122,6 +123,16 @@ public class ProgressBar : ParentBase where TNumber : INumber } 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(ref pv), (ulong)(object)value!); + } + if (!UpdateOnDraw) UpdateProgress(); + } public TNumber ProgressValue { @@ -186,7 +197,7 @@ public class ProgressBar : ParentBase where TNumber : INumber var x = GetInternalocation(ProgressValue); 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); } else ProgresRct.Size = new(x, ProgresRct.Size.Y); diff --git a/GraphicsManager/Objects/Rectangle.cs b/GraphicsManager/Objects/Rectangle.cs index 2b8b97c..cb7190c 100755 --- a/GraphicsManager/Objects/Rectangle.cs +++ b/GraphicsManager/Objects/Rectangle.cs @@ -19,10 +19,10 @@ public class Rectangle : ITextureObject public ObjectAnchor Anchor { get; set; } = ObjectAnchor.Left | ObjectAnchor.Top; - public Vector3i GetWindowLocation() + public Vector2i GetWindowLocation() { if (!Loaded) return Location; - Vector3i loc = Location; + Vector2i loc = Location; IParent? p = Parent; while (p is not null) { @@ -33,10 +33,10 @@ public class Rectangle : ITextureObject return loc; } - public Vector3i GetParentLocation(IParent par) + public Vector2i GetParentLocation(IParent par) { if (!Loaded) return Location; - Vector3i loc = Location; + Vector2i loc = Location; IParent? p = Parent; 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) { @@ -121,6 +121,11 @@ public class Rectangle : ITextureObject GL.DrawElements(PrimitiveType.Triangles, Indexs.Length, DrawElementsType.UnsignedShort, 0); } } + + 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 List SubHitBoxes { get; } = new(); @@ -172,7 +177,7 @@ public class Rectangle : ITextureObject Loaded = true; Window.MouseDown += Window_MouseDown; 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 (WindowLoaded is not null) WindowLoaded.Invoke(this); } @@ -269,8 +274,9 @@ public class Rectangle : ITextureObject public int BufferObject { get; private set; } public bool IgnoreHover { get; set; } public int ArrayObject { get; private set; } - private Vector2i size_ = new(); - private Vector3i loc_ = new(); + private Vector2i size_ = new(), loc_; + + private bool UpdateOnCALL = true; public float[] Points { @@ -283,23 +289,21 @@ public class Rectangle : ITextureObject GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject); GL.BindVertexArray(ArrayObject); - int add = 3; + int NumberOfCords = 2; if (Textures.Any()) { - add = 5; + NumberOfCords = 4; GL.EnableVertexAttribArray(Textures.First().Location); - GL.VertexAttribPointer(Textures.First().Location, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); - if (PrintPoints) EXT.PrintArray(value, "Points", 5); + GL.VertexAttribPointer(Textures.First().Location, 2, VertexAttribPointerType.Float, false, NumberOfCords * sizeof(float), 2 * sizeof(float)); } - else if (PrintPoints) EXT.PrintArray(value, "Points", 3); - GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, add * sizeof(float), 0); + GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, NumberOfCords * sizeof(float), 0); GL.EnableVertexAttribArray(0); GL.BindBuffer(BufferTarget.ArrayBuffer, BufferObject); GL.BufferData(BufferTarget.ArrayBuffer, value.Length * sizeof(float), value, Hint); GL.BindVertexArray(ArrayObject); GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject); 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 (!IsVisible) 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)) { Parent.TryDraw(deapth+1); @@ -415,10 +429,10 @@ public class Rectangle : ITextureObject case TextureDisplay.Clamped: Points = new float[] { - saf.X, laf.Y, 0, Textures[0].MaxText.X, Textures[0].MaxText.Y, - saf.X, saf.Y, 0, Textures[0].MaxText.X, 0, - laf.X, saf.Y, 0, 0, 0, - laf.X, laf.Y, 0, 0, Textures[0].MaxText.Y, + saf.X, laf.Y, Textures[0].MaxText.X, Textures[0].MaxText.Y, + saf.X, saf.Y, Textures[0].MaxText.X, 0, + laf.X, saf.Y, 0, 0, + laf.X, laf.Y, 0, Textures[0].MaxText.Y, }; break; case TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter or TextureDisplay.TextureHorizontalCenter: @@ -433,14 +447,14 @@ public class Rectangle : ITextureObject } Points = new float[] { - saf.X, laf.Y, 0, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4 - saf.X, saf.Y, 0, Textures[0].MaxText.X, 0, //9 - laf.X, saf.Y, 0, 0, 0, //14 - laf.X, laf.Y, 0, 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, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 - laf.X + diff, saf.Y, 0, per, 0, //34 - laf.X + diff, laf.Y, 0, per, Textures[0].MaxText.Y, //39 + saf.X, laf.Y, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4 + saf.X, saf.Y, Textures[0].MaxText.X, 0, //9 + laf.X, saf.Y, 0, 0, //14 + laf.X, laf.Y, 0, Textures[0].MaxText.Y, //19 + saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 + saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29 + laf.X + diff, saf.Y, per, 0, //34 + laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39 }; Indexs = new ushort[] { @@ -465,22 +479,22 @@ public class Rectangle : ITextureObject } Points = new float[] { - saf.X, laf.Y, 0, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4 - saf.X, saf.Y, 0, Textures[0].MaxText.X, 0, //9 - laf.X, saf.Y, 0, 0, 0, //14 - laf.X, laf.Y, 0, 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, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 - laf.X + diff, saf.Y, 0, per, 0, //34 - laf.X + diff, laf.Y, 0, 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, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 - laf.X + diff, saf.Y, 0, per, 0, //34 - laf.X + diff, laf.Y, 0, 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, saf.Y, 0, Textures[0].MaxText.X-per, 0, //29 - laf.X + diff, saf.Y, 0, per, 0, //34 - laf.X + diff, laf.Y, 0, per, Textures[0].MaxText.Y, //39 + saf.X, laf.Y, Textures[0].MaxText.X, Textures[0].MaxText.Y, //4 + saf.X, saf.Y, Textures[0].MaxText.X, 0, //9 + laf.X, saf.Y, 0, 0, //14 + laf.X, laf.Y, 0, Textures[0].MaxText.Y, //19 + saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 + saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29 + laf.X + diff, saf.Y, per, 0, //34 + laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39 + saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 + saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29 + laf.X + diff, saf.Y, per, 0, //34 + laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39 + saf.X - diff, laf.Y, Textures[0].MaxText.X-per, Textures[0].MaxText.Y, //24 + saf.X - diff, saf.Y, Textures[0].MaxText.X-per, 0, //29 + laf.X + diff, saf.Y, per, 0, //34 + laf.X + diff, laf.Y, per, Textures[0].MaxText.Y, //39 }; Indexs = new ushort[] { @@ -510,16 +524,13 @@ public class Rectangle : ITextureObject if (Parent is not null) Parent.TryDraw(); } } - - public bool PrintPoints = false; - private static void SetPoint(float[] temp, int start, float X, float Y, float Z, float Tx, float Ty) + private static void SetPoint(float[] temp, int start, float X, float Y, float Tx, float Ty) { temp[start] = X; temp[start + 1] = Y; - temp[start + 2] = Z; - temp[start + 3] = Tx; - temp[start + 4] = Ty; + temp[start + 2] = Tx; + temp[start + 3] = Ty; } public virtual Vector2i Size @@ -542,267 +553,46 @@ public class Rectangle : ITextureObject { size_.X = w; size_.Y = h; - if (Window is null || Parent is null) return; - 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(); + UpdateOpenGLCords(true); 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) { - 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_.Y = y; - loc_.Z = z; + UpdateOpenGLCords(true); + } + + public virtual void UpdateOpenGLCords(bool draw = false) + { if (Window is null || Parent is null) return; float[] temp = Textures.Count == 0 - ? new float[12] + ? new float[8] : TextureDisplay switch { - TextureDisplay.Clamped => new float[20], - TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter => new float[40], - TextureDisplay.Center => new float[80], - _ => new float[20] + TextureDisplay.Clamped => new float[16], + TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter => new float[32], + TextureDisplay.Center => new float[64], + _ => new float[16] }; - laf.X = Parent.IntToWindow(x); - laf.Y = Parent.IntToWindow(y, true); - temp[2] = z; - temp[(!Textures.Any() ? 5 : 7)] = z; - temp[(!Textures.Any() ? 8 : 12)] = z; - temp[(!Textures.Any() ? 11 : 17)] = z; + laf.X = Parent.IntToWindow(loc_.X); + laf.Y = Parent.IntToWindow(loc_.Y, true); - temp[(!Textures.Any() ? 6 : 10)] = laf.X; - temp[(!Textures.Any() ? 9 : 15)] = laf.X; + temp[(!Textures.Any() ? 4 : 8)] = laf.X; + temp[(!Textures.Any() ? 6 : 12)] = laf.X; temp[1] = laf.Y; - temp[(!Textures.Any() ? 10 : 16)] = laf.Y; - saf.X = Parent.IntToWindow(Size.X + x); - saf.Y = Parent.IntToWindow(Size.Y + y, true); + temp[(!Textures.Any() ? 7 : 13)] = laf.Y; + saf.X = Parent.IntToWindow(Size.X + loc_.X); + saf.Y = Parent.IntToWindow(Size.Y + loc_.Y, true); temp[0] = saf.X; - temp[(!Textures.Any() ? 3 : 5)] = saf.X; - temp[(!Textures.Any() ? 4 : 6)] = saf.Y; - temp[(!Textures.Any() ? 7 : 11)] = saf.Y; + temp[(!Textures.Any() ? 2 : 4)] = saf.X; + temp[(!Textures.Any() ? 3 : 5)] = saf.Y; + temp[(!Textures.Any() ? 5 : 9)] = saf.Y; if (Textures.Count > 0) { Vector2i s = Size; @@ -819,45 +609,41 @@ public class Rectangle : ITextureObject 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; + temp[2] = Textures[0].MaxText.X; + temp[3] = Textures[0].MaxText.Y; + temp[6] = Textures[0].MaxText.X; + temp[15] = 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[2] = Textures[0].MaxText.X; + temp[3] = Textures[0].MaxText.Y; + temp[6] = Textures[0].MaxText.X; + temp[15] = Textures[0].MaxText.Y; + temp[16] = saf.X - diff; // top r + temp[17] = laf.Y; + temp[18] = Textures[0].MaxText.X - per; + temp[19] = 1; - temp[25] = saf.X - diff; // bot r - temp[26] = saf.Y; + temp[20] = saf.X - diff; // bot r + 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[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; + temp[28] = laf.X + diff; // top l + temp[29] = laf.Y; + temp[30] = per; + temp[31] = 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; + temp[2] = Textures[0].MaxText.X; + temp[3] = Textures[0].MaxText.Y; + temp[6] = Textures[0].MaxText.X; + temp[15] = Textures[0].MaxText.Y; int dy, dx; if (s.Y > Textures[0].RawSize!.Value.Y) @@ -875,123 +661,114 @@ public class Rectangle : ITextureObject float diffy = (dy + 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, 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]); + SetPoint(temp, 16, temp[0], temp[1] + diffy, temp[2], temp[3] - (temp[3]*per)); + SetPoint(temp, 20, temp[0], temp[5] - diffy, temp[2], temp[3] * per); + SetPoint(temp, 24, temp[4] - diff, temp[5], temp[2] - (temp[2]*per), temp[7]); + SetPoint(temp, 28, temp[8] + diff, temp[5], temp[2] * per, temp[7]); + SetPoint(temp, 32, temp[8], temp[21], temp[10], temp[23]); + SetPoint(temp, 36, temp[8], temp[17], temp[10], temp[19]); + SetPoint(temp, 40, temp[28], temp[1], temp[30], temp[3]); + SetPoint(temp, 44, temp[24], temp[1], temp[26], temp[3]); + SetPoint(temp, 48, temp[24], temp[17], temp[26], temp[19]); + SetPoint(temp, 52, temp[24], temp[21], temp[26], temp[23]); + SetPoint(temp, 56, temp[28], temp[21], temp[30], temp[23]); + SetPoint(temp, 60, temp[28], temp[17], temp[30], temp[19]); break; case TextureDisplay.ProgressHorizontalCenter: if (s.X > s.Y) { if (s.X > s.Y + s.Y) { - 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[2] = Textures[0].MaxText.X; + temp[3] = Textures[0].MaxText.Y; + temp[6] = Textures[0].MaxText.X; + temp[15] = Textures[0].MaxText.Y; + temp[16] = saf.X - diff; // top r + temp[17] = laf.Y; + temp[18] = Textures[0].MaxText.X - per; + temp[19] = 1; - temp[25] = saf.X - diff; // bot r - temp[26] = saf.Y; + temp[20] = saf.X - diff; // bot r + 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[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; + temp[28] = laf.X + diff; // top l + temp[29] = laf.Y; + temp[30] = per; + temp[31] = 1; } else { - temp[3] = (0.666666f + (((s.X - s.Y) / (float)s.Y)* per)) * Textures[0].MaxText.X; - temp[4] = Textures[0].MaxText.Y; - temp[8] = temp[3]; - temp[19] = Textures[0].MaxText.Y; + temp[2] = (0.666666f + (((s.X - s.Y) / (float)s.Y)* per)) * Textures[0].MaxText.X; + temp[3] = Textures[0].MaxText.Y; + temp[6] = temp[2]; + temp[15] = 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[16] = saf.X; // top r + temp[17] = laf.Y; + temp[18] = temp[2]; + temp[19] = 1; - temp[25] = saf.X; // bot r - temp[26] = saf.Y; + temp[20] = saf.X; // bot r + 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[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; + temp[28] = laf.X + diff; // top l + temp[29] = laf.Y; + temp[30] = per; + temp[31] = 1; } } else { //first 33% of texture - temp[3] = ((s.X/(float)s.Y)*per); - temp[4] = Textures[0].MaxText.Y; - temp[8] = temp[3]; + temp[2] = ((s.X/(float)s.Y)*per); + temp[3] = Textures[0].MaxText.Y; + 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[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[20] = saf.X; // bot r + 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[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; + temp[28] = saf.X; // top l + temp[29] = laf.Y; + temp[30] = temp[2]; + temp[31] = Textures[0].MaxText.Y; } break; } } + + UpdateOnCALL = draw; Points = temp; + UpdateOnCALL = true; temp = Array.Empty(); } - public virtual Vector3i Location + public virtual Vector2i Location { get { @@ -999,7 +776,7 @@ public class Rectangle : ITextureObject } set { - SetLocation(value.X, value.Y, value.Z); + SetLocation(value.X, value.Y); } } diff --git a/GraphicsManager/Objects/TabControl.cs b/GraphicsManager/Objects/TabControl.cs index 71e39c0..aa5041c 100644 --- a/GraphicsManager/Objects/TabControl.cs +++ b/GraphicsManager/Objects/TabControl.cs @@ -36,7 +36,7 @@ public class TabControl : ParentBase, IParent } 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, Tag = loc, FontColor = this.TextColor @@ -46,7 +46,7 @@ public class TabControl : ParentBase, IParent 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.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); if (PageIndex != loc) page.Visible = false; Controls.Add(page); @@ -64,7 +64,7 @@ public class TabControl : ParentBase, IParent } 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, Tag = loc, FontColor = this.TextColor, @@ -75,7 +75,7 @@ public class TabControl : ParentBase, IParent 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.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); if (PageIndex != loc) page.Visible = false; 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 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, Controls[PageIndex].Location.Z); + Controls[PageIndex].Location = new(lx, ly); if (Controls[PageIndex] is IParent parent) { parent.ParentResize(); @@ -176,7 +176,7 @@ public class TabControl : ParentBase, IParent sy = (bottom ? Size.Y - Buttonts[i].Distance.Y - ly : Buttonts[i].Size.Y); sx = (right ? Size.X - Buttonts[i].Distance.X - lx : Buttonts[i].Size.X); Buttonts[i].Size = new(sx, sy); - Buttonts[i].Location = new(lx, ly, Buttonts[i].Location.Z); + Buttonts[i].Location = new(lx, ly); if (Buttonts[i] is IParent parent2) { parent2.ParentResize(); diff --git a/GraphicsManager/Resources/Shaders/AlphaChannel.vert b/GraphicsManager/Resources/Shaders/AlphaChannel.vert index 9d7af87..14d95b0 100755 --- a/GraphicsManager/Resources/Shaders/AlphaChannel.vert +++ b/GraphicsManager/Resources/Shaders/AlphaChannel.vert @@ -1,5 +1,5 @@ #version 330 -layout(location = 0) in vec3 aPosition; +layout(location = 0) in vec2 aPosition; layout(location = 1) in vec2 aTexCoord; out vec2 texCoord; out vec4 vertexColor; @@ -10,6 +10,6 @@ uniform mat4 windowMatrix; void main(void) { texCoord = aTexCoord; - gl_Position = vec4(aPosition, 1.0) * windowMatrix; + gl_Position = vec4(aPosition, 0.0, 1.0) * windowMatrix; vertexColor = objColor; } \ No newline at end of file diff --git a/GraphicsManager/Resources/Shaders/AlphaChannelTexture.vert b/GraphicsManager/Resources/Shaders/AlphaChannelTexture.vert index 652dbab..b248b31 100755 --- a/GraphicsManager/Resources/Shaders/AlphaChannelTexture.vert +++ b/GraphicsManager/Resources/Shaders/AlphaChannelTexture.vert @@ -1,5 +1,5 @@ #version 330 -layout(location = 0) in vec3 aPosition; +layout(location = 0) in vec2 aPosition; layout(location = 1) in vec2 aTexCoord; out vec2 texCoord; @@ -8,5 +8,5 @@ uniform mat4 windowMatrix; void main(void) { texCoord = aTexCoord; - gl_Position = vec4(aPosition, 1.0) * windowMatrix; + gl_Position = vec4(aPosition, 0.0, 1.0) * windowMatrix; } \ No newline at end of file diff --git a/GraphicsManager/Resources/Shaders/Label.vert b/GraphicsManager/Resources/Shaders/Label.vert index f43eb92..3dbb681 100755 --- a/GraphicsManager/Resources/Shaders/Label.vert +++ b/GraphicsManager/Resources/Shaders/Label.vert @@ -7,9 +7,12 @@ out vec2 vUV; uniform mat4 model; uniform mat4 projection; +uniform vec2 scale; +uniform vec2 offset; void main() { 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); } \ No newline at end of file diff --git a/GraphicsManager/Resources/Shaders/Rectangle.vert b/GraphicsManager/Resources/Shaders/Rectangle.vert index f322276..6651477 100755 --- a/GraphicsManager/Resources/Shaders/Rectangle.vert +++ b/GraphicsManager/Resources/Shaders/Rectangle.vert @@ -1,5 +1,5 @@ #version 330 core -layout (location = 0) in vec3 aPos; +layout (location = 0) in vec2 aPos; uniform vec4 objColor; out vec4 vertexColor; @@ -7,6 +7,6 @@ uniform mat4 windowMatrix; void main() { - gl_Position = vec4(aPos, 1.0) * windowMatrix; + gl_Position = vec4(aPos, 0.0, 1.0) * windowMatrix; vertexColor = objColor; } \ No newline at end of file diff --git a/GraphicsManager/Resources/Shaders/RectangleTexture.vert b/GraphicsManager/Resources/Shaders/RectangleTexture.vert index f0d4f75..1667f6f 100755 --- a/GraphicsManager/Resources/Shaders/RectangleTexture.vert +++ b/GraphicsManager/Resources/Shaders/RectangleTexture.vert @@ -1,5 +1,5 @@ #version 330 -layout(location = 0) in vec3 aPosition; +layout(location = 0) in vec2 aPosition; layout(location = 1) in vec2 aTexCoord; out vec2 texCoord; @@ -8,5 +8,5 @@ uniform mat4 windowMatrix; void main(void) { texCoord = aTexCoord; - gl_Position = vec4(aPosition, 1.0) * windowMatrix; + gl_Position = vec4(aPosition, 0.0, 1.0) * windowMatrix; } \ No newline at end of file diff --git a/GraphicsManager/Window.cs b/GraphicsManager/Window.cs index 736ccda..6ecbcad 100755 --- a/GraphicsManager/Window.cs +++ b/GraphicsManager/Window.cs @@ -81,6 +81,8 @@ public class Window : NativeWindow , IWindow GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.ScissorTest); } + + public bool UseSubFrames { get; set; } = false; private void OnTextInputEvent(TextInputEventArgs obj) { @@ -140,7 +142,7 @@ public class Window : NativeWindow , IWindow } 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 ControlList Controls { get; } = new(); @@ -152,7 +154,9 @@ public class Window : NativeWindow , IWindow return p; } - public virtual void ForceUpdate() + public bool LastFrameIsResize { get; private set; } = false; + + public virtual void ForceUpdate(bool resize = false) { BlockDraw = true; 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; } int lx, ly, sy, sx; - bool UpdateDistance = false; + bool UpdateDistance = false, SizeChanged = false; if ((Controls[i].Anchor & ObjectAnchor.PreventWidthChange) == ObjectAnchor.PreventWidthChange) { UpdateDistance = true; @@ -175,12 +179,12 @@ public class Window : NativeWindow , IWindow } 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) { - UpdateDistance = true; 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; } @@ -189,27 +193,70 @@ public class Window : NativeWindow , IWindow 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) + if (Controls[i] is IParent parent && SizeChanged) { parent.ParentResize(); } } - DrawFrame(); + + if (resize) ResizeFrameP1(); + else FrameP1(); + CheckParent(this); + LastFrameIsResize = true; BlockDraw = false; } + 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() { - ForceUpdate(); + ForceUpdate(true); } public int Frame { get; protected set; } = 0; @@ -290,7 +337,7 @@ public class Window : NativeWindow , IWindow public IRenderObject? HoveringControl { get; set; } public SubHitBox? HoveringHitBox { get; set; } - private void WhenMouseMove(MouseMoveEventArgs obj) + protected virtual void HoverCheck(MouseMoveEventArgs obj) { IRenderObject? cb = null; SubHitBox? cbhb = null; @@ -344,14 +391,6 @@ public class Window : NativeWindow , IWindow cbhb = null; CurrentBest = render; } - else - { - if (CurrentBest.Location.Z < render.Location.Z) - { - cbhb = null; - CurrentBest = render; - } - } 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() { Thread t = new Thread(_ => StartRender()); @@ -451,21 +495,6 @@ public class Window : NativeWindow , IWindow { invokes.Enqueue(A); } - - public virtual void LoadControls() - { - IEnumerable 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() { @@ -478,16 +507,59 @@ public class Window : NativeWindow , IWindow GL.Clear(ClearBufferMask.ColorBufferBit); for (int i = 0; i < Controls.Length; i++) { - if (!Controls[i].Loaded) continue; - GL.Scissor(0, 0, CS.X, CS.Y); + 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); + } + } + + 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 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; 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() { - Context.MakeCurrent(); - Frame++; - if (LogFrames) Console.WriteLine($"Drawing Frame: {Frame}"); - SubFrameCount = 0; - LoadControls(); - DrawNewFrameToBackBuffer(); - Context.SwapBuffers(); - DrawNewFrameToBackBuffer(); + FrameP1(); + if (LastFrameIsResize) + { + DrawNewFrameToBackBuffer(); + LastFrameIsResize = false; + } CheckParent(this); } } \ No newline at end of file