Improving description and measure tools
This commit is contained in:
parent
e3ad343e67
commit
98d994a066
2 changed files with 82 additions and 26 deletions
|
|
@ -34,20 +34,21 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Markdig.Agg;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Font;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.PolygonMesh.Processors;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.DesignTools
|
||||
{
|
||||
[MarkDownDescription("Drag the sphere to the locations you would like to position the description.")]
|
||||
[MarkDownDescription("Drag the sphere to the location you would like to position the description.")]
|
||||
[HideMeterialAndColor]
|
||||
public class DescriptionObject3D : Object3D, IObject3DControlsProvider, IAlwaysEditorDraw, IEditorButtonProvider
|
||||
{
|
||||
|
|
@ -87,6 +88,24 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
[MarkdownString]
|
||||
public string Description { get; set; } = "Type a description in the properties panel";
|
||||
|
||||
public enum Sides
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
public enum Positions
|
||||
{
|
||||
Above,
|
||||
Below
|
||||
}
|
||||
|
||||
[EnumDisplayAttribute(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
|
||||
public Sides Side { get; set; }
|
||||
|
||||
[EnumDisplayAttribute(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
|
||||
public Positions Position { get; set; }
|
||||
|
||||
public override bool Persistable => false;
|
||||
|
||||
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
||||
|
|
@ -169,6 +188,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
if (PositionHasBeenSet)
|
||||
{
|
||||
CreateWidgetIfRequired(controlLayer);
|
||||
markdownWidget.Visible = true;
|
||||
|
||||
var descrpition = Description.Replace("\\n", "\n");
|
||||
if (markdownWidget.Markdown != descrpition)
|
||||
|
|
@ -177,7 +197,22 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
markdownWidget.Width = 100 * GuiWidget.DeviceScale;
|
||||
}
|
||||
|
||||
markdownWidget.Position = screenStart;
|
||||
var pos = screenStart;
|
||||
if (Side == Sides.Right)
|
||||
{
|
||||
pos.X -= markdownWidget.Width;
|
||||
}
|
||||
if (Position == Positions.Below)
|
||||
{
|
||||
pos.Y -= markdownWidget.Height;
|
||||
}
|
||||
markdownWidget.Position = pos;
|
||||
|
||||
var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale);
|
||||
var distBetweenPixelsWorldSpace = controlLayer.World.GetWorldUnitsPerScreenPixelAtPosition(start);
|
||||
var transform = Matrix4X4.CreateScale(distBetweenPixelsWorldSpace) * world.RotationMatrix.Inverted * Matrix4X4.CreateTranslation(start);
|
||||
var theme = ApplicationController.Instance.MenuTheme;
|
||||
graphics2DOpenGL.RenderTransformedPath(transform, new Ellipse(0,0, 5, 5), theme.PrimaryAccentColor, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +221,12 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
if (markdownWidget == null)
|
||||
{
|
||||
var theme = ApplicationController.Instance.MenuTheme;
|
||||
var width = 200 * GuiWidget.DeviceScale;
|
||||
markdownWidget = new MarkdownWidget(theme, true)
|
||||
{
|
||||
HAnchor = HAnchor.Absolute,
|
||||
VAnchor = VAnchor.Fit,
|
||||
Width = 200,
|
||||
Width = width,
|
||||
Height = 100,
|
||||
BackgroundColor = theme.BackgroundColor,
|
||||
BackgroundRadius = new RadiusCorners(3 * GuiWidget.DeviceScale),
|
||||
|
|
@ -201,11 +237,11 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
};
|
||||
|
||||
markdownWidget.Markdown = Description;
|
||||
markdownWidget.Width = 100 * GuiWidget.DeviceScale;
|
||||
markdownWidget.Width = width;
|
||||
|
||||
controlLayer.GuiSurface.AddChild(markdownWidget);
|
||||
|
||||
markdownWidget.AfterDraw += MarkdownWidget_AfterDraw;
|
||||
controlLayer.GuiSurface.AfterDraw += GuiSurface_AfterDraw;
|
||||
|
||||
void MarkdownWidget_MouseDown(object sender, MouseEventArgs e2)
|
||||
{
|
||||
|
|
@ -216,12 +252,15 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
}
|
||||
|
||||
private void MarkdownWidget_AfterDraw(object sender, DrawEventArgs e)
|
||||
private void GuiSurface_AfterDraw(object sender, DrawEventArgs e)
|
||||
{
|
||||
if (!this.Parent.Children.Where(c => c == this).Any())
|
||||
{
|
||||
markdownWidget.Close();
|
||||
markdownWidget.AfterDraw -= MarkdownWidget_AfterDraw;
|
||||
if (sender is GuiWidget guiWidget)
|
||||
{
|
||||
guiWidget.AfterDraw -= GuiSurface_AfterDraw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,6 +272,10 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
StartPosition = new Vector3(-10, 5, 3);
|
||||
PositionHasBeenSet = false;
|
||||
if (markdownWidget != null)
|
||||
{
|
||||
markdownWidget.Visible = false;
|
||||
}
|
||||
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
|
||||
},
|
||||
HelpText = "Reset the position".Localize(),
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Markdig.Agg;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Font;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
|
|
@ -55,7 +53,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
private static Mesh shape = null;
|
||||
private List<IObject3DControl> editorControls = null;
|
||||
private MarkdownWidget markdownWidget;
|
||||
private GuiWidget numberWidget;
|
||||
|
||||
public MeasureToolObject3D()
|
||||
{
|
||||
|
|
@ -189,7 +187,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
true);
|
||||
|
||||
// Restore DepthTest
|
||||
world.Render3DLine(start, end, Color.Black, true, width: GuiWidget.DeviceScale);
|
||||
world.Render3DLine(start,
|
||||
end,
|
||||
Color.Black.WithAlpha(Constants.LineAlpha),
|
||||
true,
|
||||
GuiWidget.DeviceScale,
|
||||
true,
|
||||
true);
|
||||
|
||||
var screenStart = world.GetScreenPosition(start);
|
||||
var screenEnd = world.GetScreenPosition(end);
|
||||
|
|
@ -199,18 +203,23 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
if (PositionsHaveBeenSet)
|
||||
{
|
||||
CreateWidgetIfRequired(controlLayer);
|
||||
markdownWidget.Markdown = Distance.ToString("0.##");
|
||||
markdownWidget.Position = center;
|
||||
numberWidget.Visible = true;
|
||||
numberWidget.Text = Distance.ToString("0.##");
|
||||
numberWidget.Position = center - new Vector2(numberWidget.LocalBounds.Width / 2, numberWidget.LocalBounds.Height / 2);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateWidgetIfRequired(Object3DControlsLayer controlLayer)
|
||||
{
|
||||
if (markdownWidget == null)
|
||||
if (numberWidget == null)
|
||||
{
|
||||
var theme = ApplicationController.Instance.MenuTheme;
|
||||
markdownWidget = new MarkdownWidget(theme, true)
|
||||
numberWidget = new TextWidget(Distance.ToString("0.##"))
|
||||
{
|
||||
TextColor = theme.TextColor,
|
||||
PointSize = 10,
|
||||
Selectable = true,
|
||||
AutoExpandBoundsToText = true,
|
||||
HAnchor = HAnchor.Absolute,
|
||||
VAnchor = VAnchor.Fit,
|
||||
Width = 200,
|
||||
|
|
@ -223,28 +232,28 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
Padding = 5,
|
||||
};
|
||||
|
||||
markdownWidget.Markdown = Distance.ToString("0.##");
|
||||
markdownWidget.Width = 100 * GuiWidget.DeviceScale;
|
||||
controlLayer.GuiSurface.AddChild(numberWidget);
|
||||
|
||||
controlLayer.GuiSurface.AddChild(markdownWidget);
|
||||
controlLayer.GuiSurface.AfterDraw += GuiSurface_AfterDraw;
|
||||
|
||||
markdownWidget.AfterDraw += MarkdownWidget_AfterDraw;
|
||||
|
||||
void MarkdownWidget_MouseDown(object sender, MouseEventArgs e2)
|
||||
void NumberWidget_MouseDown(object sender, MouseEventArgs e2)
|
||||
{
|
||||
controlLayer.Scene.SelectedItem = this;
|
||||
}
|
||||
|
||||
markdownWidget.MouseDown += MarkdownWidget_MouseDown;
|
||||
numberWidget.MouseDown += NumberWidget_MouseDown;
|
||||
}
|
||||
}
|
||||
|
||||
private void MarkdownWidget_AfterDraw(object sender, DrawEventArgs e)
|
||||
private void GuiSurface_AfterDraw(object sender, DrawEventArgs e)
|
||||
{
|
||||
if (!this.Parent.Children.Where(c => c == this).Any())
|
||||
{
|
||||
markdownWidget.Close();
|
||||
markdownWidget.AfterDraw -= MarkdownWidget_AfterDraw;
|
||||
numberWidget.Close();
|
||||
if (sender is GuiWidget guiWidget)
|
||||
{
|
||||
guiWidget.AfterDraw -= GuiSurface_AfterDraw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -257,6 +266,10 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
StartPosition = new Vector3(-10, 5, 3);
|
||||
EndPosition = new Vector3(10, 5, 3);
|
||||
Distance = 0;
|
||||
if (numberWidget != null)
|
||||
{
|
||||
numberWidget.Visible = false;
|
||||
}
|
||||
PositionsHaveBeenSet = false;
|
||||
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue