Beispiel #1
0
        /// <summary>
        /// 设置当前层里的shape对象是否显示
        /// add by michael
        /// </summary>
        internal void SetShapeVisible(LayerControl frameLayer)
        {
            ShapeBase shape = frameLayer.Layer.Shape;

            shape.BeginEdit();
            if (_IsShowAllLayers)
            {
                if (frameLayer.Layer.IsVisible)
                {
                    //frameLayer.Layer.IsVisible = true;
                    frameLayer.Shape.IsVisible = true;
                    shape.IsVisible            = true;
                }
                //return;
            }

            //else if (this.trackBar1.PlayValue < frameLayer.Layer.StartTime || this.trackBar1.PlayValue > frameLayer.Layer.EndTime)
            else if (frameLayer.StartTime <= this.trackBar1.PlayValue && frameLayer.EndTime > this.trackBar1.PlayValue)
            {
                if (frameLayer.Layer.IsVisible)
                {
                    //frameLayer.Layer.IsVisible = frameLayer.LayerVisible;
                    frameLayer.Shape.IsVisible = frameLayer.Layer.IsVisible;
                    shape.IsVisible            = frameLayer.Layer.IsVisible;
                }
            }
            else if (frameLayer.StartTime > this.trackBar1.PlayValue || frameLayer.EndTime <= this.trackBar1.PlayValue)
            {
                if (frameLayer.Layer.IsVisible)
                {
                    //frameLayer.Layer.IsVisible = false;
                    frameLayer.Shape.IsVisible = false;
                    shape.IsVisible            = false;
                }
            }

            shape.EndEdit();
            shapeControl.Invalidate();
        }
Beispiel #2
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();
        }
        //mouse button is released
        public override void OnMouseUp(Canvas drawArea, MouseEventArgs e)
        {
            if (selectMode == SelectionMode.MulitSelection)
            {
                return;
            }

            int zoom = drawArea.Document.Zoom;

            if (selectMode == SelectionMode.NetSelection)
            {
                // Group selection
                drawArea.Document.SelectInRectangle(drawArea.NetRectangle);

                selectMode = SelectionMode.None;
                drawArea.DrawNetRectangle = false;

                UndoService.Commit();
            }
            if (resizedObject != null ||
                selectMode == SelectionMode.Size
                )
            {
                // after resizing
                if (resizedObject != null)
                {
                    resizedObject.BeginEdit();
                    if (resizedObject is ShapePaint)
                    {
                        ; // resizedObject.SetVirtualBounds();
                    }
                    else
                    {
                        resizedObject.VirtualBounds = resizedObject.FormatBoundsByZoom(resizedObject.VirtualBounds, zoom);
                    }

                    resizedObject.EndEdit();
                    resizedObject = null;
                }

                selectMode = SelectionMode.None;
                UndoService.Commit();
            }

            if (selectMode == SelectionMode.Move)
            {
                foreach (ShapeBase sb in drawArea.Document.SelectedShapes)
                {
                    sb.BeginEdit();
                    if (sb is ShapeFigure
                        //|| sb is ShapeLine
                        )
                    {
                        sb.SetVirtualBounds();
                    }
                    else if (sb.Type != ShapeType.Line)
                    {
                        sb.VirtualBounds = sb.FormatBoundsByZoom(sb.VirtualBounds, zoom);
                    }

                    sb.EndEdit();
                }
                selectMode = SelectionMode.None;

                Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y));
                for (int i = drawArea.Document.Count - 1; i >= 0; i--)
                {
                    if (drawArea.Document[i].HitTest(point) == 0)
                    {
                        ShapeBase so = drawArea.Document[i];
                        if (so != null)
                        {
                            // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                            if ((Control.ModifierKeys != Keys.Control || Control.ModifierKeys != Keys.Shift) && so.IsSelected && startPoint == lastPoint)
                            {
                                drawArea.Document.CancelSelect(true);
                                so.IsSelected = true;
                            }
                        }
                        break;
                    }
                }

                UndoService.Commit();
            }

            drawArea.Capture = false;
            drawArea.Refresh();
            lastPoint = drawArea.BackTrackMouse(e.Location);
        }
