/// <summary>
 /// Initializes a new instance of the PNodeList class that contains nodes copied
 /// from the specified list and that has the same initial capacity as the number
 /// of nodes copied.
 /// </summary>
 /// <param name="list">The list whose nodes are copied to the new list.</param>
 public PNodeList(PNodeList list)
 {
     foreach (PNode node in list)
     {
         List.Add(node);
     }
 }
Example #2
0
        /// <summary>
        /// Remove the child at the specified position from this node's children.
        /// </summary>
        /// <param name="index">The index of the child to remove.</param>
        /// <remarks >
        /// Any subsequent children are shifted to the left (one is subtracted 
        /// from their indices). The removed child’s parent is set to null.
        /// </remarks>
        public virtual void RemoveChild(int index)
        {
            PNode child = children[index];
            children.RemoveAt(index);

            if (children.Count == 0) {
                children = null;
            }

            child.Repaint();
            child.Parent = null;
            InvalidateFullBounds();
        }
Example #3
0
        /// <summary>
        /// Remove all the children from this node.
        /// </summary>
        /// <remarks>
        /// Note this method is more efficient then removing each child individually.
        /// </remarks>
        public virtual void RemoveAllChildren()
        {
            if (children != null) {
                int count = ChildrenCount;
                for (int i = 0; i < count; i++) {
                    children[i].Parent = null;
                }

                children = null;
                InvalidatePaint();
                InvalidateFullBounds();
            }
        }
Example #4
0
        /// <summary>
        /// Gets a list containing the subset of this node and all of its descendent nodes
        /// that are accepted by the given node filter. 
        /// </summary>
        /// <param name="filter">The filter used to determine the subset.</param>
        /// <param name="results">The list used to collect the subset; can be null.</param>
        /// <returns>
        /// A list containing the subset of this node and all its descendents accepted by
        /// the filter.
        /// </returns>
        /// <remarks>
        /// If the filter is null then all nodes will be accepted. If the results parameter is not
        /// null then it will be used to store this subset instead of creating a new list.
        /// </remarks>
        public virtual PNodeList GetAllNodes(PNodeFilter filter, PNodeList results)
        {
            if (results == null) {
                results = new PNodeList();
            }
            if (filter == null || filter.Accept(this)) {
                results.Add(this);
            }

            if (filter == null || filter.AcceptChildrenOf(this)) {
                int count = ChildrenCount;
                for (int i = 0; i < count; i++) {
                    children[i].GetAllNodes(filter, results);
                }
            }

            return results;
        }
Example #5
0
 /// <summary>
 /// Add a list of nodes to be children of this node.
 /// </summary>
 /// <param name="nodes">A list of nodes to be added to this node.</param>
 /// <remarks>
 /// If these nodes already have parents they will first be removed from
 /// those parents.
 /// </remarks>
 public virtual void AddChildren(PNodeList nodes)
 {
     AddChildren((ICollection)nodes);
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the PNodeList class that contains nodes copied
 /// from the specified list and that has the same initial capacity as the number
 /// of nodes copied.
 /// </summary>
 /// <param name="list">The list whose nodes are copied to the new list.</param>
 public PNodeList(PNodeList list)
 {
     foreach(PNode node in list) {
         List.Add(node);
     }
 }
 /// <summary>
 /// Adds the nodes of the given list to the end of this list.
 /// </summary>
 /// <param name="list">
 /// The list whose nodes should be added to the end of this list.
 /// </param>
 public void AddRange(PNodeList list)
 {
     InnerList.AddRange(list);
 }
        /// <summary>
        /// Called by the constructors to perform some common initialization tasks.
        /// </summary>
        protected virtual void Init()
        {
            float[] dash = { DASH_WIDTH, DASH_WIDTH };
            pens = new Pen[NUM_PENS];
            for (int i = 0; i < NUM_PENS; i++) {
                pens[i] = new Pen(Color.Black);
                //pens[i] = new Pen(Color.Black, 1);
                //pens[i].DashPattern = dash;
                //pens[i].DashOffset = i;
            }

            selection = new Hashtable();
            allItems = new Hashtable();
            unselectList = new PNodeList();
            marqueeMap = new Hashtable();
        }
        /// <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);
            }

            marquee.Reset();
            SetSafeMarqueePen(r.Width, r.Height);
            marquee.SetPathToRectangle(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);
                }
            }
        }
 /// <summary>
 /// Constructs a new PSelectionEventHandler that will handle selection for the
 /// children of the given list of selectable parent nodes.
 /// </summary>
 /// <param name="marqueeParent">
 /// The node to which the event handler dynamically adds a marquee (temporarily)
 /// to represent the area being selected.
 /// </param>
 /// <param name="selectableParents">
 /// A list of nodes whose children will be selected by this event handler.
 /// </param>
 public PSelectionEventHandler(PNode marqueeParent, PNodeList selectableParents)
 {
     this.marqueeParent = marqueeParent;
     this.selectableParents = selectableParents;
     Init();
 }
 /// <summary>
 /// Unselects each node in the list, if the node is currently selected.
 /// </summary>
 /// <param name="items">The list of items to unselect.</param>
 /// <remarks>
 /// This method will remove the handles from the selected nodes in the
 /// list and post a SELECTION_CHANGED_NOTIFICATION if the selection has
 /// changed.
 /// </remarks>
 public virtual void Unselect(PNodeList items)
 {
     Unselect((ICollection)items);
 }
        private PNodeList unselectList = null; // Used within drag handler temporarily

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs a new PSelectionEventHandler that will handle selection for the
        /// children of the given selectable parent node.
        /// </summary>
        /// <param name="marqueeParent">
        /// The node to which the event handler dynamically adds a marquee (temporarily)
        /// to represent the area being selected.
        /// </param>
        /// <param name="selectableParent">
        /// The node whose children will be selected by this event handler.
        /// </param>
        public PSelectionEventHandler(PNode marqueeParent, PNode selectableParent)
        {
            this.marqueeParent = marqueeParent;
            selectableParents = new PNodeList();
            selectableParents.Add(selectableParent);
            Init();
        }
 /// <summary>
 /// Sorts the given list of nodes by their distance from the given point.  Nodes
 /// closest to the point will be placed first in the list.
 /// </summary>
 /// <param name="aNodesList">The list to sort.</param>
 /// <param name="aPoint">The point to use for the comparison.</param>
 public virtual void SortNodesByDistanceFromPoint(PNodeList aNodesList, PointF aPoint)
 {
     aNodesList.Sort(new DistanceFromPointComparer(aPoint));
 }
        /// <summary>
        /// Get a list of all neighbors (parent, siblings and children).
        /// </summary>
        /// <returns>A list of all neighbors.</returns>
        public virtual PNodeList GetNeighbors()
        {
            PNodeList result = new PNodeList();

            if (focusNode == null) return result;
            if (focusNode.Parent == null) return result;

            PNode focusParent = focusNode.Parent;

            PNodeList focusParentChildren = focusParent.ChildrenReference;
            foreach (PNode each in focusParentChildren) {
                if (each != focusNode && each.Pickable) {
                    result.Add(each);
                }
            }

            result.Add(focusParent);

            PNodeList focusChildren = focusNode.ChildrenReference;
            foreach(PNode each in focusChildren) {
                result.Add(each);
            }

            return result;
        }
