Example #1
0
        private void addNewFigureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (addDllDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            Assembly asm           = Assembly.LoadFrom(addDllDialog.FileName);
            var      interfaceType = typeof(IFigureFactory);

            Type[] types = asm.GetTypes().Where(t => t != interfaceType && interfaceType.IsAssignableFrom(t)).ToArray();
            foreach (var type in types)
            {
                IFigureFactory factory = (IFigureFactory)Activator.CreateInstance(type);
                exportedTypes.Add(factory.FigureType);
                ToolStripButton btn = new ToolStripButton
                {
                    AutoSize              = false,
                    Size                  = new Size(39, 40),
                    Text                  = factory.Name,
                    DisplayStyle          = ToolStripItemDisplayStyle.Image,
                    Image                 = Properties.Resources.pen,
                    ImageTransparentColor = Color.Magenta
                };
                btn.Click += (object send, EventArgs args) => instantiateFigure = delegate()
                {
                    Figure fig = factory.Instantiate();
                    fig.Canvas     = FiguresProperties.Canvas;
                    fig.DrawingPen = new Pen(new SolidBrush(FiguresProperties.CurrBrushColor));
                    return(fig);
                };
                toolStrip1.Items.Add(btn);
            }
        }
Example #2
0
        private void pictureBox_MouseClick(object sender, MouseEventArgs e)
        {
            if (toolBox.SelectedIndex == 6)
            {
                if (count == 0)
                {
                    list.Add(e.Location);
                    count++;
                }
                else if (count == 1)
                {
                    list.Add(e.Location);
                    count++;
                }
                else if (count == 2)
                {
                    list.Add(e.Location);
                    factoryFigure = new TriangleFactory(list);

                    count = 0;
                    list  = new List <Point>();

                    CurrentFigure = factoryFigure.Create(FirstPoint, n, _currentColor, _fillColor, _currentThickness);
                    bitmap.DrawFigure(CurrentFigure);
                }
            }
        }
        private void FigureNamesCmbBx_SelectedIndexChanged(object sender, EventArgs e)
        {
            RectangleModeGrpBx.Visible = false;

            if ((FigureNamesCmbBx.SelectedItem as string) == FigureNames.Rectangle)
            {
                _figureFactory             = new CustomRectangleFactory();
                RectangleModeGrpBx.Visible = true;
            }
            else if ((FigureNamesCmbBx.SelectedItem as string) == FigureNames.Circle)
            {
                _figureFactory = new CircleFactory();
                AdjustWidthAndHeightTxtBx(true);
            }
            else if ((FigureNamesCmbBx.SelectedItem as string) == FigureNames.Rhomb)
            {
                _figureFactory = new RhombFactory();
                AdjustWidthAndHeightTxtBx(true);
            }
            else
            {
                _figureFactory = new TriangleFactory();
                AdjustWidthAndHeightTxtBx(true);
            }
        }
Example #4
0
        public Board(int matrixSize, IFigureFactory figureFactory, ICellFactory cellFactory)
        {
            _figureFactory = figureFactory;
            _cellFactory   = cellFactory;

            Size = matrixSize;

            _cells = CreateCells();
        }
Example #5
0
        private void RightTriangle_Click(object sender, EventArgs e)
        {
            textBox1.Visible      = false;
            numericUpDown.Visible = false;
            Button Btn = sender as Button;

            if (Btn != null)
            {
                setColor(this, Btn);
            }
            figureFactory = new RightTriangleFactory();
            figure        = figureFactory.CreateFigure(figure.FigureController);
            PaintMode     = true;
        }
Example #6
0
 public EditorForm()
 {
     InitializeComponent();
     SizeLabel.Text    = Convert.ToString($"{pictureBox.Width} X {pictureBox.Height}");
     canvas            = new Canvas(pictureBox.Width, pictureBox.Height);
     canvas.PictureBox = pictureBox;
     canvas.TmpBitmap  = (Bitmap)canvas.MainBitmap.Clone();
     canvas.Graphics   = Graphics.FromImage(canvas.TmpBitmap);
     pictureBox.Image  = canvas.MainBitmap;
     pen            = new Pen(Color.Black, (int)numericUpDown1.Value);
     pen.StartCap   = LineCap.Round;
     pen.EndCap     = LineCap.Round;
     figure         = new BrushFigure(new BrushController());
     toolController = new HandController();
     figureFactory  = new BrushFactory();
     tool           = new HandTool(new HandSelector());
     container      = new Container();
 }
