Esempio n. 1
0
 private void RegisterForMessages()
 {
     Messenger.Default.Register <NotificationMessage>(this, message =>
     {
         if (message.Notification == Commands.AddItem)
         {
             if (CommandAdd.CanExecute(null))
             {
                 CommandAdd.Execute(null);
             }
         }
         else if (message.Notification == Commands.EditItem)
         {
             if (CommandEdit.CanExecute(null))
             {
                 CommandEdit.Execute(null);
             }
         }
         if (message.Notification == Commands.ResetItem)
         {
             if (CommandReset.CanExecute(null))
             {
                 CommandReset.Execute(null);
             }
         }
         else if (message.Notification == Commands.DeleteItem)
         {
             if (CommandDelete.CanExecute(null))
             {
                 CommandDelete.Execute(null);
             }
         }
         else if (message.Notification == Commands.ResetAll)
         {
             if (CommandResetAll.CanExecute(null))
             {
                 CommandResetAll.Execute(null);
             }
         }
     });
     Messenger.Default.Register <NotificationMessage <ItemModel> >(this, message =>
     {
         if (message.Notification == Notifications.NotifyItemSelected)
         {
             RaisePropertyChanged("IsItemSelected");
             RaiseCanExecuteChanged(CommandEdit);
             RaiseCanExecuteChanged(CommandReset);
             RaiseCanExecuteChanged(CommandDelete);
         }
     });
 }
Esempio n. 2
0
        private void bt_line_Click(object sender, EventArgs e)
        {
            DLine line = new DLine
            {
                MyBrush    = new SolidBrush(Color.FromArgb(128, Color.DarkOrchid)),
                Selectable = true
                             //X = e.Location.X,
                             //Y = e.Location.Y,
            };
            CommandAdd add = new CommandAdd();

            add.item = line;
            paintPanel1.SetCommand(add);
        }
Esempio n. 3
0
        private void bt_txt_Click(object sender, EventArgs e)
        {
            DText txt = new DText
            {
                MyBrush    = new SolidBrush(Color.FromArgb(128, Color.DarkOrchid)),
                Words      = tb_txt.Text,
                Selectable = true
                             //X = e.Location.X,
                             //Y = e.Location.Y,
            };
            CommandAdd add = new CommandAdd();

            add.item = txt;
            paintPanel1.SetCommand(add);
        }
Esempio n. 4
0
        private void bt_rect_Click(object sender, EventArgs e)
        {
            DRectangle rect = new DRectangle
            {
                MyBrush = new SolidBrush(Color.FromArgb(128, Color.DarkOrchid)),
                //X = e.Location.X,
                //Y = e.Location.Y,
                Width      = 20,
                Height     = 20,
                Selectable = true
            };
            CommandAdd add = new CommandAdd();

            add.item = rect;
            paintPanel1.SetCommand(add);
        }
Esempio n. 5
0
        private void PaintPanel_MouseClick(object sender, MouseEventArgs e)
        {
            Matrix matrix = new Matrix();

            Point[] points = new Point[1];
            points[0] = new Point(e.X, e.Y);
            if (scene.matrix != null)
            {
                matrix = scene.matrix.Clone();
            }
            if (e.Button == MouseButtons.Left)
            {
                if (command == null)
                {
                    var currentSelectedObj = scene.SelectObject(points[0].X, points[0].Y);
                    if (currentSelectedObj != null)
                    {
                        AddSelectedItem(currentSelectedObj);
                    }
                    return;
                }
                if (command is CommandAdd)
                {
                    CommandAdd addCommand = command as CommandAdd;
                    if (addCommand.item != null)
                    {
                        if (!firstStepDone) // 第一次画
                        {
                            addCommand.item.X = e.X;
                            addCommand.item.Y = e.Y;
                            firstStepDone     = true;
                            scene.AddDrawingObject(addCommand.item);
                        }
                        else
                        {
                            if (addCommand.item is DPath)
                            {
                                ((DPath)addCommand.item).ConfirmPoint(new Point(points[0].X, points[0].Y));
                            }
                            else if (addCommand.item is DLine)
                            {
                                ((DLine)addCommand.item).X2 = points[0].X;
                                ((DLine)addCommand.item).Y2 = points[0].Y;
                                command      = null;
                                finishedStep = true;
                            }
                        }
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (command is CommandAdd)
                {
                    CommandAdd addCommand = command as CommandAdd;
                    if (addCommand.item != null)
                    {
                        if (addCommand.item is DPath)
                        {
                            ((DPath)addCommand.item).ConfirmPoint(new Point(points[0].X, points[0].Y));
                            command      = null;
                            finishedStep = true;
                        }
                    }
                }
            }
        }