From e1490772e30e9271f7d313bd82bdcbe352d0029e Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Tue, 15 Sep 2020 07:56:31 -0700 Subject: [PATCH] Better display of 3d view editor values --- .../CustomWidgets/InlineEditControl.cs | 28 ++++++- .../ScaleControls/ScaleCornerControl.cs | 4 +- .../ScaleControls/ScaleTopControl.cs | 2 +- .../Primitives/MeasureToolObject3D.cs | 76 ++++++++++--------- .../DesignTools/Primitives/SphereObject3D.cs | 6 +- .../TracedPositionObject3DControl.cs | 5 +- .../View3D/Gui3D/MoveInZControl.cs | 2 +- .../View3D/Object3DControlsLayer.cs | 5 +- 8 files changed, 75 insertions(+), 53 deletions(-) diff --git a/MatterControlLib/CustomWidgets/InlineEditControl.cs b/MatterControlLib/CustomWidgets/InlineEditControl.cs index bf3ad2a43..d7497ff40 100644 --- a/MatterControlLib/CustomWidgets/InlineEditControl.cs +++ b/MatterControlLib/CustomWidgets/InlineEditControl.cs @@ -31,6 +31,7 @@ using System; using System.Diagnostics; using MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; namespace MatterHackers.MatterControl.CustomWidgets { @@ -42,20 +43,39 @@ namespace MatterHackers.MatterControl.CustomWidgets private RunningInterval runningInterval; private ThemeConfig theme; - public InlineEditControl(string defaultSizeString = "-0000.00", Agg.Font.Justification justification = Agg.Font.Justification.Left) + public InlineEditControl(string defaultSizeString = "-0000.00") { theme = AppContext.Theme; base.Visible = false; - double pointSize = 12; + double pointSize = 10; - numberDisplay = new TextWidget(defaultSizeString, 0, 0, pointSize, justification: justification, textColor: theme.TextColor) + this.Padding = new BorderDouble(3); + + numberDisplay = new TextWidget(defaultSizeString, 0, 0, pointSize, justification: Agg.Font.Justification.Center, textColor: theme.TextColor) { Visible = false, VAnchor = VAnchor.Bottom, HAnchor = HAnchor.Left, Text = "0", + AutoExpandBoundsToText = true, }; + + this.BeforeDraw += (s, e) => + { + if (s is GuiWidget widget) + { + var test = true; + if (test) + { + // return; + } + + var bounds = widget.LocalBounds; + e.Graphics2D.Render(new RoundedRect(bounds, 3 * GuiWidget.DeviceScale), theme.BackgroundColor.WithAlpha(200)); + } + }; + AddChild(numberDisplay); numberEdit = new MHNumberEdit(0, theme, pixelWidth: numberDisplay.Width, allowNegatives: true, allowDecimals: true) @@ -68,7 +88,7 @@ namespace MatterHackers.MatterControl.CustomWidgets numberEdit.ActuallNumberEdit.InternalNumberEdit.TextChanged += (s, e) => { numberDisplay.Text = GetDisplayString == null ? "None" : GetDisplayString.Invoke(Value); - base.OnTextChanged(e); + this.OnTextChanged(e); }; numberEdit.ActuallNumberEdit.InternalNumberEdit.MaxDecimalsPlaces = 2; diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs index 2aa9c3c34..f39f61ac5 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs @@ -76,7 +76,7 @@ namespace MatterHackers.Plugins.EditorTools xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, - GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value), + GetDisplayString = (value) => "{0:0.0}".FormatWith(value), }; xValueDisplayInfo.EditComplete += EditComplete; @@ -92,7 +92,7 @@ namespace MatterHackers.Plugins.EditorTools yValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, - GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value) + GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; yValueDisplayInfo.EditComplete += EditComplete; diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs index 8032da0d3..48f2d005f 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs @@ -93,7 +93,7 @@ namespace MatterHackers.Plugins.EditorTools return false; }, - GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value) + GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; zValueDisplayInfo.VisibleChanged += (s, e) => diff --git a/MatterControlLib/DesignTools/Primitives/MeasureToolObject3D.cs b/MatterControlLib/DesignTools/Primitives/MeasureToolObject3D.cs index 8424573c2..8b02f9924 100644 --- a/MatterControlLib/DesignTools/Primitives/MeasureToolObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/MeasureToolObject3D.cs @@ -27,7 +27,6 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; @@ -36,7 +35,6 @@ using System.Threading.Tasks; using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; -using MatterHackers.Agg.VertexSource; using MatterHackers.DataConverters3D; using MatterHackers.Localizations; using MatterHackers.MatterControl.PartPreviewWindow; @@ -51,6 +49,7 @@ namespace MatterHackers.MatterControl.DesignTools public class MeasureToolObject3D : Object3D, IObject3DControlsProvider, IEditorDraw { private static Mesh shape = null; + private List editorControls; public MeasureToolObject3D() { @@ -91,45 +90,50 @@ namespace MatterHackers.MatterControl.DesignTools public List GetObject3DControls(Object3DControlsLayer object3DControlsLayer) { - return new List + if (editorControls == null) { - new TracedPositionObject3DControl(object3DControlsLayer, - this, - () => + editorControls = new List { - return PositionsHaveBeenSet ? StartPosition : StartPosition.Transform(Matrix); - }, - (position) => - { - if (!PositionsHaveBeenSet) + new TracedPositionObject3DControl(object3DControlsLayer, + this, + () => { - PositionsHaveBeenSet = true; - EndPosition = EndPosition.Transform(this.Matrix); - } - - StartPosition = position; - Distance = (StartPosition - EndPosition).Length; - UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues)); - }), - new TracedPositionObject3DControl(object3DControlsLayer, - this, - () => - { - return PositionsHaveBeenSet ? EndPosition : EndPosition.Transform(Matrix); - }, - (position) => - { - if (!PositionsHaveBeenSet) + return PositionsHaveBeenSet ? StartPosition : StartPosition.Transform(Matrix); + }, + (position) => { - PositionsHaveBeenSet = true; - StartPosition = StartPosition.Transform(this.Matrix); - } + if (!PositionsHaveBeenSet) + { + PositionsHaveBeenSet = true; + EndPosition = EndPosition.Transform(this.Matrix); + } - EndPosition = position; - Distance = (StartPosition - EndPosition).Length; - UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues)); - }), - }; + StartPosition = position; + Distance = (StartPosition - EndPosition).Length; + UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues)); + }), + new TracedPositionObject3DControl(object3DControlsLayer, + this, + () => + { + return PositionsHaveBeenSet ? EndPosition : EndPosition.Transform(Matrix); + }, + (position) => + { + if (!PositionsHaveBeenSet) + { + PositionsHaveBeenSet = true; + StartPosition = StartPosition.Transform(this.Matrix); + } + + EndPosition = position; + Distance = (StartPosition - EndPosition).Length; + UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues)); + }), + }; + } + + return editorControls; } public override async void OnInvalidate(InvalidateArgs invalidateType) diff --git a/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs b/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs index d0a96f602..485a90c1c 100644 --- a/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs @@ -122,7 +122,7 @@ namespace MatterHackers.MatterControl.DesignTools return Task.CompletedTask; } - public static Mesh CreateSphere(double diameter = 1, int sides = 30, int latitudeSides = 30, double startingAngle = 0, double endingAngle = MathHelper.Tau) + public static Mesh CreateSphere(double diameter = 1, int sides = 30, int latitudeSides = 30, double startingAngleDeg = 0, double endingAngleDeg = 360) { var path = new VertexStorage(); var angleDelta = MathHelper.Tau / 2 / latitudeSides; @@ -135,8 +135,8 @@ namespace MatterHackers.MatterControl.DesignTools path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle))); } - var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle)); - var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle)); + var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngleDeg)); + var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngleDeg)); var steps = Math.Max(1, (int)(sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5)); return VertexSourceToMesh.Revolve(path, steps, diff --git a/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs b/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs index 6ab6cbcfe..1a93fe904 100644 --- a/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs +++ b/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs @@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl.DesignTools { public class TracedPositionObject3DControl : IObject3DControl { - private readonly double blockSize = 9 * GuiWidget.DeviceScale; + private readonly double blockSize = 11 * GuiWidget.DeviceScale; private ITraceable collisionVolume; private ThemeConfig theme; @@ -65,7 +65,8 @@ namespace MatterHackers.MatterControl.DesignTools this.context = context; this.getPosition = getPosition; this.setPosition = setPosition; - this.shape = PlatonicSolids.CreateCube(); // SphereObject3D.CreateSphere(); + this.shape = PlatonicSolids.CreateCube(); + this.shape = SphereObject3D.CreateSphere(1, 15, 10); collisionVolume = shape.CreateBVHData(); this.owner = owner; } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs index 69a8e121c..d47d54f24 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs @@ -93,7 +93,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow return false; }, - GetDisplayString = (value) => "{0:0.0#}mm".FormatWith(value) + GetDisplayString = (value) => "{0:0.0#}".FormatWith(value) }; zHeightDisplayInfo.VisibleChanged += (s, e) => diff --git a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs index 4887dd7ad..fcda20e8d 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs @@ -909,16 +909,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // Invoke existing IEditorDraw when iterating items if (selectedItem is IEditorDraw editorDraw) { - // TODO: Putting the drawing code in the IObject3D means almost certain bindings to MatterControl in IObject3D. If instead - // we had a UI layer object that used binding to register scene drawing hooks for specific types, we could avoid the bindings editorDraw.DrawEditor(this, transparentMeshes, e); } } foreach (var item in scene.Children) { - if (item.Visible - && (item != selectedItem)) + if (item.Visible) { DrawObject(item, transparentMeshes, e); }