Ejemplo n.º 1
0
        private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            bitmap.CopyInNew();

            if (mouseDown)
            {
                if (_reversal && ActiveFigure != null)
                {
                    int rev = e.Y - FirstPoint.Y;
                    ActiveFigure.SetAngle(rev);
                    bitmap.DeleteFigure(ActiveFigure);
                    bitmap.DrawFigure(ActiveFigure);
                }
                if (_changeLocation)
                {
                    fill            = false;
                    _deletingFigure = false;

                    Point delta = new Point();

                    delta.X    = e.X - FirstPoint.X;
                    delta.Y    = e.Y - FirstPoint.Y;
                    FirstPoint = e.Location;

                    if (CurrentFigure == null)
                    {
                        CurrentFigure = bitmap.SelectFigureByPoint(e.Location);
                        if (CurrentFigure != null)
                        {
                            bitmap.Bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
                            bitmap.DeleteFigure(CurrentFigure);
                        }
                    }
                    if (CurrentFigure != null)
                    {
                        bitmap.ShowOnTheScreen();
                        CurrentFigure.Move(delta);
                        bitmap.DrawFigure(CurrentFigure);
                        mode = "Рисуем";
                    }
                }

                else if (toolBox.SelectedIndex == 0)
                {
                    SecondPoint = FirstPoint;
                    FirstPoint  = e.Location;
                    bitmap.DrawLine(FirstPoint, SecondPoint, _currentThickness, _currentColor);
                    bitmap.CopyInOld();
                    pictureBox.Image = bitmap.Bitmap;
                }
                else if (toolBox.SelectedIndex != 6 && toolBox.SelectedIndex != -1 && mode == "Рисуем")
                {
                    if (CurrentFigure == null && factoryFigure != null)
                    {
                        CurrentFigure = factoryFigure.Create(FirstPoint, n, _currentColor, _fillColor, _currentThickness);
                    }

                    if (CurrentFigure != null)
                    {
                        CurrentFigure.Update(e.Location);
                        bitmap.DrawFigure(CurrentFigure);
                    }
                }
            }
            if (mode == "Изменить" && mouseDown)  //mode == "Изменить"
            {
                ActiveFigure.Update(e.Location);
                bitmap.DrawFigure(ActiveFigure);
            }

            if (bitmap.SelectFigureByPointq(e.Location) && mode != "Выбрал" && mode != "Изменить" && mode != "Заливка")
            {
                CurrentFigure = bitmap.GetAFigure();
                bitmap.HighlightSelectedFigure(CurrentFigure);
                mode = "Навел";
            }
            else if (mode != "Выбрал" && mode != "Изменить" && mode != "Заливка")
            {
                mode = "Рисуем";
            }

            if (mode == "Выбрал")
            {
                q = bitmap.PointInPoint(ActiveFigure, e.Location);
            }

            if (toolBox.SelectedIndex != -1 && mode != "Изменить")
            {
                _changeLocation = false;
                _deletingFigure = false;
                _editFigure     = false;
                _reversal       = false;
            }
            xLabel.Text    = $"X = {e.X}";
            Ylabel.Text    = $"Y = {e.Y}";
            modeLabel.Text = mode;
            GC.Collect();

            pictureBox.Image = bitmap.tmpBitmap;
        }