|
@@ -1,10 +1,13 @@
|
|
|
-using Avalonia;
|
|
|
+using System.Globalization;
|
|
|
+using Avalonia;
|
|
|
using Avalonia.Media;
|
|
|
using Avalonia.Styling;
|
|
|
using Drawie.Backend.Core.Surfaces;
|
|
|
using Drawie.Backend.Core.Surfaces.PaintImpl;
|
|
|
+using Drawie.Backend.Core.Text;
|
|
|
using PixiEditor.Models.Controllers.InputDevice;
|
|
|
using Drawie.Numerics;
|
|
|
+using PixiEditor.Extensions.UI.Overlays;
|
|
|
using PixiEditor.Helpers;
|
|
|
using Colors = Drawie.Backend.Core.ColorsImpl.Colors;
|
|
|
using Point = Avalonia.Point;
|
|
@@ -25,6 +28,10 @@ internal class SnappingOverlay : Overlay
|
|
|
private Paint horizontalAxisPen;
|
|
|
private Paint verticalAxisPen;
|
|
|
private Paint previewPointPen;
|
|
|
+ private VecD lastMousePosition;
|
|
|
+
|
|
|
+ private Paint distanceTextPaint;
|
|
|
+ private Font distanceFont = Font.CreateDefault();
|
|
|
|
|
|
private const float startSize = 1;
|
|
|
|
|
@@ -39,7 +46,9 @@ internal class SnappingOverlay : Overlay
|
|
|
/*TODO: Theme variant is not present, that's why Dark is hardcoded*/
|
|
|
horizontalAxisPen = ResourceLoader.GetPaint("HorizontalSnapAxisBrush", PaintStyle.Stroke, ThemeVariant.Dark) ?? new Paint() { Color = Colors.Red, Style = PaintStyle.Stroke, IsAntiAliased = true, StrokeWidth = startSize};
|
|
|
verticalAxisPen = ResourceLoader.GetPaint("VerticalSnapAxisBrush", PaintStyle.Stroke, ThemeVariant.Dark) ?? new Paint() { Color = Colors.Green, Style = PaintStyle.Stroke, IsAntiAliased = true, StrokeWidth = startSize};
|
|
|
- previewPointPen = ResourceLoader.GetPaint("SnapPointPreviewBrush", PaintStyle.Fill, ThemeVariant.Dark) ?? new Paint() { Color = Colors.Blue, Style = PaintStyle.Stroke, IsAntiAliased = true, StrokeWidth = startSize};
|
|
|
+ previewPointPen = ResourceLoader.GetPaint("SnapPointPreviewBrush", PaintStyle.Fill, ThemeVariant.Dark) ?? new Paint() { Color = Colors.Blue, Style = PaintStyle.Stroke, IsAntiAliased = true, StrokeWidth = startSize};
|
|
|
+ distanceTextPaint = new Paint() { Color = Colors.White, Style = PaintStyle.Fill, IsAntiAliased = true, StrokeWidth = startSize };
|
|
|
+
|
|
|
IsHitTestVisible = false;
|
|
|
}
|
|
|
|
|
@@ -50,13 +59,18 @@ internal class SnappingOverlay : Overlay
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ VecD mousePoint = SnappingController.HighlightedPoint ?? lastMousePosition;
|
|
|
+
|
|
|
if (!string.IsNullOrEmpty(SnappingController.HighlightedXAxis))
|
|
|
{
|
|
|
foreach (var snapPoint in SnappingController.HorizontalSnapPoints)
|
|
|
{
|
|
|
if (snapPoint.Key == SnappingController.HighlightedXAxis)
|
|
|
{
|
|
|
- context.DrawLine(new VecD(snapPoint.Value(), 0), new VecD(snapPoint.Value(), canvasBounds.Height), horizontalAxisPen);
|
|
|
+ VecD snapPointValue = snapPoint.Value();
|
|
|
+ context.DrawLine(new VecD(snapPointValue.X, mousePoint.Y), new VecD(snapPointValue.X, snapPointValue.Y), horizontalAxisPen);
|
|
|
+
|
|
|
+ DrawDistanceText(context, snapPointValue + new VecD(10 / ZoomScale, 0), mousePoint);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -67,7 +81,10 @@ internal class SnappingOverlay : Overlay
|
|
|
{
|
|
|
if (snapPoint.Key == SnappingController.HighlightedYAxis)
|
|
|
{
|
|
|
- context.DrawLine(new VecD(0, snapPoint.Value()), new VecD(canvasBounds.Width, snapPoint.Value()), verticalAxisPen);
|
|
|
+ var snapPointValue = snapPoint.Value();
|
|
|
+ context.DrawLine(new VecD(mousePoint.X, snapPointValue.Y), new VecD(snapPointValue.X, snapPointValue.Y), verticalAxisPen);
|
|
|
+
|
|
|
+ DrawDistanceText(context, snapPointValue + new VecD(0, -10 / ZoomScale), mousePoint);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -78,6 +95,27 @@ internal class SnappingOverlay : Overlay
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void DrawDistanceText(Canvas context, VecD snapPointValue, VecD mousePoint)
|
|
|
+ {
|
|
|
+ VecD distance = snapPointValue - mousePoint;
|
|
|
+ VecD center = (snapPointValue + mousePoint) / 2;
|
|
|
+ distanceFont.Size = 12 / (float)ZoomScale;
|
|
|
+
|
|
|
+ distanceTextPaint.Color = Colors.Black;
|
|
|
+ distanceTextPaint.Style = PaintStyle.Stroke;
|
|
|
+ distanceTextPaint.StrokeWidth = 2f / (float)ZoomScale;
|
|
|
+
|
|
|
+ context.DrawText($"{distance.Length.ToString("F2", CultureInfo.CurrentCulture)} px", center, distanceFont, distanceTextPaint);
|
|
|
+ distanceTextPaint.Color = Colors.White;
|
|
|
+ distanceTextPaint.Style = PaintStyle.Fill;
|
|
|
+ context.DrawText($"{distance.Length.ToString("F2", CultureInfo.CurrentCulture)} px", center, distanceFont, distanceTextPaint);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnOverlayPointerMoved(OverlayPointerArgs args)
|
|
|
+ {
|
|
|
+ lastMousePosition = args.Point;
|
|
|
+ }
|
|
|
+
|
|
|
protected override void ZoomChanged(double newZoom)
|
|
|
{
|
|
|
horizontalAxisPen.StrokeWidth = startSize / (float)newZoom;
|