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;
        }
예제 #2
0
 void IResizingTarget.OnResizingStarted(ResizingDirection direction)
 {
     // Makes sure the point is synchronized with the underlying key/value pair.
     SynchronizePoint();
     // Remember the starting point
     startingPoint = ActualPoint;
 }
예제 #3
0
        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);
        }
예제 #4
0
 void IResizingTarget.OnResizingCompleted(ResizingDirection direction, double horizontalChange, double verticalChange)
 {
     using (var transaction = UndoRedoService.CreateTransaction())
     {
         OnResizingCompleted(direction, horizontalChange, verticalChange);
         UndoRedoService.SetName(transaction, "Move control point");
     }
 }
예제 #5
0
        protected virtual void OnResizingStarted(ResizingDirection direction)
        {
            var selectedPoints = ControlPoints.Where(c => c.IsSelected).ToList();

            foreach (IResizingTarget c in selectedPoints)
            {
                c.OnResizingStarted(direction);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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;
        }
예제 #8
0
        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);
        }
예제 #9
0
        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;
        }
예제 #10
0
        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;
            }
        }
예제 #11
0
        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;
        }
예제 #12
0
        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;
        }
예제 #13
0
        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;
        }
예제 #14
0
        /// <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);
        }
예제 #15
0
        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;
        }
예제 #16
0
        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);
            }
        }
예제 #18
0
 void IResizingTarget.OnResizingStarted(ResizingDirection direction)
 {
     OnResizingStarted(direction);
 }
예제 #19
0
        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);
        }
예제 #20
0
 protected abstract string ComputeTransactionName(ResizingDirection direction, double horizontalChange, double verticalChange);
예제 #21
0
 protected abstract void OnResizeDelta(ResizingDirection direction, double horizontalChange, double verticalChange);
예제 #22
0
 protected override string ComputeTransactionName(ResizingDirection direction, double horizontalChange, double verticalChange)
 {
     return(direction == ResizingDirection.Center ? "Move sprite center" : null);
 }
예제 #23
0
 void IResizingTarget.OnResizingDelta(ResizingDirection direction, double horizontalChange, double verticalChange)
 {
     OnResizingDelta(direction, horizontalChange, verticalChange);
 }
예제 #24
0
 protected override string ComputeTransactionName(ResizingDirection direction, double horizontalChange, double verticalChange)
 {
     return(direction == ResizingDirection.Center ? "Move region" : "Update region size");
 }