Browse Source

add get_sort()

David Rose 22 years ago
parent
commit
89659d9e78
2 changed files with 24 additions and 0 deletions
  1. 23 0
      panda/src/pgraph/nodePath.cxx
  2. 1 0
      panda/src/pgraph/nodePath.h

+ 23 - 0
panda/src/pgraph/nodePath.cxx

@@ -168,6 +168,29 @@ get_stashed_children() const {
   return result;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::get_sort
+//       Access: Published
+//  Description: Returns the sort value of the referenced node within
+//               its parent; that is, the sort number passed on the
+//               last reparenting operation for this node.  This will
+//               control the position of the node within its parent's
+//               list of children.
+////////////////////////////////////////////////////////////////////
+int NodePath::
+get_sort() const {
+  if (!has_parent()) {
+    return 0;
+  }
+  PandaNode *parent = _head->get_next()->get_node();
+  PandaNode *child = node();
+  nassertr(parent != (PandaNode *)NULL && child != (PandaNode *)NULL, 0);
+  int child_index = parent->find_child(child);
+  nassertr(child_index != -1, 0);
+
+  return parent->get_child_sort(child_index);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::find
 //       Access: Published

+ 1 - 0
panda/src/pgraph/nodePath.h

@@ -186,6 +186,7 @@ PUBLISHED:
 
   INLINE bool has_parent() const;
   INLINE NodePath get_parent() const;
+  int get_sort() const;
 
   NodePath find(const string &path) const;
   NodePath find_path_to(PandaNode *node) const;