瀏覽代碼

fix base.mouseWatcherNode.showRegions()

David Rose 19 年之前
父節點
當前提交
0c267327e4

+ 48 - 1
panda/src/tform/mouseWatcher.cxx

@@ -222,6 +222,14 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) {
   }
   }
 
 
   MutexHolder holder(_lock);
   MutexHolder holder(_lock);
+
+#ifndef NDEBUG
+  if (!_show_regions_render2d.is_empty()) {
+    old_group->hide_regions();
+    new_group->show_regions(_show_regions_render2d);
+  }
+#endif  // NDEBUG
+
   MutexHolder holder2(old_group->_lock);
   MutexHolder holder2(old_group->_lock);
   MutexHolder holder3(new_group->_lock);
   MutexHolder holder3(new_group->_lock);
 
 
@@ -272,7 +280,6 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) {
 
 
   // Did not find the group to erase
   // Did not find the group to erase
   return false;
   return false;
-
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -565,6 +572,46 @@ clear_current_regions() {
   }
   }
 }
 }
 
 
+#ifndef NDEBUG
+////////////////////////////////////////////////////////////////////
+//     Function: MouseWatcher::do_show_regions
+//       Access: Protected, Virtual
+//  Description: The protected implementation of show_regions().  This
+//               assumes the lock is already held.
+////////////////////////////////////////////////////////////////////
+void MouseWatcher::
+do_show_regions(const NodePath &render2d) {
+  MouseWatcherGroup::do_show_regions(render2d);
+  _show_regions_render2d = render2d;
+
+  Groups::const_iterator gi;
+  for (gi = _groups.begin(); gi != _groups.end(); ++gi) {
+    MouseWatcherGroup *group = (*gi);
+    group->show_regions(render2d);
+  }
+}
+#endif  // NDEBUG
+
+#ifndef NDEBUG
+////////////////////////////////////////////////////////////////////
+//     Function: MouseWatcher::do_hide_regions
+//       Access: Protected, Virtual
+//  Description: The protected implementation of hide_regions().  This
+//               assumes the lock is already held.
+////////////////////////////////////////////////////////////////////
+void MouseWatcher::
+do_hide_regions() {
+  MouseWatcherGroup::do_hide_regions();
+  _show_regions_render2d = NodePath();
+
+  Groups::const_iterator gi;
+  for (gi = _groups.begin(); gi != _groups.end(); ++gi) {
+    MouseWatcherGroup *group = (*gi);
+    group->hide_regions();
+  }
+}
+#endif  // NDEBUG
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseWatcher::intersect_regions
 //     Function: MouseWatcher::intersect_regions
 //       Access: Protected, Static
 //       Access: Protected, Static

+ 10 - 1
panda/src/tform/mouseWatcher.h

@@ -126,6 +126,11 @@ protected:
   void set_current_regions(Regions &regions);
   void set_current_regions(Regions &regions);
   void clear_current_regions();
   void clear_current_regions();
 
 
+#ifndef NDEBUG
+  virtual void do_show_regions(const NodePath &render2d);
+  virtual void do_hide_regions();
+#endif  // NDEBUG
+
   static void intersect_regions(Regions &only_a,
   static void intersect_regions(Regions &only_a,
                                 Regions &only_b,
                                 Regions &only_b,
                                 Regions &both,
                                 Regions &both,
@@ -161,7 +166,7 @@ protected:
 private:
 private:
   void consider_keyboard_suppress(const MouseWatcherRegion *region);
   void consider_keyboard_suppress(const MouseWatcherRegion *region);
 
 
-protected:
+private:
   // This wants to be a set, but because you cannot export sets across
   // This wants to be a set, but because you cannot export sets across
   // dlls in windows, we will make it a vector instead
   // dlls in windows, we will make it a vector instead
   typedef pvector< PT(MouseWatcherGroup) > Groups;
   typedef pvector< PT(MouseWatcherGroup) > Groups;
@@ -194,6 +199,10 @@ protected:
   ModifierButtons _mods;
   ModifierButtons _mods;
   DisplayRegion *_display_region;
   DisplayRegion *_display_region;
 
 
+#ifndef NDEBUG
+  NodePath _show_regions_render2d;
+#endif
+
 protected:
 protected:
   // Inherited from DataNode
   // Inherited from DataNode
   virtual void do_transmit_data(DataGraphTraverser *trav,
   virtual void do_transmit_data(DataGraphTraverser *trav,

+ 35 - 10
panda/src/tform/mouseWatcherGroup.cxx

@@ -222,11 +222,7 @@ write(ostream &out, int indent_level) const {
 void MouseWatcherGroup::
 void MouseWatcherGroup::
 show_regions(const NodePath &render2d) {
 show_regions(const NodePath &render2d) {
   MutexHolder holder(_lock);
   MutexHolder holder(_lock);
-
-  _show_regions = true;
-  _show_regions_root = render2d.attach_new_node("show_regions");
-  _show_regions_root.set_bin("unsorted", 0);
-  update_regions();
+  do_show_regions(render2d);
 }
 }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
@@ -250,17 +246,14 @@ set_color(const Colorf &color) {
 #ifndef NDEBUG
 #ifndef NDEBUG
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseWatcherGroup::hide_regions
 //     Function: MouseWatcherGroup::hide_regions
-//       Access: Published
+//       Access: Published, Virtual
 //  Description: Stops the visualization created by a previous call to
 //  Description: Stops the visualization created by a previous call to
 //               show_regions().
 //               show_regions().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void MouseWatcherGroup::
 void MouseWatcherGroup::
 hide_regions() {
 hide_regions() {
   MutexHolder holder(_lock);
   MutexHolder holder(_lock);
-
-  _show_regions_root.remove_node();
-  _show_regions = false;
-  _vizzes.clear();
+  do_hide_regions();
 }
 }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
@@ -298,6 +291,38 @@ do_remove_region(MouseWatcherRegion *region) {
   return false;
   return false;
 }
 }
 
 
+#ifndef NDEBUG
+////////////////////////////////////////////////////////////////////
+//     Function: MouseWatcherGroup::do_show_regions
+//       Access: Protected, Virtual
+//  Description: The protected implementation of show_regions().  This
+//               assumes the lock is already held.
+////////////////////////////////////////////////////////////////////
+void MouseWatcherGroup::
+do_show_regions(const NodePath &render2d) {
+  _show_regions = true;
+  _show_regions_root = render2d.attach_new_node("show_regions");
+  _show_regions_root.set_bin("unsorted", 0);
+  update_regions();
+}
+#endif  // NDEBUG
+
+#ifndef NDEBUG
+////////////////////////////////////////////////////////////////////
+//     Function: MouseWatcherGroup::do_hide_regions
+//       Access: Protected, Virtual
+//  Description: The protected implementation of hide_regions().  This
+//               assumes the lock is already held.
+////////////////////////////////////////////////////////////////////
+void MouseWatcherGroup::
+do_hide_regions() {
+  _show_regions_root.remove_node();
+  _show_regions = false;
+  _vizzes.clear();
+}
+#endif  // NDEBUG
+
+
 #ifndef NDEBUG
 #ifndef NDEBUG
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseWatcherGroup::update_regions
 //     Function: MouseWatcherGroup::update_regions

+ 5 - 0
panda/src/tform/mouseWatcherGroup.h

@@ -60,6 +60,11 @@ PUBLISHED:
 protected:
 protected:
   bool do_remove_region(MouseWatcherRegion *region);
   bool do_remove_region(MouseWatcherRegion *region);
 
 
+#ifndef NDEBUG
+  virtual void do_show_regions(const NodePath &render2d);
+  virtual void do_hide_regions();
+#endif  // NDEBUG
+
 protected:
 protected:
   typedef pvector< PT(MouseWatcherRegion) > Regions;
   typedef pvector< PT(MouseWatcherRegion) > Regions;
   Regions _regions;
   Regions _regions;