Example #1
0
        private void ScaleLine(LineFigure lf, Point pos)
        {
            if (_nowScaling == null)
            {
                _originalX = lf.X.CachedValue.AsDouble;
                _originalY = lf.Y.CachedValue.AsDouble;
                _originalW = lf.Width.CachedValue.AsDouble;
                _originalH = lf.Height.CachedValue.AsDouble;
                var snappedTo   = StepManager.SnapTo(pos, lf.GetMagnets(), lf.Center);
                var bLenSquared = _originalW * _originalW + _originalH * _originalH;
                if ((snappedTo == lf.Start) && (Math.Abs(bLenSquared) > Utils.Tolerance))
                {
                    var ax = _originalX + _originalW - pos.X;
                    var ay = _originalY + _originalH - pos.Y;

                    _nowScaling = new ScaleLineStep(lf, ScaleLineStep.Side.End,
                                                    (ax * _originalW + ay * _originalH) / bLenSquared);
                }
                else if ((snappedTo == lf.End) && (Math.Abs(bLenSquared) > Utils.Tolerance))
                {
                    var ax = pos.X - _originalX;
                    var ay = pos.Y - _originalY;

                    _nowScaling = new ScaleLineStep(lf, ScaleLineStep.Side.Start,
                                                    (ax * _originalW + ay * _originalH) / bLenSquared);
                }
                if (_nowScaling == null)
                {
                    return;
                }
                StepManager.InsertNext(_nowScaling);
            }
            else
            {
                var sls = (ScaleLineStep)_nowScaling;

                if (sls.ScaleAround == ScaleLineStep.Side.Start)
                {
                    var bLenSquared = _originalW * _originalW + _originalH * _originalH;

                    var ax = pos.X - _originalX;
                    var ay = pos.Y - _originalY;

                    sls.Scale((ax * _originalW + ay * _originalH) / bLenSquared);
                }
                else if (sls.ScaleAround == ScaleLineStep.Side.End)
                {
                    var bLenSquared = _originalW * _originalW + _originalH * _originalH;

                    var ax = _originalX + _originalW - pos.X;
                    var ay = _originalY + _originalH - pos.Y;

                    sls.Scale((ax * _originalW + ay * _originalH) / bLenSquared);
                }
            }
        }
Example #2
0
        private void RotateLine(LineFigure lf, Point pos)
        {
            if (_nowRotating == null)
            {
                var snappedTo = StepManager.SnapTo(pos, lf.GetMagnets(), lf.Center);
                if (snappedTo == lf.Start)
                {
                    var angle = Utils.AngleBetween(lf.X.CachedValue.AsDouble + lf.Width.CachedValue.AsDouble - pos.X,
                                                   lf.Y.CachedValue.AsDouble + lf.Height.CachedValue.AsDouble - pos.Y,
                                                   lf.Width.CachedValue.AsDouble,
                                                   lf.Height.CachedValue.AsDouble);

                    _nowRotating = new RotateLineStep(lf, RotateLineStep.Side.End,
                                                      angle / (2 * Math.PI));
                }
                else if (snappedTo == lf.End)
                {
                    var angle = Utils.AngleBetween(pos.X - lf.X.CachedValue.AsDouble, pos.Y - lf.Y.CachedValue.AsDouble,
                                                   lf.Width.CachedValue.AsDouble, lf.Height.CachedValue.AsDouble);

                    _nowRotating = new RotateLineStep(lf, RotateLineStep.Side.Start,
                                                      angle / (2 * Math.PI));
                }
                if (_nowRotating == null)
                {
                    return;
                }
                _originalX = lf.X.CachedValue.AsDouble;
                _originalY = lf.Y.CachedValue.AsDouble;
                _originalW = lf.Width.CachedValue.AsDouble;
                _originalH = lf.Height.CachedValue.AsDouble;
                StepManager.InsertNext(_nowRotating);
            }
            else
            {
                var rls = (RotateLineStep)_nowRotating;

                if (rls.RotateAround == RotateLineStep.Side.Start)
                {
                    var angle = Utils.AngleBetween(pos.X - _originalX, pos.Y - _originalY,
                                                   _originalW, _originalH);

                    rls.Rotate(angle / (2 * Math.PI));
                }
                else if (rls.RotateAround == RotateLineStep.Side.End)
                {
                    var angle = Utils.AngleBetween(_originalX + _originalW - pos.X,
                                                   _originalY + _originalH - pos.Y,
                                                   _originalW, _originalH);

                    rls.Rotate(angle / (2 * Math.PI));
                }
            }
        }
Example #3
0
 private void ResizeLine(LineFigure lf, Point pos)
 {
     if (_nowResizing == null)
     {
         var snappedTo = StepManager.SnapTo(pos, lf.GetMagnets(), lf.Center);
         if (snappedTo == lf.Start)
         {
             _nowResizing = new ResizeLineStep(lf, ResizeLineStep.Side.End, pos.X - _downPos.X,
                                               pos.Y - _downPos.Y);
         }
         else if (snappedTo == lf.End)
         {
             _nowResizing = new ResizeLineStep(lf, ResizeLineStep.Side.Start, pos.X - _downPos.X,
                                               pos.Y - _downPos.Y);
         }
         if (_nowResizing == null)
         {
             return;
         }
         StepManager.InsertNext(_nowResizing);
     }
     else
     {
         var rls     = (ResizeLineStep)_nowResizing;
         var snapped = StepManager.Snap(pos, _nowResizing.Figure);
         if (snapped != null)
         {
             if (rls.ResizeAround == ResizeLineStep.Side.End)
             {
                 rls.Resize("(" + snapped.X.ExprString + ") - " + rls.Figure.Name + ".x",
                            "(" + snapped.Y.ExprString + ") - " + rls.Figure.Name + ".y", snapped.Def);
             }
             else if (rls.ResizeAround == ResizeLineStep.Side.Start)
             {
                 rls.Resize("(" + snapped.X.ExprString + ") - (" + rls.Figure.Name + ".x + (" +
                            rls.Figure.Name + ".width))",
                            "(" + snapped.Y.ExprString + ") - (" + rls.Figure.Name + ".y + (" +
                            rls.Figure.Name + ".height))", snapped.Def);
             }
         }
         else
         {
             if (rls.ResizeAround == ResizeLineStep.Side.End)
             {
                 rls.Resize(pos.X - _downPos.X, pos.Y - _downPos.Y);
             }
             else if (rls.ResizeAround == ResizeLineStep.Side.Start)
             {
                 rls.Resize(pos.X - _downPos.X, pos.Y - _downPos.Y);
             }
         }
     }
 }