Example #1
0
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            var newPoint = Snap.ToGrid(e.GetPosition(this));

            if (!DoubleUtils.Equals(newPoint, this.MousePosition))
            {
                this.MousePosition = newPoint;
            }
        }
Example #2
0
        internal bool NotifyMouseClick(Point currentPoint)
        {
            if (ClosedShape)
            {
                return(false);
            }

            currentPoint = Snap.ToGrid(currentPoint);

            if (_points.Count != 0)
            {
                // check if new point has same coordinations as last point
                var lastPoint = _points.Last();
                if (DoubleUtils.Equals(lastPoint, currentPoint))
                {
                    return(true);
                }

                // check if new point has same coordinations as first pont
                var firstPoint = _points[0];
                if (DoubleUtils.Equals(firstPoint, currentPoint))
                {
                    CloseShape();
                    return(true);
                }
            }

            _points.Add(currentPoint);
            _lastLine = new LineViewModel(currentPoint.X, currentPoint.Y, _mousePosition.X, _mousePosition.Y);
            this.Items.Add(_lastLine);

            if (_closeLine == null && this.Items.Count == 2)
            {
                var firstPoint = _points[0];
                _closeLine = new LineViewModel(_mousePosition.X, _mousePosition.Y, firstPoint.X, firstPoint.Y);
                this.Items.Add(_closeLine);
            }

            return(true);
        }