Пример #1
0
        private void UpdatePosition()
        {
            Point positionInBrush = this.dragCurrentPosition * this.rootToBrushMatrix;

            if (this.IsShiftDown)
            {
                Vector vector1 = this.initialEndPoint - this.initialStartPoint;
                double length  = vector1.Length;
                if (length == 0.0)
                {
                    positionInBrush = this.initialStartPoint;
                }
                else
                {
                    Vector vector2 = vector1 / length;
                    positionInBrush = this.initialStartPoint + vector2 * (positionInBrush - this.initialStartPoint) * vector2;
                }
            }
            Point point = RoundingHelper.RoundPosition(new Point(this.initialStartPoint.X + this.initialEndPoint.X - positionInBrush.X, this.initialStartPoint.Y + this.initialEndPoint.Y - positionInBrush.Y));

            if (this.ActiveAdorner.Kind == LinearGradientAdornerKind.StartPoint)
            {
                positionInBrush *= this.brushToRootMatrix;
                BrushTransformBehavior.OffsetDragPoint(ref positionInBrush, this.initialEndPoint * this.brushToRootMatrix, this.dragOffset, 0.001 / this.ActiveView.Zoom);
                positionInBrush   = RoundingHelper.RoundPosition(positionInBrush * this.rootToBrushMatrix);
                this.actionString = StringTable.UndoUnitLinearGradientStart;
                if (!this.HasMouseMovedAfterDown)
                {
                    this.CopyPrimaryBrushToSelection();
                }
                this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)positionInBrush);
                if (this.IsAltDown)
                {
                    this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point);
                }
            }
            else
            {
                positionInBrush *= this.brushToRootMatrix;
                BrushTransformBehavior.OffsetDragPoint(ref positionInBrush, this.initialStartPoint * this.brushToRootMatrix, this.dragOffset, 0.001 / this.ActiveView.Zoom);
                positionInBrush   = RoundingHelper.RoundPosition(positionInBrush * this.rootToBrushMatrix);
                this.actionString = StringTable.UndoUnitLinearGradientEnd;
                if (!this.HasMouseMovedAfterDown)
                {
                    this.CopyPrimaryBrushToSelection();
                }
                this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)positionInBrush);
                if (this.IsAltDown)
                {
                    this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point);
                }
            }
            this.UpdateEditTransaction();
        }
Пример #2
0
        protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow)
        {
            switch (this.ActiveAdorner.Kind)
            {
            case RadialGradientAdornerKind.GradientOriginPoint:
                this.actionString = StringTable.UndoUnitRadialGradientOrigin;
                if (!this.HasMouseMovedAfterDown)
                {
                    this.CopyPrimaryBrushToSelection();
                }
                Point point = this.initialCenterInBrush;
                if (Tolerances.HaveMoved(dragCurrentPosition, this.initialCenterInDocument, this.ActiveView.Zoom))
                {
                    Point positionInBrush = this.ActiveAdorner.InverseTransformPoint(dragCurrentPosition * this.initialContextToElementMatrix, true) * this.brushToRootMatrix;
                    BrushTransformBehavior.OffsetDragPoint(ref positionInBrush, this.initialCenterInBrush * this.brushToRootMatrix, this.dragOffset, 0.0);
                    point = RoundingHelper.RoundPosition(positionInBrush * this.rootToBrushMatrix);
                }
                if (this.ActiveAdorner.GradientOriginPoint != point)
                {
                    this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point);
                    this.UpdateEditTransaction();
                    break;
                }
                break;

            case RadialGradientAdornerKind.RadiusPoint:
                this.actionString = StringTable.UndoUnitScaleRadialGradient;
                if (!this.HasMouseMovedAfterDown)
                {
                    this.CopyPrimaryBrushToSelection();
                    this.radiusX = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusXProperty);
                    this.radiusY = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusYProperty);
                    if (Math.Abs(this.radiusX) < 0.01)
                    {
                        this.radiusX = 0.01;
                    }
                    if (Math.Abs(this.radiusY) < 0.01)
                    {
                        this.radiusY = 0.01;
                    }
                }
                Vector perpendicular;
                double num1 = GradientStopBehavior.VectorProjection(this.ActiveAdorner.BrushCenter * this.brushToRootMatrix, this.initialPointerPosition, dragCurrentPosition, 0.0, out perpendicular);
                double num2 = RoundingHelper.RoundLength(this.radiusX * num1);
                double num3 = RoundingHelper.RoundLength(this.radiusY * num1);
                this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)num2);
                this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)num3);
                this.UpdateEditTransaction();
                break;
            }
            this.ActiveView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow);
            return(true);
        }