public static int CompareToCommon(TimelineItem timelineItemA, TimelineItem timelineItemB, TimelineItemManager timelineItemManager) { int num1 = timelineItemManager.SortByZOrder ? 1 : -1; TimelineItem parent = timelineItemA.Parent; SceneNode sceneNode1 = timelineItemA.SceneNode; SceneNode sceneNode2 = timelineItemB.SceneNode; if (sceneNode1 == null || sceneNode2 == null) { return(0); } DocumentNode documentNode1 = sceneNode1.DocumentNode; DocumentNode documentNode2 = sceneNode2.DocumentNode; if (documentNode1.Parent == null) { return(documentNode2.Parent == null ? 0 : -1); } if (documentNode1.IsChild && documentNode2.IsChild) { int num2 = documentNode1.Parent.Children.IndexOf(documentNode1); int num3 = documentNode1.Parent.Children.IndexOf(documentNode2); return(num1 * (num3 - num2)); } SceneNode sceneNode3 = timelineItemA.Parent.SceneNode; if (sceneNode3 == null) { return(0); } ZOrderComparer <SceneNode> zorderComparer = new ZOrderComparer <SceneNode>(sceneNode3); return(-num1 *zorderComparer.Compare(sceneNode1, sceneNode2)); }
/// <summary> /// Modify the order of the objects in the given <see cref="T:Northwoods.Go.GoCollection" /> <paramref name="c" /> /// to be in their Z-order position in the layers of this collection. /// </summary> /// <param name="c">a <see cref="T:Northwoods.Go.GoCollection" /> that will be modified</param> /// <remarks>See the remarks for <see cref="M:Northwoods.Go.GoLayerCollection.SortByZOrder(Northwoods.Go.GoObject[])" />.</remarks> public void SortByZOrder(GoCollection c) { if (!c.IsEmpty) { ZOrderComparer comparer = GetComparer(); c.Sort(comparer); } }
/// <summary> /// Sort an <c>Array</c> of <see cref="T:Northwoods.Go.GoObject" />s by their Z-order position in these layers. /// </summary> /// <param name="a">an array of <see cref="T:Northwoods.Go.GoObject" />s in layers of this layer collection; this array is modified</param> /// <remarks> /// <para> /// This method does not modify the order of any objects in any layer--it simply /// modifies the argument array by sorting the objects by their current Z-order in these layers. /// For example, if you have a few selected objects, you can use this method to find the /// selected object which is in front of the other selected objects. That would be the last /// object in the array after calling this method. /// </para> /// <para> /// If one or more elements of the argument array <paramref name="a" /> are not /// <see cref="T:Northwoods.Go.GoObject" />s that belong to one of these layers, the resulting sort order is indeterminate. /// In many circumstances you can easily create an array of <c>GoObject</c>s by calling /// <see cref="M:Northwoods.Go.GoLayerCollection.CopyArray" />. /// </para> /// </remarks> /// <seealso cref="M:Northwoods.Go.GoLayerCollection.SortByZOrder(Northwoods.Go.GoCollection)" /> public void SortByZOrder(GoObject[] a) { if (a.Length > 1) { ZOrderComparer comparer = GetComparer(); Array.Sort(a, 0, a.Length, comparer); } }
private ZOrderComparer GetComparer() { if (myComparer == null) { myComparer = new ZOrderComparer(this); } using (GoLayerCollectionEnumerator goLayerCollectionEnumerator = GetEnumerator()) { while (goLayerCollectionEnumerator.MoveNext()) { goLayerCollectionEnumerator.Current.InitializeIndices(); } } return(myComparer); }