示例#1
0
 public void Select(Graphics gr, List <Figure> figures, Group group, Manipulator manipulator, float x, float y)
 {
     foreach (var fig in figures)
     {
         if (fig.Touch(gr, x, y))
         {
             group.Clear();
             manipulator.Attach(fig);
             break;
         }
         else
         {
             manipulator.Clear(gr);
         }
     }
 }
示例#2
0
        public Main()
        {
            Tools.Add("", null);
            Tools.Add("Rectangle", new MyRectangle.RectangleCreator());
            Tools.Add("Ellipse", new MyEllipse.EllipseCreator());


            this.ClientSize = new System.Drawing.Size(1500, 1000);

            InitializeComponent();

            RectangelButton.Click += (s, a) => {
                //if (CurrentFig != null) CurrentFig = null;
                FigureCreator = Tools[RectangelButton.Text];
                group.Clear();
                manipulator.Clear(gr);
                pictureBox1.Refresh();
            };

            EllipseButton.Click += (s, a) => {
                //if (CurrentFig != null) CurrentFig = null;
                FigureCreator = Tools[EllipseButton.Text];
                group.Clear();
                manipulator.Clear(gr);
                pictureBox1.Refresh();
            };

            SelectButton.Click += (s, a) => {
                //if (CurrentFig != null) CurrentFig = null;
                FigureCreator = Tools[""];
                group.Clear();
                manipulator.Clear(gr);
                pictureBox1.Refresh();
            };

            ClearButton.Click += (s, a) =>
            {
                //if (CurrentFig != null) CurrentFig = null;
                Figures.Clear();
                group.Clear();
                //command.Clear();
                manipulator.Clear(gr);
                pictureBox1.Refresh();
            };

            NewFigBtn.Click += (s, a) =>
            {
                if (manipulator.fig == null)
                {
                    return;
                }
                GroupCreator groupCreator = new GroupCreator();
                groupCreator.CopyCreated(group);
                Tools.Add($"Group {comboBox1.Items.Count + 1}", groupCreator);
                comboBox1.Items.Add($"Group {comboBox1.Items.Count + 1}");
            };

            DrawGroupBtn.Click += (s, a) =>
            {
                if (comboBox1.SelectedIndex == -1)
                {
                    return;
                }
                FigureCreator = Tools[comboBox1.SelectedItem.ToString()];
            };

            //CancelButton.Click += (s, a) =>
            //{
            //    if(Figures.Count != 0)
            //        //if (UsedFigures.Count != 0)
            //        //{
            //            //int index = -1;
            //            //CurrentFig = UsedFigures.Pop();
            //            foreach (var f in Figures)
            //                if (f.X == CurrentFig.X &&
            //                    f.Y == CurrentFig.Y &&
            //                    f.H == CurrentFig.H &&
            //                    f.W == CurrentFig.W)
            //                {
            //                    //index = Figures.IndexOf(f);
            //                    //command.Undo();
            //                    //CurrentFig = command.Figure;
            //                    if (CurrentFig == null)
            //                        Figures.RemoveAt(index);
            //                    else
            //                        Figures[index] = CurrentFig;
            //                    break;
            //                }
            //            manipulator.Clear(gr);
            //            pictureBox1.Refresh();
            //        //}
            //        else MessageBox.Show("Стек пуст");
            //};

            gr = pictureBox1.CreateGraphics();
            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        }