Esempio n. 1
0
 private void color_Click_1(object sender, EventArgs e)
 {
     if (colorDialog1.ShowDialog() == DialogResult.OK)
     {
         for (int i = 0; i < storage.getCount(); i++)
         {
             if (storage.GetFigure(i).getChosen() == true)
             {
                 ChangeColorCommand ch_color = (ChangeColorCommand)commands["ChangeColor"].clon();
                 ch_color.execute(storage, colorDialog1.Color);
                 history.Push(ch_color);
                 ChosenCommand ch_com = (ChosenCommand)commands["Chosen"].clon();
                 ch_com.execute(storage, i);
                 history.Push(ch_com);
             }
         }
     }
     Refresh();
 }
Esempio n. 2
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            bool flag = false;

            for (int i = 0; i < storage.getCount(); i++)
            {
                if (storage.GetFigure(i).countDist(e.X, e.Y) == true)
                {
                    ChosenCommand ch_com = (ChosenCommand)commands["Chosen"].clon();
                    ch_com.execute(storage, i);
                    history.Push(ch_com);
                    flag = true;
                    break;
                }
            }

            if (flag == false)
            {
                for (int i = 0; i < storage.getCount(); i++)
                {
                    if (storage.GetFigure(i).getChosen() == true)
                    {
                        ChosenCommand ch_com = (ChosenCommand)commands["Chosen"].clon();
                        ch_com.execute(storage, i);
                        history.Push(ch_com);
                        flag = true;
                    }
                }

                if (storage.getKind() == 1)
                {
                    CreateFigureCommand create = (CreateFigureCommand)commands["Create"].clon();
                    create.execute("line", storage, e.X, e.Y);
                    history.Push(create);
                }

                if (storage.getKind() == 2)
                {
                    CreateFigureCommand create = (CreateFigureCommand)commands["Create"].clon();
                    create.execute("circle", storage, e.X, e.Y);
                    history.Push(create);
                }

                if (storage.getKind() == 3)
                {
                    CreateFigureCommand create = (CreateFigureCommand)commands["Create"].clon();
                    create.execute("Triangle", storage, e.X, e.Y);
                    history.Push(create);
                }

                if (storage.getKind() == 4)
                {
                    CreateFigureCommand create = (CreateFigureCommand)commands["Create"].clon();
                    create.execute("rectangle", storage, e.X, e.Y);
                    history.Push(create);
                }
            }

            undo_unexecute.Enabled = true;
            Refresh();
        }