Exemple #1
0
        /// <summary>
        /// Creates an ornament from string line and adds it to given shape
        /// </summary>
        /// <returns>Ornament this method created</returns>
        private Ornament CreateOrnament(string line, Shape.Shape shape)
        {
            line.Trim('\t');
            string[] words = line.Split(' ');
            Ornament o     = new Ornament(words[2].Trim('\"'), OrnamentHelper.GetOrnamentOrientationFromString(words[1]), shape);
            var      cmd   = new AddOrnament(
                shape,
                o);

            cmd.Execute();
            return(o);
        }
        public ButtonCollection(CanvasManager canvasManager)
        {
            buttons.Add(new Button(10, 10, "Rectangle", () =>
            {
                MakeFigure mf = new MakeFigure(canvasManager, new BasicFigure(120, 20, 30, 30, BasicFigure.RectangleStrategy.Instance));
                canvasManager.Do(mf);
                return(true);
            }));

            buttons.Add(new Button(10, 10 + 25 * 1, "Ellipse", () =>
            {
                MakeFigure mf = new MakeFigure(canvasManager, new BasicFigure(120, 60, 30, 30, BasicFigure.EllipseStrategy.Instance));
                canvasManager.Do(mf);
                return(true);
            }));

            buttons.Add(new Button(10, 10 + 25 * 2, "Undo", () =>
            {
                canvasManager.Undo();
                return(true);
            }));
            buttons.Add(new Button(10, 10 + 25 * 3, "Redo", () =>
            {
                canvasManager.Redo();
                return(true);
            }));

            buttons.Add(new Button(10, 10 + 25 * 4, "Open", () =>
            {
                Console.WriteLine("Open pressed!");
                var fl = new FileLoader("./grammar.test");
                canvasManager.canvas.AddFigure(fl.Read());
                return(true);
            }));

            buttons.Add(new Button(10, 10 + 25 * 5, "Save", () =>
            {
                Console.WriteLine("Save pressed!");
                var fw = new FileWriter("./drawing.cd");
                fw.Write(ref canvasManager.canvas.figures);
                return(true);
            }));

            buttons.Add(new Button(10, 10 + 25 * 6, "Select", () =>
            {
                canvasManager.canvas.selecting = !canvasManager.canvas.selecting;
                if (canvasManager.canvas.selecting)
                {
                    Console.WriteLine("Select enabled!");
                }
                else
                {
                    Console.WriteLine("Select disabled!");
                    canvasManager.canvas.selectedFigures.Clear();
                }
                return(true);
            }));
            buttons.Add(new Button(10, 10 + 25 * 7, "Group", () =>
            {
                var mf = new GroupFigures(canvasManager, canvasManager.canvas.selectedFigures);
                canvasManager.Do(mf);
                canvasManager.canvas.selectedFigures.Clear();
                Console.WriteLine("Group pressed!");
                return(true);
            }));
            buttons.Add(new Button(10, 10 + 25 * 8, "Ornament", () =>
            {
                Console.WriteLine("Ornament pressed!");
                var ao = new AddOrnament(canvasManager, canvasManager.canvas.selectedFigures);
                canvasManager.Do(ao);
                return(true);
            }));
        }