Browse Source

add support for multiple PGTop nodes

David Rose 21 years ago
parent
commit
8f491813d0
4 changed files with 49 additions and 2 deletions
  1. 4 1
      direct/src/showbase/ShowBase.py
  2. 39 1
      panda/src/pgui/pgTop.I
  3. 2 0
      panda/src/pgui/pgTop.cxx
  4. 4 0
      panda/src/pgui/pgTop.h

+ 4 - 1
direct/src/showbase/ShowBase.py

@@ -688,7 +688,10 @@ class ShowBase(DirectObject.DirectObject):
         # ratio.
         # ratio.
         
         
         aspectRatio = self.getAspectRatio()
         aspectRatio = self.getAspectRatio()
-        self.aspect2dp = self.render2dp.attachNewNode(PGTop("aspect2d"))
+        self.aspect2dp = self.render2dp.attachNewNode(PGTop("aspect2dp"))
+        # Temporary test for old panda.
+        if hasattr(PGTop, 'setStartSort'):
+            self.aspect2dp.node().setStartSort(16384)
         self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0)
         self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0)
 
 
         # It's important to know the bounds of the aspect2d screen.
         # It's important to know the bounds of the aspect2d screen.

+ 39 - 1
panda/src/pgui/pgTop.I

@@ -25,7 +25,8 @@
 INLINE PGTop::
 INLINE PGTop::
 PGTop(const PGTop &copy) :
 PGTop(const PGTop &copy) :
   PandaNode(copy),
   PandaNode(copy),
-  _watcher(copy._watcher)
+  _watcher(copy._watcher),
+  _start_sort(copy._start_sort)
 {
 {
 }
 }
 
 
@@ -41,6 +42,43 @@ get_mouse_watcher() const {
   return _watcher;
   return _watcher;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PGTop::set_start_sort
+//       Access: Published
+//  Description: Specifies the sort index that is assigned during the
+//               traversal to the first PGItem that is discovered
+//               during traversal.  Subsequent PGItems will be
+//               assigned consecutively higher sort indexes.
+//
+//               This number is used by the MouseWatcher system to
+//               rank the clickable mouse regions in the same order in
+//               which the items are rendered, so that items on top
+//               will receive mouse priority.
+//
+//               Normally, it makes the most sense to leave this
+//               initial value at its default value of 0, unless you
+//               need the PGItems to have a particular sort value with
+//               respect to some other objects in the scene
+//               (particularly with a second PGTop node).
+////////////////////////////////////////////////////////////////////
+INLINE void PGTop::
+set_start_sort(int start_sort) {
+  _start_sort = start_sort;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PGTop::get_start_sort
+//       Access: Published
+//  Description: Returns the sort index that is assigned during the
+//               traversal to the first PGItem that is discovered
+//               during traversal.  See set_start_sort().
+////////////////////////////////////////////////////////////////////
+INLINE int PGTop::
+get_start_sort() const {
+  return _start_sort;
+}
+
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PGTop::add_region
 //     Function: PGTop::add_region
 //       Access: Public
 //       Access: Public

+ 2 - 0
panda/src/pgui/pgTop.cxx

@@ -35,6 +35,7 @@ PGTop(const string &name) :
   PandaNode(name)
   PandaNode(name)
 {
 {
   _watcher_group = (PGMouseWatcherGroup *)NULL;
   _watcher_group = (PGMouseWatcherGroup *)NULL;
+  _start_sort = 0;
 
 
   // A PGTop node normally has an infinite bounding volume.  Screw
   // A PGTop node normally has an infinite bounding volume.  Screw
   // culling.
   // culling.
@@ -115,6 +116,7 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
   // PGTop node, for the convenience of PGItems to register themselves
   // PGTop node, for the convenience of PGItems to register themselves
   // as they are drawn.
   // as they are drawn.
   PGCullTraverser pg_trav(this, trav);
   PGCullTraverser pg_trav(this, trav);
+  pg_trav._sort_index = _start_sort;
   pg_trav.traverse_below(data);
   pg_trav.traverse_below(data);
 
 
   // We've taken care of the traversal, thank you.
   // We've taken care of the traversal, thank you.

+ 4 - 0
panda/src/pgui/pgTop.h

@@ -61,6 +61,9 @@ PUBLISHED:
   void set_mouse_watcher(MouseWatcher *watcher);
   void set_mouse_watcher(MouseWatcher *watcher);
   INLINE MouseWatcher *get_mouse_watcher() const;
   INLINE MouseWatcher *get_mouse_watcher() const;
 
 
+  INLINE void set_start_sort(int start_sort);
+  INLINE int get_start_sort() const;
+
 public:
 public:
   // These methods duplicate the functionality of MouseWatcherGroup.
   // These methods duplicate the functionality of MouseWatcherGroup.
   INLINE bool add_region(MouseWatcherRegion *region);
   INLINE bool add_region(MouseWatcherRegion *region);
@@ -69,6 +72,7 @@ public:
 private:
 private:
   PT(MouseWatcher) _watcher;
   PT(MouseWatcher) _watcher;
   PGMouseWatcherGroup *_watcher_group;
   PGMouseWatcherGroup *_watcher_group;
+  int _start_sort;
   
   
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {