예제 #1
0
        public void GuideMove(double x, double y)
        {
            double sx = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
            double sy = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;

            _state.GuidePosition = new GuidePoint(sx, sy);
            _measure.Point1      = new GuidePoint(sx, sy);

            TryToSnapToGuideLine();

            if (_state.HaveSnapPoint)
            {
                _state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
                _measure.Point1      = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
            }

            _measure.Distance = GuideHelpers.Distance(_measure.Point0, _measure.Point1);
            _measure.Angle    = GuideHelpers.LineSegmentAngle(_measure.Point0, _measure.Point1);

            _invalidate();
        }
예제 #2
0
        public void SpiroMove(double x, double y)
        {
            double sx = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
            double sy = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;

            if (_state.EnableSnap)
            {
                _state.GuidePosition = new GuidePoint(sx, sy);
                _measure.Point1      = new GuidePoint(x, y);

                TryToSnapToGuideLine();

                if (_state.HaveSnapPoint)
                {
                    _state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
                    _measure.Point1      = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);

                    sx = _state.SnapPoint.X;
                    sy = _state.SnapPoint.Y;
                }

                _measure.Point1 = new GuidePoint(sx, sy);

                _measure.Distance = GuideHelpers.Distance(_measure.Point0, _measure.Point1);
                _measure.Angle    = GuideHelpers.LineSegmentAngle(_measure.Point0, _measure.Point1);
            }

            if (_state.Shape != null)
            {
                if (_state.Shape.Points.Count > 1)
                {
                    SetPointPosition(_state.Shape, _state.Shape.Points.Count - 1, sx, sy);
                    RunSpiro(_state.Shape);
                }

                _invalidate();
            }
            else
            {
                if (_state.Mode == EditorMode.Create)
                {
                    // Dehover shape and dehover point.
                    Deselect();

                    SpiroShape hitShape;
                    int        hitShapePointIndex;
                    var        result = HitTestForPoint(_drawing.Shapes, x, y, _state.HitTresholdSquared, out hitShape, out hitShapePointIndex);
                    if (result)
                    {
                        // Hover shape and point.
                        Select(hitShape, hitShapePointIndex);
                    }
                    else
                    {
                        if (HitTestForShape(_drawing.Shapes, x, y, _state.HitTreshold, out hitShape, out hitShapePointIndex))
                        {
                            // Hover shape and dehover point.
                            Select(hitShape);
                        }
                    }
                }
                else if (_state.Mode == EditorMode.Move)
                {
                    // Calculate move offset.
                    double dx = sx - _startX;
                    double dy = sy - _startY;
                    // Update start position.
                    _startX = sx;
                    _startY = sy;

                    for (int i = 0; i < _state.HitListShapes.Count; i++)
                    {
                        var shape = _state.HitListShapes[i];
                        var index = _state.HitListPoints[i];

                        // Move selected shape.
                        if (index == -1)
                        {
                            // Move all shape points.
                            for (int j = 0; j < shape.Points.Count; j++)
                            {
                                SetPointPositionDelta(shape, j, dx, dy);
                            }
                            RunSpiro(shape);
                        }

                        // Move selected point.
                        if (index != -1)
                        {
                            SetPointPosition(shape, index, sx, sy);
                            RunSpiro(shape);
                        }
                    }

                    _invalidate();
                }
                else if (_state.Mode == EditorMode.Selected)
                {
                    _invalidate();
                }
            }
        }
예제 #3
0
        public void SpiroLeftDown(double x, double y)
        {
            double sx = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
            double sy = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;

            if (_state.EnableSnap)
            {
                _state.GuidePosition = new GuidePoint(sx, sy);

                if (_state.Shape == null)
                {
                    _measure.Point0 = new GuidePoint(x, y);
                }

                _measure.Point1 = new GuidePoint(x, y);

                TryToSnapToGuideLine();

                if (_state.HaveSnapPoint)
                {
                    _state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
                    _measure.Point1      = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);

                    sx = _state.SnapPoint.X;
                    sy = _state.SnapPoint.Y;
                }

                if (_state.Shape == null)
                {
                    _measure.Point0 = new GuidePoint(sx, sy);
                }

                _measure.Point1 = new GuidePoint(sx, sy);

                _measure.Distance = GuideHelpers.Distance(_measure.Point0, _measure.Point1);
                _measure.Angle    = GuideHelpers.LineSegmentAngle(_measure.Point0, _measure.Point1);
            }

            _startX = sx;
            _startY = sy;

            if (_state.Shape == null)
            {
                SpiroShape hitShape;
                int        hitShapePointIndex;

                // Hit test for point.
                var result = HitTestForPoint(_drawing.Shapes, x, y, _state.HitTresholdSquared, out hitShape, out hitShapePointIndex);
                if (result)
                {
                    Deselect();
                    Select(hitShape, hitShapePointIndex);
                    // Begin point move.
                    _state.Mode = EditorMode.Move;
                    return;
                }
                else
                {
                    // Hit test for shape and nearest point.
                    if (HitTestForShape(_drawing.Shapes, x, y, _state.HitTreshold, out hitShape, out hitShapePointIndex))
                    {
                        Select(hitShape);
                        // Begin point move.
                        _state.Mode = EditorMode.Move;
                        return;
                    }

                    if (_state.HitListShapes.Count > 0)
                    {
                        Deselect();
                        return;
                    }
                }
            }

            if (_state.Mode == EditorMode.Create)
            {
                Create(sx, sy);
            }
        }