Exemple #1
0
        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            LabelX.Content = "X = " + e.GetPosition(CanvasMain).X;
            LabelY.Content = "Y = " + e.GetPosition(CanvasMain).Y;
            var point = e.GetPosition(CanvasMain);

            if (_isDraw && !_isMove && (e.LeftButton == MouseButtonState.Pressed))
            {
                _x2 = point.X;
                _y2 = point.Y;
                ChangingObjects();

                PrintFigure(_figures[_tag]);
                if (_isConnected)
                {
                    UdpHelper.SendFigure(Command.Point, _figures[_tag], _client, _isOneFigure);
                }

                _figures.Clear();
            }
            else if (_isMove && e.LeftButton == MouseButtonState.Pressed)
            {
                _figure.FirstPoint.X  = _oldPointFirst.X + (point.X - _x1);
                _figure.SecondPoint.X = _oldPointSecond.X + (point.X - _x1);
                _figure.FirstPoint.Y  = _oldPointFirst.Y + (point.Y - _y1);
                _figure.SecondPoint.Y = _oldPointSecond.Y + (point.Y - _y1);

                if (_isConnected)
                {
                    UdpHelper.SendFigure(Command.Move, _figure, _client, _isOneFigure);
                }

                if (_isOneFigure)
                {
                    CanvasMain.Children.Remove(_chousenShape);
                }
                else
                {
                    CanvasMain.Children.RemoveAt(CanvasMain.Children.Count - 1);
                }

                _isOneFigure = false;
                _figure.SetColor();
                _figure.Draw(CanvasMain);
                _figure.Tag = CanvasMain.Children.IndexOf(CanvasMain.Children[CanvasMain.Children.Count - 1]);
                _shape.Figures.Add(_figure);
                SetEventOnLastFigure();
            }
        }
Exemple #2
0
        private void PrintFigure(Figure figure)
        {
            Dispatcher.Invoke(() =>
            {
                if (_isOneFigure)
                {
                    CanvasMain.Children.RemoveAt(CanvasMain.Children.Count - 1);
                    _shape.Figures.RemoveAt(_shape.Figures.Count - 1);
                }

                _shape.Figures.Add(figure);
                figure.SetColor();
                figure.Draw(CanvasMain);
                _isOneFigure = true;
                SetEventOnLastFigure();
            });
        }
Exemple #3
0
        private void ReceiveMoveFigure(Figure figure)
        {
            Dispatcher.Invoke(() =>
            {
                if (CanvasMain.Children.Count <= figure.Tag)
                {
                    return;
                }

                if (_isOneFigure)
                {
                    CanvasMain.Children.RemoveAt(figure.Tag);
                }
                else
                {
                    CanvasMain.Children.RemoveAt(CanvasMain.Children.Count - 1);
                }

                figure.SetColor();
                figure.Draw(CanvasMain);
                _shape.Figures.Add(figure);
                SetEventOnLastFigure();
            });
        }