|
|
@@ -64,10 +64,8 @@ internal class DimensionObject : IImageEditorStateObject
|
|
|
return new Vector(mainVec.Y, -mainVec.X);
|
|
|
}
|
|
|
|
|
|
- public void SetState(ImageEditorState state)
|
|
|
+ private void CreateThumb()
|
|
|
{
|
|
|
- _state = state;
|
|
|
-
|
|
|
var p1 = new Vector(Point1.X, Point1.Y);
|
|
|
var p2 = new Vector(Point2.X, Point2.Y);
|
|
|
|
|
|
@@ -84,7 +82,6 @@ internal class DimensionObject : IImageEditorStateObject
|
|
|
|
|
|
var perpVec = new Vector(mainVec.Y, -mainVec.X);
|
|
|
|
|
|
- var arrowLength = LineThickness * 2;
|
|
|
var offset = perpVec * Offset;
|
|
|
|
|
|
var thumbSize = 30;
|
|
|
@@ -94,20 +91,25 @@ internal class DimensionObject : IImageEditorStateObject
|
|
|
Thumb.RenderTransform = new TransformGroup
|
|
|
{
|
|
|
Children = [
|
|
|
- new RotateTransform(Math.Atan2(mainVec.Y, mainVec.X) * 180 / Math.PI),
|
|
|
- new ScaleTransform(1 / _state.ScaleFactor, 1 / _state.ScaleFactor)
|
|
|
+ new RotateTransform(Math.Atan2(mainVec.Y, mainVec.X) * 180 / Math.PI)
|
|
|
]
|
|
|
};
|
|
|
Thumb.BorderThickness = new(1);
|
|
|
- Thumb.Width = thumbSize;
|
|
|
- Thumb.Height = thumbSize;
|
|
|
+ Thumb.Width = length;
|
|
|
+ Thumb.Height = Math.Max(20, thumbSize / _state.ScaleFactor);
|
|
|
|
|
|
var thumbPos = p1 + offset + mainVec * length / 2;
|
|
|
- Canvas.SetLeft(Thumb, thumbPos.X - thumbSize / 2);
|
|
|
- Canvas.SetTop(Thumb, thumbPos.Y - thumbSize / 2);
|
|
|
+ Canvas.SetLeft(Thumb, thumbPos.X - Thumb.Width / 2);
|
|
|
+ Canvas.SetTop(Thumb, thumbPos.Y - Thumb.Height / 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void SetState(ImageEditorState state)
|
|
|
+ {
|
|
|
+ _state = state;
|
|
|
+ CreateThumb();
|
|
|
+ }
|
|
|
+
|
|
|
public void Update()
|
|
|
{
|
|
|
Control.Children.RemoveAll(Control.Children.Where(x => !(x is Thumb)));
|
|
|
@@ -133,14 +135,25 @@ internal class DimensionObject : IImageEditorStateObject
|
|
|
var arrowLength = LineThickness * 2;
|
|
|
var offset = perpVec * Offset;
|
|
|
|
|
|
+ var middle = p1 + offset + mainVec * length / 2;
|
|
|
+
|
|
|
+ var line1 = new Line
|
|
|
+ {
|
|
|
+ StartPoint = Point(p1 + offset),
|
|
|
+ EndPoint = Point(middle),
|
|
|
+ StrokeLineCap = PenLineCap.Round
|
|
|
+ };
|
|
|
+ var line2 = new Line
|
|
|
+ {
|
|
|
+ StartPoint = Point(middle),
|
|
|
+ EndPoint = Point(p2 + offset),
|
|
|
+ StrokeLineCap = PenLineCap.Round
|
|
|
+ };
|
|
|
+
|
|
|
var mainLines = new List<Line>()
|
|
|
{
|
|
|
- new()
|
|
|
- {
|
|
|
- StartPoint = Point(p1 + offset),
|
|
|
- EndPoint = Point(p2 + offset),
|
|
|
- StrokeLineCap = PenLineCap.Round
|
|
|
- },
|
|
|
+ line1,
|
|
|
+ line2,
|
|
|
new()
|
|
|
{
|
|
|
StartPoint = Point(p1 + offset),
|
|
|
@@ -203,17 +216,24 @@ internal class DimensionObject : IImageEditorStateObject
|
|
|
Text = Text,
|
|
|
FontSize = textHeight,
|
|
|
TextAlignment = TextAlignment.Center,
|
|
|
- Width = length,
|
|
|
Foreground = PrimaryBrush
|
|
|
};
|
|
|
text.RenderTransform = new RotateTransform(Math.Atan2(mainVec.Y, mainVec.X) * 180 / Math.PI);
|
|
|
- var textPos = p1 + offset + mainVec * length / 2 + perpVec * (textHeight / 2 + 5);
|
|
|
- Canvas.SetLeft(text, textPos.X - length / 2);
|
|
|
- Canvas.SetTop(text, textPos.Y - textHeight / 2);
|
|
|
+ var textPos = p1 + offset + mainVec * length / 2;
|
|
|
+ Canvas.SetLeft(text, textPos.X);
|
|
|
+ Canvas.SetTop(text, textPos.Y);
|
|
|
+ text.SizeChanged += (o, e) =>
|
|
|
+ {
|
|
|
+ line1.EndPoint = Point(middle - mainVec * (text.Bounds.Width / 2 + 5));
|
|
|
+ line2.StartPoint = Point(middle + mainVec * (text.Bounds.Width / 2 + 5));
|
|
|
|
|
|
- Control.Children.Add(text);
|
|
|
+ var topCorner = textPos - mainVec * text.Bounds.Width / 2 + perpVec * text.Bounds.Height / 2;
|
|
|
|
|
|
- var thumbSize = 30;
|
|
|
+ Canvas.SetLeft(text, textPos.X - text.Bounds.Width / 2);
|
|
|
+ Canvas.SetTop(text, textPos.Y - text.Bounds.Height / 2);
|
|
|
+ };
|
|
|
+
|
|
|
+ Control.Children.Add(text);
|
|
|
|
|
|
if(Thumb is null && _active && length > 0)
|
|
|
{
|
|
|
@@ -225,23 +245,7 @@ internal class DimensionObject : IImageEditorStateObject
|
|
|
Control.Children.Add(Thumb);
|
|
|
}
|
|
|
|
|
|
- if(Thumb is not null)
|
|
|
- {
|
|
|
- Thumb.RenderTransform = new TransformGroup
|
|
|
- {
|
|
|
- Children = [
|
|
|
- new RotateTransform(Math.Atan2(mainVec.Y, mainVec.X) * 180 / Math.PI),
|
|
|
- new ScaleTransform(1 / _state.ScaleFactor, 1 / _state.ScaleFactor)
|
|
|
- ]
|
|
|
- };
|
|
|
- Thumb.BorderThickness = new(1);
|
|
|
- Thumb.Width = thumbSize;
|
|
|
- Thumb.Height = thumbSize;
|
|
|
-
|
|
|
- var thumbPos = p1 + offset + mainVec * length / 2;
|
|
|
- Canvas.SetLeft(Thumb, thumbPos.X - thumbSize / 2);
|
|
|
- Canvas.SetTop(Thumb, thumbPos.Y - thumbSize / 2);
|
|
|
- }
|
|
|
+ CreateThumb();
|
|
|
}
|
|
|
|
|
|
private Vector Rotate(Vector v, double angle)
|