From ecf4e808ea7fef534c1f5c59977b1c3003b02e0a Mon Sep 17 00:00:00 2001 From: JacobTech Date: Fri, 22 Dec 2023 11:11:51 -0500 Subject: [PATCH] Framework Update A few changes, mostly to update the .NET framework version. --- GraphicsManager/ContextMenu.cs | 2 +- GraphicsManager/Enums/TextureDisplay.cs | 1 + GraphicsManager/GraphicsManager.csproj | 4 +- GraphicsManager/Interfaces/IWindow.cs | 2 + GraphicsManager/Objects/Core/ControlList.cs | 12 +- GraphicsManager/Objects/FlowLayout.cs | 16 +- GraphicsManager/Objects/Rectangle.cs | 170 +++++++++++++++----- GraphicsManager/Objects/TexturedTextBox.cs | 38 +++-- 8 files changed, 177 insertions(+), 68 deletions(-) diff --git a/GraphicsManager/ContextMenu.cs b/GraphicsManager/ContextMenu.cs index d36a968..46cca8b 100644 --- a/GraphicsManager/ContextMenu.cs +++ b/GraphicsManager/ContextMenu.cs @@ -36,7 +36,7 @@ public class ContextMenu : Window BackgroundColor = new(0, 0, 0, 0); } - private Task ItemsOnControlAdded(IRenderObject arg) + private Task ItemsOnControlAdded(int index, IRenderObject arg) { arg.Clicked += ArgOnClicked; this.Context.MakeCurrent(); diff --git a/GraphicsManager/Enums/TextureDisplay.cs b/GraphicsManager/Enums/TextureDisplay.cs index 0ceca19..dc8cdd6 100644 --- a/GraphicsManager/Enums/TextureDisplay.cs +++ b/GraphicsManager/Enums/TextureDisplay.cs @@ -4,6 +4,7 @@ public enum TextureDisplay : byte { Clamped, HorizontalCenter, + TextureHorizontalCenter, VerticalCenter, Center, ProgressHorizontalCenter, diff --git a/GraphicsManager/GraphicsManager.csproj b/GraphicsManager/GraphicsManager.csproj index e225300..bc33c55 100644 --- a/GraphicsManager/GraphicsManager.csproj +++ b/GraphicsManager/GraphicsManager.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable 1.0.0.0 @@ -10,7 +10,7 @@ False https://git.jacobtech.com/JacobTech.com/GraphicsManager git - 1.0.7-alpha48 + 1.0.7-alpha69 diff --git a/GraphicsManager/Interfaces/IWindow.cs b/GraphicsManager/Interfaces/IWindow.cs index 76010b8..8f63143 100644 --- a/GraphicsManager/Interfaces/IWindow.cs +++ b/GraphicsManager/Interfaces/IWindow.cs @@ -24,6 +24,8 @@ public interface IWindow : IParent public string ClipboardString { get; set; } + public string Title { get; set; } + public Vector2 MousePosition { get; set; } public ContextMenu? ActiveMenu { get; set; } diff --git a/GraphicsManager/Objects/Core/ControlList.cs b/GraphicsManager/Objects/Core/ControlList.cs index 4c90ffa..6928fc8 100644 --- a/GraphicsManager/Objects/Core/ControlList.cs +++ b/GraphicsManager/Objects/Core/ControlList.cs @@ -18,7 +18,7 @@ public class ControlList public int Length => _internal.Count; - internal event Func? ControlAdded; + internal event Func? ControlAdded; internal event Func? ControlRemoved; public void Remove(IRenderObject item, bool purge = true) @@ -32,16 +32,22 @@ public class ControlList GC.Collect(); if (ControlRemoved is not null && !Clearing) _ = ControlRemoved.Invoke(); } + + public void MoveControlToEnd(IRenderObject item) + { + _internal.Remove(item); + _internal.Add(item); + } public void Add(IRenderObject item) { - if (ControlAdded is not null) ControlAdded.Invoke(item).Wait(); + if (ControlAdded is not null) ControlAdded.Invoke(_internal.Count, item).Wait(); _internal.Add(item); } public void Insert(int index, IRenderObject item) { - if (ControlAdded is not null) ControlAdded.Invoke(item).Wait(); + if (ControlAdded is not null) ControlAdded.Invoke(index, item).Wait(); _internal.Insert(index, item); } diff --git a/GraphicsManager/Objects/FlowLayout.cs b/GraphicsManager/Objects/FlowLayout.cs index f829a8f..b9a6cf9 100644 --- a/GraphicsManager/Objects/FlowLayout.cs +++ b/GraphicsManager/Objects/FlowLayout.cs @@ -117,9 +117,21 @@ public class FlowLayout : ParentBase return Task.CompletedTask; } - private Task ControlsOnControlAdded(IRenderObject arg) + private Task ControlsOnControlAdded(int index, IRenderObject arg) { - if (Controls.Length > 0) arg.Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y, arg.Location.Z); + if (Controls.Length > 0) + { + if (index < Controls.Length) + { + arg.Location = Controls[index].Location; + Controls[index].Location = new(arg.Location.X, arg.Location.Y + arg.Size.Y, arg.Location.Z); + 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); + } + } + else arg.Location = new(0, Controls[Controls.Length - 1].Location.Y + Controls[Controls.Length - 1].Size.Y, arg.Location.Z); + } else arg.Location = new(0); if (arg is IParent par2) { diff --git a/GraphicsManager/Objects/Rectangle.cs b/GraphicsManager/Objects/Rectangle.cs index eb0bdee..93b62fc 100755 --- a/GraphicsManager/Objects/Rectangle.cs +++ b/GraphicsManager/Objects/Rectangle.cs @@ -1,4 +1,5 @@ -using GraphicsManager.Enums; +using System.Diagnostics; +using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects.Core; using OpenTK.Graphics.OpenGL4; @@ -18,6 +19,34 @@ public class Rectangle : ITextureObject public ObjectAnchor Anchor { get; set; } = ObjectAnchor.Left | ObjectAnchor.Top; + public Vector3i GetWindowLocation() + { + if (!Loaded) return Location; + Vector3i loc = Location; + IParent? p = Parent; + while (p is not null) + { + loc += p.Position; + p = p.Parent; + } + + return loc; + } + + public Vector3i GetParentLocation(IParent par) + { + if (!Loaded) return Location; + Vector3i loc = Location; + IParent? p = Parent; + while (p is not null && p != par) + { + loc += p.Position; + p = p.Parent; + } + + return loc; + } + public List Textures { get; set; } = new(); public ContextMenu? ContextMenu { get; set; } = null; public event Func? FilesDroped; @@ -63,12 +92,13 @@ public class Rectangle : ITextureObject } public Action? OnDrawAction; - public Action? OnDrawExitAction; + //public Action? OnDrawExitAction; public virtual void Draw(int x, int y, int w, int h) { if (Visible && Loaded) { + if (OnDrawAction is not null) OnDrawAction.Invoke(); if (!Window!.Context.IsCurrent) Window.Context.MakeCurrent(); foreach (Texture tex in Textures) { @@ -132,6 +162,17 @@ public class Rectangle : ITextureObject if (WindowLoaded is not null) WindowLoaded.Invoke(this); } + public void TransferOwners(IWindow w, IParent p) + { + if (Parent is not null) + { + Parent.Controls._internal.Remove(this); + Window = w; + Parent = p; + } + p.Controls.Add(this); + } + private void WindowOnFileDrop(FileDropEventArgs obj) { if (!MouseInside) return; @@ -279,12 +320,25 @@ public class Rectangle : ITextureObject default: switch (value) { - case TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter: + 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, + }; + break; + case TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter or TextureDisplay.TextureHorizontalCenter: float per = (float)Textures[0].RawSize!.Value.Y / Textures[0].RawSize!.Value.X; float diff = 0; if (Window is not null) { diff = Window.IntToFloat(Size.Y) + 1; + if (value == TextureDisplay.TextureHorizontalCenter) + { + diff = Window.IntToFloat(Textures[0].RawSize!.Value.Y); + } } Points = new float[] { @@ -326,7 +380,15 @@ public class Rectangle : ITextureObject if (Window is null || Parent is null) return; Parent.ReportSizeUpdate(this); //float[] temp = Points; - float[] temp = Textures.Count == 0 ? new float[12] : (TextureDisplay == TextureDisplay.Center ? new float[20] : new float[40]); + float[] temp = Textures.Count == 0 + ? new float[12] + : TextureDisplay switch + { + TextureDisplay.Clamped => new float[20], + TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter + or TextureDisplay.Center or TextureDisplay.TextureHorizontalCenter => new float[40], + _ => new float[20] + }; saf = new Vector2(Parent.IntToFloat(value.X + loc_.X, false), Parent.IntToFloat(value.Y + loc_.Y, true)); temp[2] = Location.Z; temp[(!Textures.Any() ? 5 : 7)] = Location.Z; @@ -347,8 +409,16 @@ public class Rectangle : ITextureObject Vector2i s = value; float diff = Window.IntToFloat(s.Y) + 1; float per = (float)Textures[0].RawSize!.Value.Y / Textures[0].RawSize!.Value.X; + if (TextureDisplay == TextureDisplay.TextureHorizontalCenter) + diff = Window.IntToFloat(Textures[0].RawSize!.Value.Y); 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; @@ -413,21 +483,21 @@ public class Rectangle : ITextureObject } else { - temp[3] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.X; - temp[4] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.Y; - temp[8] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.X; - temp[19] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.Y; + 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; //start last 33% of texture - temp[20] =laf.X + diff; // top r + temp[20] = saf.X; // top r temp[21] = laf.Y; temp[22] = 0; - temp[23] = per; + temp[23] = temp[3]; temp[24] = 1; - - temp[25] = laf.X + diff; // bot r + + temp[25] = saf.X; // bot r temp[26] = saf.Y; temp[27] = 0; - temp[28] = per; + temp[28] = temp[3]; temp[29] = 0; temp[30] = laf.X + diff; // bot l @@ -446,33 +516,33 @@ public class Rectangle : ITextureObject else { //first 33% of texture - temp[3] = (s.X/(s.Y*3)); + temp[3] = ((s.X/(float)s.Y)*per); temp[4] = Textures[0].MaxText.Y; - temp[8] = (s.X/(s.Y*3)); + temp[8] = temp[3]; temp[19] = Textures[0].MaxText.Y; - temp[20] = laf.X; // top r + temp[20] = saf.X; // top r temp[21] = laf.Y; temp[22] = 0; - temp[23] = (s.X/(s.Y*3)); - temp[24] = 1; + 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] = (s.X/(s.Y*3)); + temp[28] = temp[3]; temp[29] = 0; temp[30] = saf.X; // bot l temp[31] = saf.Y; temp[32] = 0; - temp[33] = (s.X/(s.Y*3)); + temp[33] = temp[3]; temp[34] = 0; - temp[35] = laf.X; // top l + temp[35] = saf.X; // top l temp[36] = laf.Y; temp[37] = 0; - temp[38] = (s.X/(s.Y*3)); - temp[39] = 1; + temp[38] = temp[3]; + temp[39] = Textures[0].MaxText.Y; } break; } @@ -492,7 +562,15 @@ public class Rectangle : ITextureObject { loc_ = value; if (Window is null || Parent is null) return; - float[] temp = Textures.Count == 0 ? new float[12] : (TextureDisplay == TextureDisplay.Center ? new float[20] : new float[40]); + float[] temp = Textures.Count == 0 + ? new float[12] + : TextureDisplay switch + { + TextureDisplay.Clamped => new float[20], + TextureDisplay.HorizontalCenter or TextureDisplay.ProgressHorizontalCenter + or TextureDisplay.Center => new float[40], + _ => new float[20] + }; laf = new Vector2(Parent.IntToFloat(value.X, false), Parent.IntToFloat(value.Y, true)); temp[2] = value.Z; temp[(!Textures.Any() ? 5 : 7)] = value.Z; @@ -515,6 +593,12 @@ public class Rectangle : ITextureObject float per = (float)Textures[0].RawSize!.Value.Y / Textures[0].RawSize!.Value.X; 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; @@ -579,21 +663,21 @@ public class Rectangle : ITextureObject } else { - temp[3] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.X; - temp[4] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.Y; - temp[8] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.X; - temp[19] = (0.666666f + ((s.X - s.Y) / s.Y)) * Textures[0].MaxText.Y; + 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; //start last 33% of texture - temp[20] =laf.X + diff; // top r + temp[20] = saf.X; // top r temp[21] = laf.Y; temp[22] = 0; - temp[23] = per; + temp[23] = temp[3]; temp[24] = 1; - - temp[25] = laf.X + diff; // bot r + + temp[25] = saf.X; // bot r temp[26] = saf.Y; temp[27] = 0; - temp[28] = per; + temp[28] = temp[3]; temp[29] = 0; temp[30] = laf.X + diff; // bot l @@ -612,33 +696,33 @@ public class Rectangle : ITextureObject else { //first 33% of texture - temp[3] = (s.X/(s.Y*3)); + temp[3] = ((s.X/(float)s.Y)*per); temp[4] = Textures[0].MaxText.Y; - temp[8] = (s.X/(s.Y*3)); + temp[8] = temp[3]; temp[19] = Textures[0].MaxText.Y; - temp[20] = laf.X; // top r + temp[20] = saf.X; // top r temp[21] = laf.Y; temp[22] = 0; - temp[23] = (s.X/(s.Y*3)); - temp[24] = 1; + 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] = (s.X/(s.Y*3)); + temp[28] = temp[3]; temp[29] = 0; temp[30] = saf.X; // bot l temp[31] = saf.Y; temp[32] = 0; - temp[33] = (s.X/(s.Y*3)); + temp[33] = temp[3]; temp[34] = 0; - temp[35] = laf.X; // top l + temp[35] = saf.X; // top l temp[36] = laf.Y; temp[37] = 0; - temp[38] = (s.X/(s.Y*3)); - temp[39] = 1; + temp[38] = temp[3]; + temp[39] = Textures[0].MaxText.Y; } break; } diff --git a/GraphicsManager/Objects/TexturedTextBox.cs b/GraphicsManager/Objects/TexturedTextBox.cs index 8758306..e3d93f8 100755 --- a/GraphicsManager/Objects/TexturedTextBox.cs +++ b/GraphicsManager/Objects/TexturedTextBox.cs @@ -13,7 +13,6 @@ public class TexturedTextBox : Rectangle { private Label _label; private Label _watermark; - public ContextMenu? ContextMenu { get; set; } public TextLocation TextLocation { get; set; } = TextLocation.TopLeft; @@ -23,13 +22,15 @@ public class TexturedTextBox : Rectangle base.HoverMouse = MouseCursor.IBeam; _label = new Label(LabelFam) { - HoverMouse = MouseCursor.IBeam + HoverMouse = MouseCursor.IBeam, + IgnoreHover = true }; TextureDisplay = TextureDisplay.HorizontalCenter; _watermark = new(WaterFam) { Color = new(128, 128, 128, 255), - HoverMouse = MouseCursor.IBeam + HoverMouse = MouseCursor.IBeam, + IgnoreHover = true }; } @@ -52,13 +53,15 @@ public class TexturedTextBox : Rectangle base.HoverMouse = MouseCursor.IBeam; _label = new Label(LabelFam) { - HoverMouse = MouseCursor.IBeam + HoverMouse = MouseCursor.IBeam, + IgnoreHover = true }; TextureDisplay = TextureDisplay.HorizontalCenter; _watermark = new(WaterFam) { Color = new(128, 128, 128, 255), - HoverMouse = MouseCursor.IBeam + HoverMouse = MouseCursor.IBeam, + IgnoreHover = true }; } @@ -212,28 +215,29 @@ public class TexturedTextBox : Rectangle { if (!Visible || !Loaded) return; int nx = x, ny = y, nw = w, nh = h; - if (Location.X + Border > nw) + if (Location.X > nw) return; else { - nx += (Location.X + Border); - nw -= (Location.X + Border); - if (Size.X - Border < nw) - nw = Size.X - Border; + nx += Location.X; + nw -= Location.X; + if (Size.X < nw) + nw = Size.X; } - if (Location.Y + Border > nh) + if (Location.Y > nh) return; else { - ny += (Location.Y + Border); - nh -= (Location.Y + Border); - if (Size.Y - Border < nh) - nh = Size.Y - Border; + ny += Location.Y; + nh -= Location.Y; + if (Size.Y < nh) + nh = Size.Y; } - if (nh < 1 || nw < 1) return; - GL.Scissor(nx,ny,nw,nh); + if (nw == 0 || nh == 0) return; + GL.Scissor(nx, Window!.Size.Y - ny - nh, nw, nh); base.Draw(nx,ny,nw,nh); + GL.Scissor(nx, Window!.Size.Y - ny - nh, nw, nh); if (!string.IsNullOrEmpty(_label.Text)) _label.Draw(nx,ny,nw,nh); else _watermark.Draw(nx,ny,nw,nh); }