From 0c267327e4a0928d4a87e8589a986d4d398c8bed Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 28 Apr 2006 23:25:06 +0000 Subject: [PATCH] fix base.mouseWatcherNode.showRegions() --- panda/src/tform/mouseWatcher.cxx | 49 ++++++++++++++++++++++++++- panda/src/tform/mouseWatcher.h | 11 +++++- panda/src/tform/mouseWatcherGroup.cxx | 45 ++++++++++++++++++------ panda/src/tform/mouseWatcherGroup.h | 5 +++ 4 files changed, 98 insertions(+), 12 deletions(-) diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx index 1216cc18cb..25419ceff4 100644 --- a/panda/src/tform/mouseWatcher.cxx +++ b/panda/src/tform/mouseWatcher.cxx @@ -222,6 +222,14 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) { } 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 holder3(new_group->_lock); @@ -272,7 +280,6 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) { // Did not find the group to erase 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 // Access: Protected, Static diff --git a/panda/src/tform/mouseWatcher.h b/panda/src/tform/mouseWatcher.h index c8b0a481db..a1c39fd9f2 100644 --- a/panda/src/tform/mouseWatcher.h +++ b/panda/src/tform/mouseWatcher.h @@ -126,6 +126,11 @@ protected: void set_current_regions(Regions ®ions); 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, Regions &only_b, Regions &both, @@ -161,7 +166,7 @@ protected: private: void consider_keyboard_suppress(const MouseWatcherRegion *region); -protected: +private: // This wants to be a set, but because you cannot export sets across // dlls in windows, we will make it a vector instead typedef pvector< PT(MouseWatcherGroup) > Groups; @@ -194,6 +199,10 @@ protected: ModifierButtons _mods; DisplayRegion *_display_region; +#ifndef NDEBUG + NodePath _show_regions_render2d; +#endif + protected: // Inherited from DataNode virtual void do_transmit_data(DataGraphTraverser *trav, diff --git a/panda/src/tform/mouseWatcherGroup.cxx b/panda/src/tform/mouseWatcherGroup.cxx index e5f8ced1a0..3d671f0844 100644 --- a/panda/src/tform/mouseWatcherGroup.cxx +++ b/panda/src/tform/mouseWatcherGroup.cxx @@ -222,11 +222,7 @@ write(ostream &out, int indent_level) const { void MouseWatcherGroup:: show_regions(const NodePath &render2d) { 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 @@ -250,17 +246,14 @@ set_color(const Colorf &color) { #ifndef NDEBUG //////////////////////////////////////////////////////////////////// // Function: MouseWatcherGroup::hide_regions -// Access: Published +// Access: Published, Virtual // Description: Stops the visualization created by a previous call to // show_regions(). //////////////////////////////////////////////////////////////////// void MouseWatcherGroup:: hide_regions() { MutexHolder holder(_lock); - - _show_regions_root.remove_node(); - _show_regions = false; - _vizzes.clear(); + do_hide_regions(); } #endif // NDEBUG @@ -298,6 +291,38 @@ do_remove_region(MouseWatcherRegion *region) { 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 //////////////////////////////////////////////////////////////////// // Function: MouseWatcherGroup::update_regions diff --git a/panda/src/tform/mouseWatcherGroup.h b/panda/src/tform/mouseWatcherGroup.h index a95bf08fdf..28c9573227 100644 --- a/panda/src/tform/mouseWatcherGroup.h +++ b/panda/src/tform/mouseWatcherGroup.h @@ -60,6 +60,11 @@ PUBLISHED: protected: bool do_remove_region(MouseWatcherRegion *region); +#ifndef NDEBUG + virtual void do_show_regions(const NodePath &render2d); + virtual void do_hide_regions(); +#endif // NDEBUG + protected: typedef pvector< PT(MouseWatcherRegion) > Regions; Regions _regions;