Beispiel #4
0
 private void SetShapeSelectedWithShift(ShapeBase shape, bool selected)
 {
     shape.BeginEdit();
     shape.IsSelected = selected;
     shape.EndEdit();
 }
        public override void OnMouseDown(Canvas drawArea, MouseEventArgs e)
        {
            Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y));

            if (e.Button == MouseButtons.Left)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (drawArea.ShortcutKey == Keys.Control ||
                        drawArea.ShortcutKey == Keys.Shift)
                    {
                        selectMode = SelectionMode.MulitSelection;
                        for (int i = drawArea.Document.Count - 1; i >= 0; i--)
                        {
                            int handleNumber = drawArea.Document[i].HitTest(point);
                            if (handleNumber == 0)
                            {
                                drawArea.Document[i].IsSelected = !drawArea.Document[i].IsSelected;
                                break;
                            }
                        }
                        return;
                    }
                }

                wasMove    = false;
                selectMode = SelectionMode.None;

                // Test for resizing
                for (int i = drawArea.Document.Count - 1; i >= 0; i--)
                {
                    int handleNumber = drawArea.Document[i].HitTest(point);
                    if (handleNumber > 0)
                    {
                        selectMode = SelectionMode.Size;
                        UndoService.BeginTransaction("Resize the shape");
                        resizedObject = drawArea.Document[i];

                        resizedObjectHandle = handleNumber;

                        drawArea.Document.CancelSelect();
                        drawArea.Document[i].IsSelected = true;
                        break;
                    }
                }


                // Test for move
                if (selectMode == SelectionMode.None)
                {
                    ShapeBase so = null;
                    for (int i = drawArea.Document.Count - 1; i >= 0; i--)
                    {
                        if (drawArea.Document[i].HitTest(point) == 0)
                        {
                            so = drawArea.Document[i];
                            break;
                        }
                    }

                    if (so != null)
                    {
                        UndoService.BeginTransaction("Move the shape");
                        selectMode = SelectionMode.Move;
                        // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                        if ((Control.ModifierKeys & Keys.Control) == 0 && !so.IsSelected)
                        {
                            drawArea.Document.CancelSelect(true);
                        }

                        // Select clicked object
                        int paintcount = drawArea.Document.ShapeDraw.SelectedShapes.Length;
                        int textcount  = (from shape in drawArea.Document
                                          where
                                          shape.IsSelected &&
                                          (shape.Type == ShapeType.Text ||
                                           shape.Type == ShapeType.Time ||
                                           shape.Type == ShapeType.Temperature ||
                                           shape.Type == ShapeType.DynamicText)
                                          select shape).Count();

                        LayerControl lc = null;
                        if (so is ShapePaint && paintcount > 0)
                        {
                            so.BeginEdit();

                            //foreach (ShapeBase sb in drawArea.Document.ShapeDraw.SelectedShapes)
                            //    sb.IsSelected = false;

                            so.IsSelected = true;
                            so.EndEdit();
                            lc = drawArea.MessageControl.GetLayerControl(so);
                            if (lc != null)
                            {
                                lc.IsSelected = so.IsSelected;
                            }
                        }
                        else if ((so.Type == ShapeType.Text ||
                                  so.Type == ShapeType.Time ||
                                  so.Type == ShapeType.Temperature ||
                                  so.Type == ShapeType.DynamicText) && textcount > 0)
                        {
                            so.BeginEdit();
                            so.IsSelected = true;
                            so.EndEdit();
                            lc = drawArea.MessageControl.GetLayerControl(so);
                            if (lc != null)
                            {
                                lc.IsSelected = so.IsSelected;
                            }
                        }
                        else
                        {
                            so.IsSelected = true;
                        }

                        drawArea.Cursor = Cursors.SizeAll;
                    }
                }

                // Net selection
                if (selectMode == SelectionMode.None)
                {
                    //click on background
                    if ((Control.ModifierKeys & Keys.Control) == 0)
                    {
                        drawArea.Document.CancelSelect(true);
                    }

                    selectMode = SelectionMode.NetSelection;
                    UndoService.BeginTransaction("Select some shapes");
                    drawArea.DrawNetRectangle = true;
                }



                lastPoint  = point;
                startPoint = point;
            }
            else if (e.Button == MouseButtons.Right)
            {
                //drawArea.Document.CancelSelect(true);
                //for (int i = drawArea.Document.Count -1; i >= 0; i--)
                //{
                //    if (drawArea.Document[i].HitTest(point) >= 0)
                //    {
                //        drawArea.Document[i].IsSelected = true;
                //        break;
                //    }
                //}
                bool emptyInsect = false;
                foreach (ShapeBase s in drawArea.Document)
                {
                    if (s.HitTest(point) >= 0)
                    {
                        emptyInsect = true;
                        break;
                    }
                }
                if (!emptyInsect)
                {
                    drawArea.Document.CancelSelect(true);
                }
            }

            drawArea.Capture      = true;
            drawArea.NetRectangle = ShapeControlPaintNew.GetNormalizedRectangle(startPoint, lastPoint);
            drawArea.Refresh();
        }