Example #15
0
 /// <summary>
 /// Remove all the children in the given list from this node’s list
 /// of children.
 /// </summary>
 /// <param name="childrenNodes">The list of children to remove.</param>
 /// <remarks>All removed nodes will have their parent set to null.</remarks>
 public virtual void RemoveChildren(PNodeList childrenNodes)
 {
     RemoveChildren((ICollection)childrenNodes);
 }
Example #16
0
 /// <summary>
 /// Removes bounds handles from the given node.
 /// </summary>
 /// <param name="aNode">The node to remove the bounds handles from.</param>
 public static void RemoveBoundsHandlesFrom(PNode aNode)
 {
     PNodeList handles = new PNodeList();
     PNodeList children = aNode.ChildrenReference;
     foreach (PNode each in children) {
         if (each is PBoundsHandle) {
             handles.Add(each);
         }
     }
     aNode.RemoveChildren(handles);
 }
Example #17
0
        /// <summary>
        /// This method paints the bounds and full bounds of nodes when the appropriate debug
        /// flags are set.
        /// </summary>
        /// <param name="paintContext">
        /// The paint context to use for painting debug information.
        /// </param>
        /// <remarks>
        /// Setting debugBounds and/or debugFullBounds flags is useful for visual debugging.
        /// </remarks>
        protected virtual void PaintDebugInfo(PPaintContext paintContext)
        {
            if (PDebug.DebugBounds || PDebug.DebugFullBounds) {
                Graphics2D g = paintContext.Graphics;

                PNodeList nodes = new PNodeList();
                RectangleF nodeBounds = RectangleF.Empty;

                for (int i = 0; i < LayerCount; i++) {
                    GetLayer(i).GetAllNodes(null, nodes);
                }

                GetAllNodes(null, nodes);

                foreach (PNode each in nodes) {

                    if (PDebug.DebugBounds) {
                        nodeBounds = each.Bounds;

                        if (!nodeBounds.IsEmpty) {
                            nodeBounds = each.LocalToGlobal(nodeBounds);
                            nodeBounds = GlobalToLocal(nodeBounds);
                            if (each == this || each.IsDescendentOf(this)) {
                                nodeBounds = LocalToView(nodeBounds);
                            }
                            g.DrawRectangle(boundsPen, nodeBounds.X, nodeBounds.Y, nodeBounds.Width, nodeBounds.Height);
                        }
                    }

                    if (PDebug.DebugFullBounds) {
                        nodeBounds = each.FullBounds;

                        if (!nodeBounds.IsEmpty) {
                            if (each.Parent != null) {
                                nodeBounds = each.Parent.LocalToGlobal(nodeBounds);
                            }
                            nodeBounds = GlobalToLocal(nodeBounds);
                            if (each == this || each.IsDescendentOf(this)) {
                                nodeBounds = LocalToView(nodeBounds);
                            }
                            //g.FillRectangle(fullBoundsBrush, nodeBounds);
                            g.DrawRectangle(fullBoundsPen, nodeBounds);
                        }
                    }
                }
            }
        }
Example #18
0
 /// <summary>
 /// Adds the nodes of the given list to the end of this list.
 /// </summary>
 /// <param name="list">
 /// The list whose nodes should be added to the end of this list.
 /// </param>
 public void AddRange(PNodeList list)
 {
     InnerList.AddRange(list);
 }