Пример #1
0
        public void Paint(Graphics g, Size size)
        {
            LocalMessageBus.Send(null,
                                 new MenuMessage(
                                     new MenuCommand[]
            {
                new MenuCommand {
                    Command = MenuCommands.Delete, Enabled = SelectedCount > 0
                }
                , new MenuCommand {
                    Command = MenuCommands.Copy, Enabled = !(Count < 1 || SelectedCount < 1)
                }
                , new MenuCommand {
                    Command = MenuCommands.Paste, Enabled = CopyAction.Current.CanPaste
                }
            }
                                     ));
            if (Count < 1 || SelectedCount < 1)
            {
                LocalMessageBus.Send(this, new IsSelectShapImage(false));
            }
            else if (SelectedCount == 1 && SelectedShape.Type == ShapeType.Image)
            {
                LocalMessageBus.Send(this, new IsSelectShapImage(true));
            }
            else
            {
                LocalMessageBus.Send(this, new IsSelectShapImage(false));
            }

            if (Count < 1)
            {
                return;
            }

            Visitor.Graphics = g;
            Visitor.Zoom     = Zoom;

            UndoService.Suspend();
            //paint background Layer
            ShapeBase backItem = Find(delegate(ShapeBase item)
            {
                return(item.IsBackground && item.IsVisible);
            });

            if (backItem != null)
            {
                if (backItem.VirtualBounds.Size != size)
                {
                    backItem.BeginEdit();
                    backItem.VirtualBounds = new Rectangle(Point.Empty, size);
                    backItem.EndEdit();
                }
                //backItem.Paint(g);
                backItem.Accept(Visitor);
            }

            ShapeBase[] shapes = this.ToArray();

            bool drawSpecialShape = false;

            //paint all layers except dynamic layers
            foreach (ShapeBase shape in shapes)
            {
                if (!shape.IsVisible ||
                    shape.IsBackground
                    //|| shape.Type == ShapeType.DynamicText
                    //|| shape.Type == ShapeType.DynamicVideo
                    )
                {
                    continue;
                }

                if (shape.Type == ShapeType.DownArrow ||
                    shape.Type == ShapeType.Ellipse ||
                    shape.Type == ShapeType.LeftArrow ||
                    shape.Type == ShapeType.Line ||
                    shape.Type == ShapeType.Rectangle ||
                    shape.Type == ShapeType.RightArrow ||
                    shape.Type == ShapeType.UpArrow)
                {
                    if (!drawSpecialShape)
                    {
                        DrawSpecialShape(shapes, g);
                        drawSpecialShape = true;
                    }
                }
                else
                {
                    shape.Accept(Visitor); //shape.Paint(g);
                }
            }

            //paint dynamic layers
            //将DynamicText层永远显示在最上面 add by Michael
            foreach (ShapeBase shape in shapes)
            {
                if (shape.IsVisible && shape.IsDynamicLayer /*(shape.Type == ShapeType.DynamicText)*/)
                {
                    shape.Accept(Visitor);//shape.Paint(g);
                }
            }

            //paint selected layers' frame
            foreach (ShapeBase shape in shapes)
            {
                if (!shape.IsVisible || !shape.IsSelected)
                {
                    continue;
                }
                //shape.PaintSelect(g, true);
                shape.DrawTracker(g);
            }

            UndoService.Resume();
        }