Example #1
0
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);

            if (IsMouseCaptured && _currentSelectionEventArgs != null)
            {
                ReleaseMouseCapture();

                RaiseEvent(_currentSelectionEventArgs);
                _currentSelection = null;
                _currentSelectionEventArgs = null;
            }
        }
Example #2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (IsMouseCaptured)
            {
                if (_currentSelection == null)
                {
                    var newSelection = new Selection(NextSelectionId++);
                    Children.Add(newSelection);
                    _currentSelectionEventArgs = new FigureSelectedEventArgs(
                        FigureSelectedEvent,
                        this,
                        newSelection.Id,
                        () => Children.Remove(newSelection));

                    _currentSelection = newSelection;
                }

                Point currentPoint = e.GetPosition(this);
                Point modifiedPoint = RestrictToCanvasBounds(currentPoint);

                double width = Math.Abs(_mouseLeftDownPoint.X - modifiedPoint.X);
                double height = Math.Abs(_mouseLeftDownPoint.Y - modifiedPoint.Y);
                double left = Math.Min(_mouseLeftDownPoint.X, modifiedPoint.X);
                double top = Math.Min(_mouseLeftDownPoint.Y, modifiedPoint.Y);

                _currentSelection.Width = width;
                _currentSelection.Height = height;
                SetLeft(_currentSelection, left);
                SetTop(_currentSelection, top);

                _currentSelectionEventArgs.RelativeOffsetY = top / ActualHeight;
                _currentSelectionEventArgs.RelativeOffsetX = left / ActualWidth;
                _currentSelectionEventArgs.RelativeWidth = width / ActualWidth;
                _currentSelectionEventArgs.RelativeHeight = height / ActualHeight;
            }
        }