Example #7
0
        static void Main()
        {
            Form form = new Form();

            form.Width  = 800;
            form.Height = 600;
            DrawingBoard.Init(form);
            form.Show();
            //DrawingBoard.Draw();

            //Использование абстрактной фабрики
            IFigureFactory figureFactory = LoadFactory();

            for (int i = 0; i < 20; i++)
            {
                IDrawAPI circle = figureFactory.GetFigure("CircleFigure");
                circle.DrawAt(random.Next(0, DrawingBoard.Width - MAXWIDTHOFFSET), random.Next(TEXTOFFSET, DrawingBoard.Height - MAXHEIGTHOFFSET));
            }

            for (int i = 0; i < 20; i++)
            {
                IDrawAPI circle = figureFactory.GetFigure("SquareFigure");
                circle.DrawAt(random.Next(0, DrawingBoard.Width - MAXWIDTHOFFSET), random.Next(TEXTOFFSET, DrawingBoard.Height - MAXHEIGTHOFFSET));
            }

            for (int i = 0; i < 20; i++)
            {
                IDrawAPI circle = figureFactory.GetFigure("RectangleFigure");
                circle.DrawAt(random.Next(0, DrawingBoard.Width - MAXWIDTHOFFSET), random.Next(TEXTOFFSET, DrawingBoard.Height - MAXHEIGTHOFFSET));
            }

            DrawingBoard.Buffer.Graphics.DrawString($"Circle instances:{CircleFigure.ObjectCounter}" +
                                                    $"\nSquare instances:{SquareFigure.ObjectCounter}" +
                                                    $"\nRectangle instances:{RectangleFigure.ObjectCounter}",
                                                    SystemFonts.DefaultFont,
                                                    Brushes.White,
                                                    0, 0);
            DrawingBoard.Draw();
            Application.Run(form);
        }
Example #8
0
        static void Main(string[] args)
        {
            // создание объекта с расширяемыми свойствами
            dynamic flex = new ExpandoObject();

            TestDynamic(flex);
            // предполагаю, что для добавления свойств произвольному объект требуется использовать DLR и
            // наследоваться от DynamicObject, так как ExpandoObject помечен как не наследуемый
            // Вариант реализации класса ElastoClass
            dynamic ec = new ElastoClass();

            TestDynamic(ec);

            IFigureFactory figureFactory = LoadFactory();

            IFigure[] figures =
            {
                figureFactory.CreateInstance("Rectangle", new Point(0,   0)),
                figureFactory.CreateInstance("Square",    new Point(20, 30)),
                figureFactory.CreateInstance("Box",       new Point(33, 22)),
                figureFactory.CreateInstance("LowCicle",  new Point(33, 22))
            };
            foreach (var figure in figures)
            {
                Console.WriteLine($"Фигура: {figure.GetType()} , {figure} ");
            }

            IFigureCreator[] creators =
            {
                new RectangleCreator(new Point(10, 10)),
                new LowCicleCreator(new Point(12,  15)),
                new SquareCreator(new Point(20, 10))
            };

            foreach (IFigureCreator creator in creators)
            {
                Console.WriteLine($"Фигура: {creator.GetType()} , { creator.Create()} ");
            }
        }
 public void RegisterFigureFactory(IFigureFactory factory)
 {
     _factory = factory ?? throw new ArgumentNullException();
 }
 public MouseHandlerOnDrawRectangle(IFigureFactory factory)
 {
     FigureFactory = factory;
 }
Example #11
0
 public MouseHandlerOnDrawArrows(IFigureFactory figureFactory)
 {
     IsTapped      = false;
     FigureFactory = figureFactory;
 }
Example #12
0
        private void toolBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Change_location.Hide();
            DeleteFigure.Hide();
            Reversal.Hide();

            switch (toolBox.SelectedIndex)
            {
            case 1:
                textBox1.Hide();
                factoryFigure = new LineFactory();
                break;

            case 2:
                textBox1.Hide();
                factoryFigure = new RectangleFactory();
                break;

            case 3:
                textBox1.Hide();
                factoryFigure = new SquareFactory();
                break;

            case 4:
                textBox1.Show();
                if (textBox1.Text == "Количество граней")
                {
                    MessageBox.Show("Введите количество граней 3 или больше.");
                }
                textBox1.Text = "";
                factoryFigure = new NSidedPolygonFactory();
                break;

            case 5:
                textBox1.Hide();
                factoryFigure = new TrapezoidFactory();
                break;

            case 6:
                textBox1.Hide();
                factoryFigure = null;
                break;

            case 7:
                textBox1.Hide();
                factoryFigure = new RightTriangleFactory();
                break;

            case 8:
                textBox1.Hide();
                factoryFigure = new IsoscelesTriangleFactory();
                break;

            case 10:
                textBox1.Hide();
                factoryFigure = new CircleFactory();
                break;

            case 11:
                textBox1.Hide();
                factoryFigure = new EllipseFactory();
                break;
            }
        }