protected override void OnResizeDelta(ResizingDirection direction, double horizontalChange, double verticalChange) { if (direction.HasFlag(ResizingDirection.Center)) { // TODO: not yet implememted return; } var scaledHorizontalChange = (float)Math.Round(horizontalChange / ScaleFactor, MidpointRounding.AwayFromZero); var scaledVerticalChange = (float)Math.Round(verticalChange / ScaleFactor, MidpointRounding.AwayFromZero); var deltaVector = new Vector4(); if (direction.HasFlag(ResizingDirection.Left)) { deltaVector.X = scaledHorizontalChange; } if (direction.HasFlag(ResizingDirection.Right)) { deltaVector.Z = -scaledHorizontalChange; } if (direction.HasFlag(ResizingDirection.Top)) { deltaVector.Y = scaledVerticalChange; } if (direction.HasFlag(ResizingDirection.Bottom)) { deltaVector.W = -scaledVerticalChange; } Borders += deltaVector; }
void IResizingTarget.OnResizingStarted(ResizingDirection direction) { // Makes sure the point is synchronized with the underlying key/value pair. SynchronizePoint(); // Remember the starting point startingPoint = ActualPoint; }
public static void Resizable(this Control control, ResizingDirection resizableVertical = (ResizingDirection.ResizingForward | ResizingDirection.ResizingReverse), ResizingDirection resizableHorizontal = (ResizingDirection.ResizingForward | ResizingDirection.ResizingReverse)) { if (resizables.ContainsKey(control)) { return; } ResizingData data = new ResizingData() { verticalAllowed = resizableVertical, horizontalAllowed = resizableHorizontal, verticalCurrent = ResizingDirection.NoResizing, horizontalCurrent = ResizingDirection.NoResizing, minWidth = null, maxWidth = null, minHeight = null, maxHeight = null, originalLocation = control.Location, originalSize = control.Size, originalCursor = control.Cursor, resizingCursor = false }; resizables.Add(control, data); control.MouseDown += new MouseEventHandler(control_MouseDown); control.MouseUp += new MouseEventHandler(control_MouseUp); control.MouseMove += new MouseEventHandler(control_MouseMove); }
void IResizingTarget.OnResizingCompleted(ResizingDirection direction, double horizontalChange, double verticalChange) { using (var transaction = UndoRedoService.CreateTransaction()) { OnResizingCompleted(direction, horizontalChange, verticalChange); UndoRedoService.SetName(transaction, "Move control point"); } }
protected virtual void OnResizingStarted(ResizingDirection direction) { var selectedPoints = ControlPoints.Where(c => c.IsSelected).ToList(); foreach (IResizingTarget c in selectedPoints) { c.OnResizingStarted(direction); } }
protected virtual void OnResizingDelta(ResizingDirection direction, double horizontalChange, double verticalChange) { var selectedPoints = ControlPoints.Where(c => c.IsSelected).ToList(); foreach (IResizingTarget c in selectedPoints) { c.OnResizingDelta(direction, horizontalChange, verticalChange); } }
void IResizingTarget.OnResizingStarted(ResizingDirection direction) { if (resizingTransaction != null || resizingContext != null) { throw new InvalidOperationException("A resize operation was already in progress."); } resizingTransaction = UndoRedoService.CreateTransaction(); resizingContext = SynchronizationContext.Current; }
void IResizingTarget.OnResizingDelta(ResizingDirection direction, double horizontalChange, double verticalChange) { if (resizingTransaction == null || resizingContext == null) { throw new InvalidOperationException("No resize operation in progress."); } // The synchronization context has changed here, we must signal we intentionnally continue an existing transaction. resizingTransaction.Continue(); OnResizeDelta(direction, horizontalChange, verticalChange); }
public SizingAdorner(UIEditorGameAdornerService service, UIElement gameSideElement, ResizingDirection resizingDirection) : base(service, gameSideElement) { BackgroundColor = Color.Transparent; Visual.Name = $"[Sizing] {resizingDirection}"; Visual.CanBeHitByUser = true; ResizingDirection = resizingDirection; // support for mouse over cursor Visual.MouseOverStateChanged += MouseOverStateChanged; }
protected virtual void OnResizingDelta(ResizingDirection direction, double horizontalChange, double verticalChange) { var changeVector = Curve.InverseTransformVector(new WindowsVector(horizontalChange, verticalChange)); CoerceResizing(ref changeVector, true); switch (direction) { case ResizingDirection.Center: Point = Point + changeVector; break; } }
protected override void OnResizeDelta(ResizingDirection direction, double horizontalChange, double verticalChange) { var scaledHorizontalChange = (float)Math.Round(horizontalChange / ScaleFactor, MidpointRounding.AwayFromZero); var scaledVerticalChange = (float)Math.Round(verticalChange / ScaleFactor, MidpointRounding.AwayFromZero); var newCenter = Center; if (direction.HasFlag(ResizingDirection.Center)) { newCenter.X += scaledHorizontalChange; newCenter.Y += scaledVerticalChange; } Center = newCenter; }
protected virtual void OnResizingCompleted(ResizingDirection direction, double horizontalChange, double verticalChange) { if (Math.Abs(horizontalChange) + Math.Abs(verticalChange) < MathUtil.ZeroToleranceDouble) { return; } // Zooming might have change during the resizing, so we need to calculate from the original position var vector = Curve.InverseTransformPoint(startingPoint + new WindowsVector(horizontalChange, verticalChange)); CoerceResizing(ref vector, false); Key = vector.X; Value = vector.Y; }
void IResizingTarget.OnResizingCompleted(ResizingDirection direction, double horizontalChange, double verticalChange) { if (resizingTransaction == null || resizingContext == null) { throw new InvalidOperationException("No resize operation in progress."); } // The synchronization context has changed here, we must signal we intentionnally continue an existing transaction. resizingTransaction.Continue(); var transactionName = ComputeTransactionName(direction, horizontalChange, verticalChange); UndoRedoService.SetName(resizingTransaction, transactionName); resizingTransaction.Complete(); resizingTransaction = null; resizingContext = null; }
/// <summary> /// Resizes an element. /// </summary> /// <param name="element">The element to move.</param> /// <param name="resizingDirection"></param> /// <param name="delta"></param> /// <param name="magnetDistance">The maximum distance at which magnet will be applied</param> /// <param name="resolution">The resolution of the UI.</param> /// <returns></returns> public static bool Resize([NotNull] UIElement element, ResizingDirection resizingDirection, ref Vector3 delta, float magnetDistance, ref Vector3 resolution) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var parameters = new LayoutParameters { Left = resizingDirection.HasFlag(ResizingDirection.Left), Right = resizingDirection.HasFlag(ResizingDirection.Right), Top = resizingDirection.HasFlag(ResizingDirection.Top), Bottom = resizingDirection.HasFlag(ResizingDirection.Bottom), CanResize = true, }; UpdateElementLayout(element, ref delta, magnetDistance, ref resolution, parameters); return(true); }
protected override void OnResizeDelta(ResizingDirection direction, double horizontalChange, double verticalChange) { var scaledHorizontalChange = (float)Math.Round(horizontalChange / ScaleFactor, MidpointRounding.AwayFromZero); var scaledVerticalChange = (float)Math.Round(verticalChange / ScaleFactor, MidpointRounding.AwayFromZero); var newRegion = Region; if (direction.HasFlag(ResizingDirection.Center)) { newRegion.Left += scaledHorizontalChange; newRegion.Top += scaledVerticalChange; // Clamp to keep region size ClampHorizontally(ref newRegion, (float)imageWidth - Region.Width, (float)imageWidth); ClampVertically(ref newRegion, (float)imageHeight - Region.Height, (float)imageHeight); } else { if (direction.HasFlag(ResizingDirection.Left)) { var xOffset = MathUtil.Clamp(scaledHorizontalChange, -newRegion.Left, newRegion.Width); newRegion.Left += xOffset; newRegion.Width -= xOffset; } if (direction.HasFlag(ResizingDirection.Right)) { var xOffset = Math.Max(-newRegion.Width, scaledHorizontalChange); newRegion.Width += xOffset; } if (direction.HasFlag(ResizingDirection.Top)) { var yOffset = MathUtil.Clamp(scaledVerticalChange, -newRegion.Top, newRegion.Height); newRegion.Top += yOffset; newRegion.Height -= yOffset; } if (direction.HasFlag(ResizingDirection.Bottom)) { var yOffset = Math.Max(-newRegion.Height, scaledVerticalChange); newRegion.Height += yOffset; } } Region = newRegion; }
protected override void OnResizingCompleted(ResizingDirection direction, double horizontalChange, double verticalChange) { base.OnResizingCompleted(direction, horizontalChange, verticalChange); Debug.Assert(IsSynchronized); // Maintain order if (Previous != null && ActualKey < (Previous.IsSynchronized ? Previous.ActualKey : Previous.Key) || Next != null && ActualKey > (Next.IsSynchronized ? Next.ActualKey : Next.Key)) { var editableCurve = Curve as EditableCurveViewModel <TValue>; if (editableCurve == null) { return; } var actualPoint = ActualPoint; // remove editableCurve.RemovePoint(this); // re-add editableCurve.AddPoint(actualPoint); } }
protected override string ComputeTransactionName(ResizingDirection direction, double horizontalChange, double verticalChange) { switch (direction) { case ResizingDirection.Center: // TODO: not yet implememted return("Move sprite borders"); case ResizingDirection.Left: case ResizingDirection.Top: case ResizingDirection.Right: case ResizingDirection.Bottom: return($"Update sprite {direction} border"); case ResizingDirection.TopLeft: case ResizingDirection.TopRight: case ResizingDirection.BottomLeft: case ResizingDirection.BottomRight: return($"Update sprite {direction} borders."); default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } }
void IResizingTarget.OnResizingStarted(ResizingDirection direction) { OnResizingStarted(direction); }
private static SizeChange getNewSize(ResizingDirection direction, int originalSize, int mouseOffset, int?min, int?max) { SizeChange result = new SizeChange() { newSize = originalSize, sizeChange = 0, locationDelta = 0 }; int _newSize = 0; switch (direction) { case ResizingDirection.ResizingForward: _newSize = originalSize + mouseOffset; if (((min == null) || (min <= _newSize)) && ((max == null) || (max >= _newSize))) { result.newSize = _newSize; result.sizeChange = mouseOffset; } else { if ((min != null) && (_newSize < min)) { result.newSize = (int)min; result.sizeChange = result.newSize - originalSize; } else if ((max != null) && (_newSize > min)) { result.newSize = (int)max; result.sizeChange = result.newSize - originalSize; } } break; case ResizingDirection.ResizingReverse: _newSize = originalSize - mouseOffset; if (((min == null) || (min <= _newSize)) && ((max == null) || (max >= _newSize))) { result.newSize = _newSize; result.sizeChange = -mouseOffset; result.locationDelta = mouseOffset; } else { if ((min != null) && (_newSize < min)) { result.newSize = (int)min; result.sizeChange = result.newSize - originalSize; result.locationDelta = -result.sizeChange; } else if ((max != null) && (_newSize > min)) { result.newSize = (int)max; result.sizeChange = result.newSize - originalSize; result.locationDelta = -result.sizeChange; } } break; case ResizingDirection.NoResizing: default: break; } return(result); }
protected abstract string ComputeTransactionName(ResizingDirection direction, double horizontalChange, double verticalChange);
protected abstract void OnResizeDelta(ResizingDirection direction, double horizontalChange, double verticalChange);
protected override string ComputeTransactionName(ResizingDirection direction, double horizontalChange, double verticalChange) { return(direction == ResizingDirection.Center ? "Move sprite center" : null); }
void IResizingTarget.OnResizingDelta(ResizingDirection direction, double horizontalChange, double verticalChange) { OnResizingDelta(direction, horizontalChange, verticalChange); }
protected override string ComputeTransactionName(ResizingDirection direction, double horizontalChange, double verticalChange) { return(direction == ResizingDirection.Center ? "Move region" : "Update region size"); }