Ejemplo n.º 1
0
		public void FigureSelected(FigureSelectedEventArgs arg)
		{
			var sourceRect = new RelativeSelection(
				_page.PageDimensions,
				arg.RelativeOffsetX,
				arg.RelativeOffsetY,
				arg.RelativeWidth,
				arg.RelativeHeight);

			var figure = _page.CreateFigure(sourceRect);
			_figureMap.Add(arg.Id, figure);

			var figureSelectedEvent = new FigureSelectedEvent(
				figure,
				() => {
					_page.RemoveFigure(_figureMap[arg.Id]);
					_figureMap.Remove(arg.Id);
					arg.Undo();
				});

			_messageBus.Publish(figureSelectedEvent);
		}
Ejemplo n.º 2
0
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);

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

                RaiseEvent(_currentSelectionEventArgs);
                _currentSelection = null;
                _currentSelectionEventArgs = null;
            }
        }
Ejemplo n.º 3
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;
            }
        }