コード例 #1
0
ファイル: MainForm.cs プロジェクト: Skrylax/Paint-Application
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            bool hasMoved = mouseDownLocation.X != e.X || mouseDownLocation.Y != e.Y;

            if (hasSelected)
            {
                if (hasSecondSelected)
                {
                    ShapeComposite newGroup = new ShapeComposite("group");
                    newGroup.AddChild(SelectedShape);
                    newGroup.AddChild(SecondSelectedShape);

                    shapeList.Remove(SelectedShape);
                    shapeList.Remove(SecondSelectedShape);

                    SecondSelectedShape.selected = false;
                    SecondSelectedShape          = null;

                    Command groupShape = new AddShapeCommand(shapeList, newGroup);
                    history.Add(groupShape);

                    Command selectShape = new SelectShapeCommand(newGroup, this);
                    history.Add(selectShape);
                }

                if (hasMoved)
                {
                    Point   velocity  = new Point(e.Location.X - mouseDownLocation.X, e.Location.Y - mouseDownLocation.Y);
                    Command moveShape = new MoveShapeCommand(SelectedShape, velocity, shapeStartPosition);
                    history.Add(moveShape);
                }

                Invalidate();
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Skrylax/Paint-Application
        private void RectangleButton_Click(object sender, EventArgs e)
        {
            Command addShape = new AddShapeCommand(shapeList, new BaseShape("rectangle", 50, 50, 50, 50, RectangleStategy.Instance()));

            history.Add(addShape);
            Invalidate();
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Skrylax/Paint-Application
        private void EllipseButton_Click(object sender, EventArgs e)
        {
            Command addShape = new AddShapeCommand(shapeList, new EllipseShape("ellipse", 50, 50, 50, 50));

            history.Add(addShape);
            Invalidate();
        }
コード例 #4
0
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileInputOutput fileInput = new FileInputOutput(openFileDialog.OpenFile());
                fileInput.CreateList();

                foreach (string[] shape in fileInput.streamList)
                {
                    if (shape[0] == "rectangle")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new RectangleShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        history.Add(addShape);
                    }

                    if (shape[0] == "ellipse")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new EllipseShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        history.Add(addShape);
                    }
                }
            }
            Invalidate();
        }
コード例 #5
0
ファイル: ShapeFactory.cs プロジェクト: ChrisMoreton/Test3
 public static void AddShape(Connectable shape, ShapeTypes type)
 {
     if (shape == null)
         throw new ArgumentNullException("A null cannot be added to the shape collection.");
     //the undo trick
     AddShapeCommand cmd = new AddShapeCommand(shape, type, Canvas);
     UndoManager.Execute(cmd);
     RaiseOnShapeAdded(shape);
 }
コード例 #6
0
ファイル: ShapeFactory.cs プロジェクト: 15831944/Test3-1
        public static void AddShape(Connectable shape, ShapeTypes type)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("A null cannot be added to the shape collection.");
            }
            //the undo trick
            AddShapeCommand cmd = new AddShapeCommand(shape, type, Canvas);

            UndoManager.Execute(cmd);
            RaiseOnShapeAdded(shape);
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: Skrylax/Paint-Application
        // Open existing file
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileInputOutput fileInput = new FileInputOutput(openFileDialog.OpenFile());
                fileInput.CreateList();
                List <string[]> tempList = fileInput.streamList;

                Stack <Command> commandStack = new Stack <Command>();

                foreach (string[] shape in fileInput.streamList)
                {
                    if (shape[0] == "rectangle")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new RectangleShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        commandStack.Push(addShape);
                    }

                    if (shape[0] == "ellipse")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new EllipseShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        commandStack.Push(addShape);
                    }

                    if (shape[0] == "group")
                    {
                        ShapeComposite newGroup = new ShapeComposite(shape[0]);
                        // TODO: pop groupsize add composite shape
                        //newGroup.AddChild(commandStack.Pop());
                    }
                }

                //foreach (string[] shape in fileInput.streamList)
                //{
                //    if (shape[0] == "rectangle")
                //    {
                //        Command addShape = new AddShapeCommand(shapeList, new RectangleShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                //        history.Add(addShape);
                //    }

                //    if (shape[0] == "ellipse")
                //    {
                //        Command addShape = new AddShapeCommand(shapeList, new EllipseShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                //        history.Add(addShape);
                //    }
                //}
            }
            Invalidate();
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: dimonstrer/Editor
 public Form1()
 {
     InitializeComponent();
     commands[Keys.Right.ToString()]  = new MoveCommand(s1, this, 10, 0);
     commands[Keys.Left.ToString()]   = new MoveCommand(s1, this, -10, 0);
     commands[Keys.Up.ToString()]     = new MoveCommand(s1, this, 0, -10);
     commands[Keys.Down.ToString()]   = new MoveCommand(s1, this, 0, 10);
     commands[Keys.Delete.ToString()] = new DeleteCommand(s1, this);
     commands["Group"]     = new GroupCommand(s1, this);
     commands["Ungroup"]   = new UngroupCommand(s1, this);
     commands["AddShape"]  = new AddShapeCommand(s1, this);
     commands["Select"]    = new SelectCommand(s1, this);
     commands["MouseMove"] = new MouseMoveCommand(s1, this);
     currFig = 0;
 }
