예제 #1
0
        public override void Initialize()
        {
            PRoot   root   = Canvas.Root;
            PCamera camera = Canvas.Camera;

            //PLayer gridLayer = new GridLayer();

            // replace standard layer with grid layer.
            root.RemoveChild(camera.GetLayer(0));
            camera.RemoveLayer(0);
            root.AddChild(gridLayer);
            camera.AddLayer(gridLayer);

            // add constraints so that grid layers bounds always match cameras view bounds. This makes
            // it look like an infinite grid.
            camera.BoundsChanged        += new PPropertyEventHandler(camera_BoundsChanged);
            camera.ViewTransformChanged += new PPropertyEventHandler(camera_ViewTransformChanged);

            gridLayer.Bounds = camera.ViewBounds;

            PNode n = new PNode();

            n.Brush = Color.Blue;
            n.SetBounds(0, 0, 100, 80);

            Canvas.Layer.AddChild(n);
            Canvas.RemoveInputEventListener(Canvas.PanEventHandler);

            Canvas.AddInputEventListener(new GridDragHandler(Canvas));
        }
        /// <summary>
        /// Determines if the specified node is selectable (i.e., if it is a child
        /// of a node in the list of selectable parents).
        /// </summary>
        /// <param name="node">The node to test.</param>
        /// <returns>True if the node is selectable; otherwise, false.</returns>
        protected virtual bool IsSelectable(PNode node)
        {
            bool selectable = false;

            foreach (PNode parent in selectableParents)
            {
                if (parent.ChildrenReference.Contains(node))
                {
                    selectable = true;
                    break;
                }
                else if (parent is PCamera)
                {
                    PCamera cameraParent = (PCamera)parent;
                    for (int i = 0; i < cameraParent.LayerCount; i++)
                    {
                        PLayer layer = cameraParent.GetLayer(i);
                        if (layer.ChildrenReference.Contains(node))
                        {
                            selectable = true;
                            break;
                        }
                    }
                }
            }

            return(selectable);
        }
        /// <summary>
        /// Update the marquee bounds based on the given event data.
        /// </summary>
        /// <param name="e">A PInputEventArgs that contains the event data.</param>
        protected virtual void UpdateMarquee(PInputEventArgs e)
        {
            RectangleF r = RectangleF.Empty;

            if (marqueeParent is PCamera)
            {
                r = PUtil.AddPointToRect(r, canvasPressPt);
                r = PUtil.AddPointToRect(r, e.CanvasPosition);
            }
            else
            {
                r = PUtil.AddPointToRect(r, presspt);
                r = PUtil.AddPointToRect(r, e.Position);
            }

            r = marquee.GlobalToLocal(r);
            marquee.Reset();
            SetSafeMarqueePen(r.Width, r.Height);
            marquee.AddRectangle(r.X, r.Y, r.Width, r.Height);

            r = RectangleF.Empty;
            r = PUtil.AddPointToRect(r, presspt);
            r = PUtil.AddPointToRect(r, e.Position);

            allItems.Clear();
            PNodeFilter filter = CreateNodeFilter(r);

            foreach (PNode parent in selectableParents)
            {
                PNodeList items;
                if (parent is PCamera)
                {
                    items = new PNodeList();
                    PCamera cameraParent = (PCamera)parent;
                    for (int i = 0; i < cameraParent.LayerCount; i++)
                    {
                        cameraParent.GetLayer(i).GetAllNodes(filter, items);
                    }
                }
                else
                {
                    items = parent.GetAllNodes(filter, null);
                }

                foreach (PNode node in items)
                {
                    allItems.Add(node, true);
                }
            }
        }