public static void MoveSelection(Data.Layer layer, float dx, float dy, MoveMode mode = MoveMode.Normal) { using var group = layer.CreateUndoGroup(); foreach (var anchor in layer.Anchors) { if (anchor.IsSelected) { anchor.X = RoundToGrid(anchor.X + dx); anchor.Y = RoundToGrid(anchor.Y + dy); } } foreach (var component in layer.Components) { if (component.IsSelected) { var t = component.Transformation; t.M31 = RoundToGrid(t.M31 + dx); t.M32 = RoundToGrid(t.M32 + dy); component.Transformation = t; } } foreach (var guideline in UIBroker.GetAllGuidelines(layer)) { if (guideline.IsSelected) { guideline.X = RoundToGrid(guideline.X + dx); guideline.Y = RoundToGrid(guideline.Y + dy); } } foreach (var path in layer.Paths) { MoveSelection(path, dx, dy, mode); } }
public override void OnPointerMoved(DesignCanvas canvas, PointerRoutedEventArgs args) { base.OnPointerMoved(canvas, args); if (_origin.HasValue) { var pos = canvas.FromClientPosition(args.GetCurrentPoint(canvas).Position); var snapAxis = UIBroker.Axis.XY; if (args.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift)) { snapAxis = ClampToOrigin(pos, _origin.Value, out pos); } pos = UIBroker.SnapPointDirect(canvas.Layer, pos, 1f / canvas.ScaleFactor, snapAxis) .ToPoint(); if (_shouldMoveOrigin) { _origin = new Point( _origin.Value.X + pos.X - _anchor.X, _origin.Value.Y + pos.Y - _anchor.Y); } _anchor = pos; _points = GetPointsWithEndpoints(canvas.Layer, addIntersections: !args.KeyModifiers.HasFlag(VirtualKeyModifiers.Menu)); canvas.Invalidate(); } }
public virtual void OnKeyDown(DesignCanvas canvas, KeyRoutedEventArgs args) { var control = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); // TODO: batch and use the undoGroup reset thing on close enough keyboard moves if (args.Key == VirtualKey.Left || args.Key == VirtualKey.Up || args.Key == VirtualKey.Right || args.Key == VirtualKey.Down) { int dx = 0, dy = 0; if (args.Key == VirtualKey.Left) { dx = -1; } else if (args.Key == VirtualKey.Up) { dy = 1; } else if (args.Key == VirtualKey.Right) { dx = 1; } else if (args.Key == VirtualKey.Down) { dy = -1; } var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift); if (shift.HasFlag(CoreVirtualKeyStates.Down)) { dx *= 10; dy *= 10; if (control.HasFlag(CoreVirtualKeyStates.Down)) { dx *= 10; dy *= 10; } } var layer = canvas.Layer; using (var group = layer.CreateUndoGroup()) { Outline.MoveSelection(layer, dx, dy, GetMoveMode()); var selection = layer.Selection; if (selection.Count == 1 && selection.First() is Data.Point point && Outline.TryJoinPath(layer, point)) { DisplaySnapResult( canvas, UIBroker.GetSnapHighlight(point)); } else if (selection.OfType <Data.Point>().LastOrDefault() is Data.Point focusPoint) { DisplaySnapResult( canvas, UIBroker.GetSnapLines(layer, focusPoint.ToVector2().ToPoint())); } }
public static void DrawCoordinates(Data.Layer layer, CanvasDrawingSession ds, float rescale) { var color = Color.FromArgb(255, 21, 116, 212); var canvasPath = layer.ClosedCanvasPath; var margin = 8 * rescale; foreach (var path in layer.Paths) { foreach (var(point, angle) in UIBroker.GetCurvePointsPreferredAngle(path)) { var pos = point.ToVector2() + margin * Conversion.ToVector(angle); CanvasHorizontalAlignment hAlignment; if (PI_5_8 <= angle && angle < PI_11_8) { hAlignment = CanvasHorizontalAlignment.Right; } // No && condition here, because we check around 0 or around 360 deg else if (angle < PI_3_8 || PI_13_8 <= angle) { hAlignment = CanvasHorizontalAlignment.Left; } else { hAlignment = CanvasHorizontalAlignment.Center; } float?baseline; CanvasVerticalAlignment vAlignment; if (PI_1_8 <= angle && angle < PI_7_8) { baseline = null; vAlignment = CanvasVerticalAlignment.Bottom; } else if (PI_9_8 <= angle && angle < PI_15_8) { baseline = .78f; vAlignment = CanvasVerticalAlignment.Top; } else { baseline = .93f; vAlignment = CanvasVerticalAlignment.Center; } var rx = MathF.Round(point.X, 1); var ry = MathF.Round(point.Y, 1); DrawText(ds, $"{rx}, {ry}", pos, color, fontSize: 10, hAlignment: hAlignment, vAlignment: vAlignment, baseline: baseline, rescale: rescale); } } }
public override void OnPointerPressed(DesignCanvas canvas, PointerRoutedEventArgs args) { base.OnPointerPressed(canvas, args); var ptPoint = args.GetCurrentPoint(canvas); if (ptPoint.Properties.IsLeftButtonPressed) { var pos = canvas.FromClientPosition(ptPoint.Position); _origin = _anchor = UIBroker.SnapPointDirect(canvas.Layer, pos, 1f / canvas.ScaleFactor) .ToPoint(); canvas.Invalidate(); } }
public static void RoundSelection(Data.Layer layer) { using var group = layer.CreateUndoGroup(); foreach (var anchor in layer.Anchors) { if (anchor.IsSelected) { anchor.X = RoundToGrid(anchor.X); anchor.Y = RoundToGrid(anchor.Y); } } foreach (var component in layer.Components) { if (component.IsSelected) { var t = component.Transformation; // TODO: could round scale to 2 decimal digits, like we do when transforming // worth having a round to digits (default = 2) method here? t.M31 = RoundToGrid(t.M31); t.M32 = RoundToGrid(t.M32); component.Transformation = t; } } foreach (var guideline in UIBroker.GetAllGuidelines(layer)) { if (guideline.IsSelected) { // TODO: introduce some angle rounding? guideline.X = RoundToGrid(guideline.X); guideline.Y = RoundToGrid(guideline.Y); } } foreach (var path in layer.Paths) { foreach (var point in path.Points) { if (point.IsSelected) { point.X = RoundToGrid(point.X); point.Y = RoundToGrid(point.Y); } } } }