示例#1
0
        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed || e.RightButton == MouseButtonState.Pressed)
            {
                int   opacity = _drawing ? 1 : 0;
                int   factor  = _drawing ? 1 : -1;
                Brush fill    = _drawing ? DrawColour : null;

                LineSegment line = new LineSegment
                {
                    X1 = _currentPoint.X,
                    Y1 = _currentPoint.Y,
                    X2 = e.GetPosition(this).X,
                    Y2 = e.GetPosition(this).Y
                };

                for (int row = 0; row < Rectangles.GetLength(0); row++)
                {
                    for (int column = 0; column < Rectangles.GetLength(1); column++)
                    {
                        Rectangle rect = Rectangles[row, column];
                        double    x    = GetLeft(rect);
                        double    y    = GetTop(rect);

                        if (RectIntersectsLine(new Rect(x, y, rect.Width, rect.Height), line))
                        {
                            rect.Opacity = opacity;
                            rect.Fill    = fill;
                            if (SoftDrawing)
                            {
                                UpdateNeighbours(GetNeighbours(Rectangles, row, column), factor, fill);
                            }
                        }
                    }

                    InputChangedEvent?.Invoke(this);
                }

                _currentPoint = e.GetPosition(this);
            }
        }