improving vector2 control
This commit is contained in:
parent
91734d3f9d
commit
d1beaf9490
6 changed files with 133 additions and 45 deletions
|
|
@ -51,50 +51,90 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
public class PathEditor : IPropertyEditorFactory
|
||||
{
|
||||
private ulong lastRenderHashCode = 0;
|
||||
private Action vertexChanged;
|
||||
private ThemeConfig theme;
|
||||
private VertexStorage vertexStorage;
|
||||
private GuiWidget container;
|
||||
private ImageWidget imageWidget;
|
||||
private Object3D object3D;
|
||||
|
||||
public GuiWidget CreateEditor(PropertyEditor propertyEditor, EditableProperty property, EditorContext context)
|
||||
{
|
||||
if (property.Source is Object3D object3D)
|
||||
{
|
||||
this.object3D = object3D;
|
||||
object3D.Invalidated += RebuildImage;
|
||||
}
|
||||
|
||||
if (property.Value is VertexStorage vertexStorage)
|
||||
{
|
||||
var container = new GuiWidget()
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Stretch,
|
||||
BackgroundOutlineWidth = 1,
|
||||
BackgroundColor = Color.White,
|
||||
BorderColor = Color.Black,
|
||||
Margin = 1,
|
||||
};
|
||||
var wdiget = CreateEditor(vertexStorage, propertyEditor.UndoBuffer, propertyEditor.Theme, VertexBufferChanged);
|
||||
imageWidget.Closed += ImageWidget_Closed;
|
||||
|
||||
var imageWidget = new ImageWidget(100, 200)
|
||||
{
|
||||
AutoResize = true,
|
||||
HAnchor = HAnchor.Center,
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
container.AddChild(imageWidget);
|
||||
|
||||
void RebuildImage(object item, EventArgs e)
|
||||
{
|
||||
imageWidget.Width = container.Width;
|
||||
imageWidget.Height = container.Height;
|
||||
imageWidget.Image.Allocate((int)container.Width, (int)container.Height, 32, new BlenderBGRA());
|
||||
|
||||
var graphics2D = imageWidget.Image.NewGraphics2D();
|
||||
|
||||
var bounds = imageWidget.Image.GetBounds();
|
||||
bounds.Inflate(-1);
|
||||
graphics2D.Rectangle(bounds, Color.Red);
|
||||
|
||||
vertexStorage.RenderCurve(graphics2D, Color.Black, 2, true);
|
||||
}
|
||||
|
||||
container.SizeChanged += RebuildImage;
|
||||
|
||||
return container;
|
||||
return wdiget;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void VertexBufferChanged()
|
||||
{
|
||||
object3D.Invalidate(InvalidateType.Path);
|
||||
}
|
||||
|
||||
private void ImageWidget_Closed(object sender, EventArgs e)
|
||||
{
|
||||
imageWidget.Closed -= ImageWidget_Closed;
|
||||
object3D.Invalidated -= RebuildImage;
|
||||
}
|
||||
|
||||
void RebuildImage(object item, EventArgs e)
|
||||
{
|
||||
imageWidget.Width = container.Width;
|
||||
imageWidget.Height = container.Height;
|
||||
imageWidget.Image.Allocate((int)container.Width, (int)container.Height, 32, new BlenderBGRA());
|
||||
|
||||
var graphics2D = imageWidget.Image.NewGraphics2D();
|
||||
graphics2D.Clear(theme.BackgroundColor);
|
||||
|
||||
var bounds = imageWidget.Image.GetBounds();
|
||||
bounds.Inflate(-1);
|
||||
graphics2D.Rectangle(bounds, theme.PrimaryAccentColor);
|
||||
|
||||
var pathBounds = vertexStorage.GetBounds();
|
||||
|
||||
new VertexSourceApplyTransform(vertexStorage, Affine.NewScaling(1 / pathBounds.Height * bounds.Height)).RenderCurve(graphics2D, theme.TextColor, 2, true, theme.PrimaryAccentColor.Blend(theme.TextColor, .5), theme.PrimaryAccentColor);
|
||||
}
|
||||
|
||||
public GuiWidget CreateEditor(VertexStorage vertexStorage, UndoBuffer undoBuffer, ThemeConfig theme, Action vertexChanged)
|
||||
{
|
||||
this.vertexChanged = vertexChanged;
|
||||
this.theme = theme;
|
||||
this.vertexStorage = vertexStorage;
|
||||
|
||||
container = new GuiWidget()
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Stretch,
|
||||
BackgroundOutlineWidth = 1,
|
||||
BackgroundColor = Color.White,
|
||||
BorderColor = Color.Black,
|
||||
Margin = 1,
|
||||
};
|
||||
|
||||
imageWidget = new ImageWidget(100, 200)
|
||||
{
|
||||
AutoResize = true,
|
||||
HAnchor = HAnchor.Center,
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
container.AddChild(imageWidget);
|
||||
|
||||
container.SizeChanged += RebuildImage;
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
public class RadialPinchObject3D : OperationSourceContainerObject3D, IPropertyGridModifier, IEditorDraw
|
||||
|
|
@ -162,6 +202,19 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return AxisAlignedBoundingBox.CenteredBox(new Vector3(1, 1, sourceAabb.ZSize), center).NewTransformed(this.WorldMatrix());
|
||||
}
|
||||
|
||||
public Vector2 Point1 { get; set; } = new Vector2(0, 0);
|
||||
public Vector2 Point2 {get; set;} = new Vector2(1, 4);
|
||||
public Vector2 Point3 { get; set;} = new Vector2(2, 8);
|
||||
public Vector2 Point4 { get; set;} = new Vector2(3, 12);
|
||||
public Vector2 Point5 { get; set;} = new Vector2(4, 14);
|
||||
public Vector2 Point6 { get; set;} = new Vector2(5, 16);
|
||||
public Vector2 Point7 { get; set;} = new Vector2(6, 18);
|
||||
public Vector2 Point8 { get; set;} = new Vector2(7, 20);
|
||||
public Vector2 Point9 { get; set;} = new Vector2(8, 22);
|
||||
public Vector2 Point10 { get; set;} = new Vector2(9, 24);
|
||||
|
||||
|
||||
|
||||
public override Task Rebuild()
|
||||
{
|
||||
this.DebugDepth("Rebuild");
|
||||
|
|
@ -219,10 +272,10 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
middlePoint.X *= 2;
|
||||
|
||||
PathForHorizontalOffsets.Clear();
|
||||
PathForHorizontalOffsets.MoveTo(bottomPoint);
|
||||
PathForHorizontalOffsets.Curve4(bottomPoint, bottomPoint + new Vector2(.5, .5), middlePoint);
|
||||
PathForHorizontalOffsets.Curve4(middlePoint - new Vector2(0, -1), middlePoint + new Vector2(0, 1), topPoint);
|
||||
PathForHorizontalOffsets.Curve4(topPoint - new Vector2(.5, .5), topPoint, topPoint);
|
||||
PathForHorizontalOffsets.MoveTo(Point1);
|
||||
PathForHorizontalOffsets.Curve4(Point2, Point3, Point4);
|
||||
PathForHorizontalOffsets.Curve4(Point5, Point6, Point7);
|
||||
PathForHorizontalOffsets.Curve4(Point8, Point9, Point10);
|
||||
}
|
||||
|
||||
var horizontalOffset = new FlattenCurves(new VertexSourceApplyTransform(PathForHorizontalOffsets, Affine.NewScaling(10)));
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
};
|
||||
}
|
||||
|
||||
private static void InternalTextEditWidget_KeyDown(object sender, KeyEventArgs e)
|
||||
public static void InternalTextEditWidget_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
var textEditWidget = sender as TextEditWidget;
|
||||
var internalTextEditWidget = textEditWidget.InternalTextEditWidget;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
|
|
@ -82,10 +83,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
this.SetValue(
|
||||
string.Format("{0},{1}", xEditWidget.ActuallNumberEdit.Value.ToString("0.###"), yEditWidget.ActuallNumberEdit.Value.ToString("0.###")),
|
||||
userInitiated: true);
|
||||
userInitiated: true);
|
||||
};
|
||||
|
||||
container.AddChild(xEditWidget);
|
||||
xEditWidget.ActuallNumberEdit.KeyDown += NumberField.InternalTextEditWidget_KeyDown;
|
||||
|
||||
container.AddChild(xEditWidget);
|
||||
|
||||
double.TryParse(xyValueStrings[1], out double currentYValue);
|
||||
|
||||
|
|
@ -102,7 +105,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
userInitiated: true);
|
||||
};
|
||||
|
||||
container.AddChild(yEditWidget);
|
||||
yEditWidget.ActuallNumberEdit.KeyDown += NumberField.InternalTextEditWidget_KeyDown;
|
||||
|
||||
container.AddChild(yEditWidget);
|
||||
|
||||
this.Content = container;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3805,6 +3805,36 @@ Translated:Plug in printer USB cable and turn printer on
|
|||
English:Plugins
|
||||
Translated:Plugins
|
||||
|
||||
English:Point 1
|
||||
Translated:Point 1
|
||||
|
||||
English:Point 10
|
||||
Translated:Point 10
|
||||
|
||||
English:Point 2
|
||||
Translated:Point 2
|
||||
|
||||
English:Point 3
|
||||
Translated:Point 3
|
||||
|
||||
English:Point 4
|
||||
Translated:Point 4
|
||||
|
||||
English:Point 5
|
||||
Translated:Point 5
|
||||
|
||||
English:Point 6
|
||||
Translated:Point 6
|
||||
|
||||
English:Point 7
|
||||
Translated:Point 7
|
||||
|
||||
English:Point 8
|
||||
Translated:Point 8
|
||||
|
||||
English:Point 9
|
||||
Translated:Point 9
|
||||
|
||||
English:Point Size
|
||||
Translated:Point Size
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 7ed8dca97eab5e850a0031b71cea55c19b826f39
|
||||
Subproject commit 00b99afed26b58d9c3a25eafa891fcef0dfd89de
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 997d761896c03f40be9b7db8bd5ababd97a7c5ef
|
||||
Subproject commit c19b0609c41c64e5eb90961cd80b211abc08c0d9
|
||||
Loading…
Add table
Add a link
Reference in a new issue