diff --git a/InspectForm.Designer.cs b/InspectForm.Designer.cs new file mode 100644 index 000000000..191b03347 --- /dev/null +++ b/InspectForm.Designer.cs @@ -0,0 +1,99 @@ +namespace MatterHackers.MatterControl +{ + partial class InspectForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.treeView1 = new System.Windows.Forms.TreeView(); + this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.treeView1); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.propertyGrid1); + this.splitContainer1.Size = new System.Drawing.Size(1426, 972); + this.splitContainer1.SplitterDistance = 886; + this.splitContainer1.TabIndex = 0; + // + // treeView1 + // + this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.treeView1.FullRowSelect = true; + this.treeView1.HideSelection = false; + this.treeView1.Location = new System.Drawing.Point(0, 0); + this.treeView1.Name = "treeView1"; + this.treeView1.Size = new System.Drawing.Size(886, 972); + this.treeView1.TabIndex = 0; + this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); + // + // propertyGrid1 + // + this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill; + this.propertyGrid1.LineColor = System.Drawing.SystemColors.ControlDark; + this.propertyGrid1.Location = new System.Drawing.Point(0, 0); + this.propertyGrid1.Name = "propertyGrid1"; + this.propertyGrid1.Size = new System.Drawing.Size(536, 972); + this.propertyGrid1.TabIndex = 0; + // + // InspectForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1426, 972); + this.Controls.Add(this.splitContainer1); + this.Name = "InspectForm"; + this.Text = "InspectForm"; + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.TreeView treeView1; + private System.Windows.Forms.PropertyGrid propertyGrid1; + } +} \ No newline at end of file diff --git a/InspectForm.cs b/InspectForm.cs new file mode 100644 index 000000000..3a094444e --- /dev/null +++ b/InspectForm.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using MatterHackers.Agg; +using MatterHackers.Agg.UI; +using MatterHackers.VectorMath; + +namespace MatterHackers.MatterControl +{ + public partial class InspectForm : Form + { + private TreeNode activeTreeNode; + private GuiWidget inspectedWidget; + private GuiWidget InspectedWidget + { + get => inspectedWidget; + set + { + if (inspectedWidget != null) + { + inspectedWidget.DebugShowBounds = false; + } + + inspectedWidget = value; + inspectedWidget.DebugShowBounds = true; + + if (inspectedWidget != null) + { + propertyGrid1.SelectedObject = inspectedWidget; + } + + if (activeTreeNode != null) + { + activeTreeNode.Checked = false; + } + + if (treeNodes.TryGetValue(inspectedWidget, out TreeNode treeNode)) + { + treeView1.SelectedNode = treeNode; + activeTreeNode = treeNode; + activeTreeNode.Checked = true; + } + + inspectedWidget.Invalidate(); + } + } + + bool showNamesUnderMouse = true; + + private GuiWidget inspectedSystemWindow; + + private Vector2 mousePosition; + + Dictionary treeNodes = new Dictionary(); + + public InspectForm(GuiWidget inspectionSource) + { + InitializeComponent(); + + inspectionSource.MouseMove += (s, e) => + { + mousePosition = e.Position; + }; + + inspectionSource.AfterDraw += (s, e) => + { + if (showNamesUnderMouse && !inspectionSource.HasBeenClosed) + { + var namedChildren = new List(); + inspectedSystemWindow.FindNamedChildrenRecursive( + "", + namedChildren, + new RectangleDouble(mousePosition.x, mousePosition.y, mousePosition.x + 1, mousePosition.y + 1), + GuiWidget.SearchType.Partial, + allowDisabledOrHidden: false); + + // If the context changed, update the UI + if (namedChildren.LastOrDefault()?.widget is GuiWidget firstUnderMouse + && firstUnderMouse != this.InspectedWidget) + { + RebuildUI(namedChildren); + + this.InspectedWidget = firstUnderMouse; + } + } + }; + + this.inspectedSystemWindow = inspectionSource; + + inspectionSource.Invalidate(); + } + + private void AddItem(GuiWidget widget, string text, TreeNode childNode = null) + { + if (treeNodes.TryGetValue(widget, out TreeNode existingNode)) + { + existingNode.Nodes.Add(childNode); + existingNode.Expand(); + } + else + { + var node = new TreeNode(text) + { + Tag = widget + }; + + if (childNode != null) + { + node.Nodes.Add(childNode); + node.Expand(); + } + treeNodes.Add(widget, node); + + var parent = widget.Parent; + if (parent == null) + { + treeView1.Nodes.Add(node); + } + else + { + AddItem(parent, parent.Text, node); + } + } + } + + public void RebuildUI(List namedChildren) + { + treeView1.Nodes.Clear(); + treeNodes.Clear(); + + treeView1.SuspendLayout(); + + for (int i = 0; i < namedChildren.Count; i++) + { + var child = namedChildren[i]; + AddItem(child.widget, BuildName(child.widget)); + } + + treeView1.ResumeLayout(); + } + + private string BuildName(GuiWidget widget) + { + string nameToWrite = inspectedWidget == widget ? "* " : ""; + if (!string.IsNullOrEmpty(widget.Name)) + { + nameToWrite += $"{widget.GetType().Name} --- {widget.Name}"; + } + else + { + nameToWrite += $"{widget.GetType().Name}"; + } + + return nameToWrite; + } + + int selectionIndex; + + protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e) + { + if (e.KeyCode == System.Windows.Forms.Keys.F2) + { + selectionIndex++; + } + else if (e.KeyCode == System.Windows.Forms.Keys.F2) + { + selectionIndex--; + } + + base.OnKeyDown(e); + } + + private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) + { + this.InspectedWidget = e.Node.Tag as GuiWidget; + } + } +} diff --git a/InspectForm.resx b/InspectForm.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/InspectForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MatterControl.csproj b/MatterControl.csproj index ec741a4f9..b0bd90f89 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -143,6 +143,12 @@ + + Form + + + InspectForm.cs + @@ -490,6 +496,9 @@ config.json + + InspectForm.cs + diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index a61cd961d..7180826d8 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -557,9 +557,6 @@ namespace MatterHackers.MatterControl IsLoading = false; -#if DEBUG - AfterDraw += ShowNamesUnderMouse; -#endif base.OnLoad(args); } @@ -626,14 +623,6 @@ namespace MatterHackers.MatterControl dropWasOnChild = true; } -#if DEBUG - if (showNamesUnderMouse) - { - mousePosition = mouseEvent.Position; - Invalidate(); - } -#endif - if (GuiWidget.DebugBoundsUnderMouse) { Invalidate(); @@ -758,65 +747,8 @@ namespace MatterHackers.MatterControl #endif } - private int extraInfoOffsetFromLast = 0; - private bool showNamesUnderMouse = false; - - private GuiWidget inspectedWidget = null; - #if DEBUG - Vector2 mousePosition; - private void ShowNamesUnderMouse(object sender, DrawEventArgs e) - { - if (showNamesUnderMouse) - { - if (inspectedWidget != null) - { - inspectedWidget.DebugShowBounds = false; - } - - List namedChildren = new List(); - this.FindNamedChildrenRecursive("", namedChildren, new RectangleDouble(mousePosition.x, mousePosition.y, mousePosition.x + 1 , mousePosition.y + 1), SearchType.Partial, allowDisabledOrHidden: false); - - Vector2 start = new Vector2(10, 50); - int lineHeight = 20; - e.graphics2D.FillRectangle(start, start + new Vector2(500, namedChildren.Count * lineHeight), new RGBA_Bytes(RGBA_Bytes.Black, 120)); - - // Make sure we are in range of the current list - extraInfoOffsetFromLast = Math.Max(0, Math.Min(namedChildren.Count - 1, extraInfoOffsetFromLast)); - - for(int i=0; i< namedChildren.Count; i++) - { - var child = namedChildren[i]; - if (i == (namedChildren.Count-1) - extraInfoOffsetFromLast) - { - inspectedWidget = child.widget; - } - - string nameToWrite = inspectedWidget == child.widget ? "* " : ""; - if (child.name != null) - { - nameToWrite += $"{child.widget.GetType().Name} --- {child.name}"; - } - else - { - nameToWrite += $"{child.widget.GetType().Name} -- -"; - } - - if (inspectedWidget == child.widget) - { - nameToWrite += $" | H:{child.widget.HAnchor}, V:{child.widget.VAnchor}"; - } - - e.graphics2D.DrawString(nameToWrite, start.x, start.y, backgroundColor: RGBA_Bytes.White, drawFromHintedCach: true); - start.y += lineHeight; - } - - if (inspectedWidget != null) - { - inspectedWidget.DebugShowBounds = true; - } - } - } + InspectForm inspectForm = null; public override void OnKeyDown(KeyEventArgs keyEvent) { @@ -827,18 +759,20 @@ namespace MatterHackers.MatterControl { if (keyEvent.KeyCode == Keys.F1) { - showNamesUnderMouse = !showNamesUnderMouse; - } - else if (keyEvent.KeyCode == Keys.F2) - { - extraInfoOffsetFromLast++; - } - else if (keyEvent.KeyCode == Keys.F3) - { - extraInfoOffsetFromLast--; + //showNamesUnderMouse = !showNamesUnderMouse; + if (inspectForm == null) + { + inspectForm = new InspectForm(this); + inspectForm.FormClosed += (s, e2) => + { + inspectForm = null; + }; + inspectForm.Show(); + } } } } + #endif public static void CheckKnownAssemblyConditionalCompSymbols() {