Example #1
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);
     }
 }
Example #2
0
		public override void Initialize() {
			Canvas.RemoveInputEventListener(Canvas.PanEventHandler);

			// Create a decorator group that is NOT volatile		
			DecoratorGroup dg = new DecoratorGroup();
			dg.Brush = Brushes.Magenta;
		
			// Put some nodes under the group for it to decorate
			PPath p1 = PPath.CreateEllipse(25,25,75,75);
			p1.Brush = Brushes.Red;
			PPath p2 = PPath.CreateRectangle(125,75,50,50); 
			p2.Brush = Brushes.Blue;

			// Add everything to the Piccolo hierarchy
			dg.AddChild(p1);
			dg.AddChild(p2);
			Canvas.Layer.AddChild(dg);				

			// Create a decorator group that IS volatile
			VolatileDecoratorGroup vdg = new VolatileDecoratorGroup(Canvas.Camera);
			vdg.Brush = Brushes.Cyan;
		
			// Put some nodes under the group for it to decorate
			PPath p3 = PPath.CreateEllipse(275,175,50,50);
			p3.Brush = Brushes.Blue;
			PPath p4 = PPath.CreateRectangle(175,175,75,75); 
			p4.Brush = Brushes.Green;
		
			// Add everything to the Piccolo hierarchy
			vdg.AddChild(p3);
			vdg.AddChild(p4);
			Canvas.Layer.AddChild(vdg);						

			// Create a selection handler so we can see that the decorator actually works
			PNodeList selectableParents = new PNodeList();
			selectableParents.Add(dg);
			selectableParents.Add(vdg);

			PSelectionEventHandler ps = new PSelectionEventHandler(Canvas.Layer,selectableParents);
			Canvas.AddInputEventListener(ps);
		}
Example #3
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 #4
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();

				FirePropertyChangedEvent(PROPERTY_KEY_CHILDREN, PROPERTY_CODE_CHILDREN, null, children);
			}
		}
Example #5
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 #6
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>
		/// <returns>The removed child.</returns>
		public virtual PNode RemoveChild(int index) {
			PNode child = children[index];
			children.RemoveAt(index);

			if (children.Count == 0) {
				children = null;
			}
			
			child.Repaint();
			child.Parent = null;
			InvalidateFullBounds();

			FirePropertyChangedEvent(PROPERTY_KEY_CHILDREN, PROPERTY_CODE_CHILDREN, null, children);

			return child;
		}
Example #7
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);
 }
		/// <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>
		/// 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);
		}
Example #10
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);
			}
		}
Example #11
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);
		}
		/// <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 #14
0
		protected PNode currentPosition;				// Visual indicator of current position
		#endregion

		#region Initialization
		/// <summary>
		/// Constructs a new slideviewer control.
		/// </summary>
		public SlideViewer() {
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			slides = new PNodeList();
			slideBar = new PNode();
			slideBar.Brush = Brushes.DarkGray;
			slideBar.Bounds = new RectangleF(0, 0, Width, SLIDE_BAR_HEIGHT);

			// Add the navigation event handlers and set the keyboard focus.
			Camera.MouseDown += new PInputEventHandler(Camera_MouseDown);
			Camera.KeyDown += new PInputEventHandler(Camera_KeyDown);
			Camera.MouseMove += new PInputEventHandler(Camera_MouseMove);
			Root.DefaultInputManager.KeyboardFocus = Camera.ToPickPath();

			// Remove the default zoom and pan event handlers.
			ZoomEventHandler = null;
			PanEventHandler = null;

			this.HandleCreated += new EventHandler(SlideViewer_HandleCreated);
		}
		/// <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>
		/// 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, 1);
				pens[i].DashPattern = dash;
				pens[i].DashOffset = i;
			}
		
			selection = new Hashtable();
			allItems = new Hashtable();
			unselectList = new PNodeList();
			marqueeMap = new Hashtable();
		}
Example #17
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);
		}
		/// <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);
				}
			}
		}
Example #19
0
		/// <summary>
		/// Checks this node and it's descendents for intersection with the given bounds
		/// and adds any intersecting nodes to the given list.
		/// </summary>
		/// <param name="fullBounds">
		/// The bounds to check for intersection, in parent coordinates.
		/// </param>
		/// <param name="results">
		/// The resulting list of nodes.
		/// </param>
		public void FindIntersectingNodes(RectangleF fullBounds, PNodeList results) {
			if (FullIntersects(fullBounds)) {
				RectangleF bounds = ParentToLocal(fullBounds);

				if (Intersects(bounds)) {
					results.Add(this);
				}

				int count = ChildrenCount;
				for (int i = count - 1; i >= 0; i--) {
					PNode each = children[i];
					each.FindIntersectingNodes(bounds, results);
				}
			}
		}
Example #20
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 #21
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) {

				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);
							}
							PaintDebugBounds(paintContext, boundsPen, nodeBounds);
						}
					}
		
					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);
							}
							PaintDebugFullBounds(paintContext, fullBoundsBrush, nodeBounds);
						}
					}
				}
			}
		}