コード例 #9
0
        private void field_MouseUp(object sender, MouseEventArgs e)
        {
            if (isClicked)
            {
                Pen pen = new Pen(Color.Black);

                if (currentButton.Text == "|")
                {
                    var command = new AddShapeCommand(log, new Line(true, new Parameters(start, e.Location, pen)));
                    manager.Execute(command);
                }

                if ((currentButton.Text == "allocate") && (movedShape != null))
                {
                    var command = new ChangePointsCommand(log, movedShape, new Parameters(start, e.Location, pen));
                    manager.Execute(command);
                }

                isClicked = false;
            }

            field.Invalidate();
        }
コード例 #10
0
ファイル: MainViewModel.cs プロジェクト: nymann/WPDTU
        /// <summary>
        /// PerformCanvasMouseDown - Called when the canvas is clicked, will NOT be called when clicking a shape.
        /// </summary>
        /// <param name="e"></param>
        private void PerformCanvasMouseDown(MouseButtonEventArgs e)
        {
            try
            {
                // TODO: The behavior is kinda fishy..
                if (_shapeMode)
                {
                    var source = e.Source as UIElement;
                    var point  = source is Canvas?e.GetPosition(source) : RelativeMousePosition(e);

                    var model = new UMLShape(point.X, point.Y, GetDefaultHeight(_toolboxShapeValue),
                                             GetDefaultWidth(_toolboxShapeValue), _toolboxShapeValue);
                    var shapeToAdd = new ShapeViewModel(model);

                    // If we already have a initial node on canvas, don't allow another one.
                    if ((shapeToAdd.Type == EShape.Initial) && DoesShapesContainInitialNode())
                    {
                        System.Windows.MessageBox.Show("Canvas can only contain one initial node.");
                    }
                    else
                    {
                        Shapes.Add(shapeToAdd);
                        IUndoRedoCommand cmd = new AddShapeCommand(shapeToAdd, this);
                        _undoRedo.InsertInUndoRedo(cmd);
                    }
                }
                else if (SelectedElements != null)
                {
                    ClearSelection();
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(Constants.Messages.GenericError);
                Console.WriteLine(ex.Message);
            }
        }
コード例 #11
0
        /// <summary>
        /// This method will be called when the user has finished drawing a ghost rectangle or bundle
        /// and initiates the actual creation of a bundle and the addition to the model via the appropriate command.
        /// </summary>
        protected override void GhostDrawingComplete()
        {
            try
            {
                TextOnly shape = new TextOnly(this.Controller.Model);
                shape.Width  = (int)Rectangle.Width;
                shape.Height = (int)Rectangle.Height;
                shape.Text   = "New label";

                AddShapeCommand cmd = new AddShapeCommand(this.Controller, shape, new Point((int)Rectangle.X, (int)Rectangle.Y));
                this.Controller.UndoManager.AddUndoCommand(cmd);
                cmd.Redo();
                TextEditor.GetEditor(shape);
                TextEditor.Show();
            }
            catch
            {
                base.Controller.DeactivateTool(this);
                Controller.View.Invalidate();
                throw;
            }

            base.Controller.DeactivateTool(this);
        }