From 8300b0658f4b423294a50ed61835981191df83db Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Tue, 15 Oct 2019 19:26:58 -0400 Subject: [PATCH] Try to fix some errors --- .../FileFormats/Layout/Common.cs | 28 ++++++++++ .../GUI/BFLYT/LayoutHierarchy.cs | 6 +++ Switch_Toolbox_Library/OpenGL/OpenGLHelper.cs | 53 +++++++++++++++++++ Toolbox/Shader/Layout/Legacy/Bflyt.vert | 5 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 Switch_Toolbox_Library/OpenGL/OpenGLHelper.cs diff --git a/File_Format_Library/FileFormats/Layout/Common.cs b/File_Format_Library/FileFormats/Layout/Common.cs index ce4ac0da..96c1dfe0 100644 --- a/File_Format_Library/FileFormats/Layout/Common.cs +++ b/File_Format_Library/FileFormats/Layout/Common.cs @@ -163,6 +163,34 @@ namespace LayoutBXLYT } } + public void ApplyNewParentTransform() + { + //Get the new transform and apply it + var transform = GetParentTransform(); + // Translate += transform; + } + + public void ResetParentTransform(BasePane newParent) + { + //We need to get the difference in the parent transform and remove it to the current transform of this pane + var transform = GetParentTransform(); + var newParentTransform = newParent.GetParentTransform(); + Translate -= transform; + Translate += newParentTransform; + } + + private Vector3F GetParentTransform() { + return GetParentTransform(Vector3F.Zero); + } + + private Vector3F GetParentTransform(Vector3F translate) + { + if (Parent != null) + return translate += Parent.GetParentTransform(translate); + else + return translate; + } + public void KeepChildrenTransform(float newTransX, float newTransY) { Vector2F distance = new Vector2F(newTransX - Translate.X, newTransY - Translate.Y); diff --git a/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs b/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs index b6988626..d4bbbca9 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs @@ -410,7 +410,9 @@ namespace LayoutBXLYT var upperParentNode = targetNode.Parent; var upperParentPane = upperParentNode.Tag as BasePane; + draggedPane.ResetParentTransform(upperParentPane); draggedPane.Parent = upperParentPane; + upperParentPane.Childern.Add(draggedPane); upperParentNode.Nodes.Add(draggedNode); @@ -419,12 +421,16 @@ namespace LayoutBXLYT else //Set the target node as the parent { var parentPane = targetNode.Tag as BasePane; + draggedPane.ResetParentTransform(parentPane); draggedPane.Parent = parentPane; + parentPane.Childern.Add(draggedPane); targetNode.Nodes.Add(draggedNode); targetNode.Expand(); } + + ParentEditor.UpdateViewport(); } } } diff --git a/Switch_Toolbox_Library/OpenGL/OpenGLHelper.cs b/Switch_Toolbox_Library/OpenGL/OpenGLHelper.cs new file mode 100644 index 00000000..9ab0dc71 --- /dev/null +++ b/Switch_Toolbox_Library/OpenGL/OpenGLHelper.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using System.Drawing; + +namespace Toolbox.Library +{ + public class OpenGLHelper + { + public static Point convertScreenToWorldCoords(int x, int y) + { + int[] viewport = new int[4]; + Matrix4 modelViewMatrix, projectionMatrix; + GL.GetFloat(GetPName.ModelviewMatrix, out modelViewMatrix); + GL.GetFloat(GetPName.ProjectionMatrix, out projectionMatrix); + GL.GetInteger(GetPName.Viewport, viewport); + Vector2 mouse; + mouse.X = x; + mouse.Y = y; + Vector4 vector = UnProject(ref projectionMatrix, modelViewMatrix, new Size(viewport[2], viewport[3]), mouse); + Point coords = new Point((int)vector.X, (int)vector.Y); + return coords; + } + public static Vector4 UnProject(ref Matrix4 projection, Matrix4 view, Size viewport, Vector2 mouse) + { + Vector4 vec; + + vec.X = (2.0f * mouse.X / (float)viewport.Width - 1); + vec.Y = -(2.0f * mouse.Y / (float)viewport.Height - 1); + vec.Z = 0; + vec.W = 1.0f; + + Matrix4 viewInv = Matrix4.Invert(view); + Matrix4 projInv = Matrix4.Invert(projection); + + Vector4.Transform(ref vec, ref projInv, out vec); + Vector4.Transform(ref vec, ref viewInv, out vec); + + if (vec.W > float.Epsilon || vec.W < float.Epsilon) + { + vec.X /= vec.W; + vec.Y /= vec.W; + vec.Z /= vec.W; + } + + return vec; + } + } +} diff --git a/Toolbox/Shader/Layout/Legacy/Bflyt.vert b/Toolbox/Shader/Layout/Legacy/Bflyt.vert index 4e6f2803..d2298416 100644 --- a/Toolbox/Shader/Layout/Legacy/Bflyt.vert +++ b/Toolbox/Shader/Layout/Legacy/Bflyt.vert @@ -1,5 +1,5 @@ uniform vec2 uvScale0; -uniform vec2 uvRotate0; +uniform float uvRotate0; uniform vec2 uvTranslate0; uniform int flipTexture; uniform mat4 rotationMatrix; @@ -53,7 +53,10 @@ void main() gl_FrontColor = gl_Color; vec2 texCoord0 = vec2(0.5, 0.5) + uvScale0 * (gl_MultiTexCoord0.xy + (uvTranslate0 / uvScale0 - 0.5)); texCoord0 = SetTexCoordType(texCoords0GenType, texCoord0); + texCoord0 = rotateUV(texCoord0, radians(-uvRotate0)); gl_TexCoord[0].st = SetFlip(texCoord0); + + gl_Position = gl_ModelViewProjectionMatrix * rotationMatrix * gl_Vertex; } \ No newline at end of file