fix MouseWatcherRegion update and show_regions

This commit is contained in:
David Rose
2006-04-29 02:00:15 +00:00
parent fe0177f28c
commit 1ee0741221
5 changed files with 78 additions and 21 deletions
+18
View File
@@ -137,6 +137,24 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: PGTop::is_renderable
// Access: Public, Virtual
// Description: Returns true if there is some value to visiting this
// particular node during the cull traversal for any
// camera, false otherwise. This will be used to
// optimize the result of get_net_draw_show_mask(), so
// that any subtrees that contain only nodes for which
// is_renderable() is false need not be visited.
////////////////////////////////////////////////////////////////////
bool PGTop::
is_renderable() const {
// We flag the PGTop as renderable, even though it technically
// doesn't have anything to render, but we do need the traverser to
// visit it every frame.
return true;
}
////////////////////////////////////////////////////////////////////
// Function: PGTop::set_mouse_watcher
// Access: Published
+1
View File
@@ -56,6 +56,7 @@ public:
virtual PandaNode *make_copy() const;
virtual bool has_cull_callback() const;
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
virtual bool is_renderable() const;
PUBLISHED:
void set_mouse_watcher(MouseWatcher *watcher);
+25 -7
View File
@@ -158,6 +158,12 @@ add_group(MouseWatcherGroup *group) {
return false;
}
#ifndef NDEBUG
if (!_show_regions_render2d.is_empty()) {
group->show_regions(_show_regions_render2d);
}
#endif // NDEBUG
// Not in the set, add it and return true
_groups.push_back(pt);
return true;
@@ -188,6 +194,12 @@ remove_group(MouseWatcherGroup *group) {
_preferred_button_down_region = (MouseWatcherRegion *)NULL;
}
#ifndef NDEBUG
if (!_show_regions_render2d.is_empty()) {
group->do_hide_regions();
}
#endif // NDEBUG
// See if the group is in the set/vector
PT(MouseWatcherGroup) pt = group;
Groups::iterator gi =
@@ -223,16 +235,16 @@ 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);
#ifndef NDEBUG
if (!_show_regions_render2d.is_empty()) {
old_group->do_hide_regions();
new_group->do_show_regions(_show_regions_render2d);
}
#endif // NDEBUG
// Figure out the list of regions that change
Regions remove, add, keep;
intersect_regions(remove, add, keep,
@@ -268,6 +280,12 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) {
if (gi == _groups.end()) {
_groups.push_back(new_group);
}
#ifndef NDEBUG
if (!_show_regions_render2d.is_empty()) {
new_group->do_update_regions();
}
#endif // NDEBUG
// Remove the old group, if it is already there.
pt = old_group;
+31 -13
View File
@@ -239,14 +239,14 @@ set_color(const Colorf &color) {
MutexHolder holder(_lock);
_color = color;
update_regions();
do_update_regions();
}
#endif // NDEBUG
#ifndef NDEBUG
////////////////////////////////////////////////////////////////////
// Function: MouseWatcherGroup::hide_regions
// Access: Published, Virtual
// Access: Published
// Description: Stops the visualization created by a previous call to
// show_regions().
////////////////////////////////////////////////////////////////////
@@ -257,6 +257,20 @@ hide_regions() {
}
#endif // NDEBUG
#ifndef NDEBUG
////////////////////////////////////////////////////////////////////
// Function: MouseWatcherGroup::update_regions
// Access: Published
// Description: Refreshes the visualization created by
// show_regions().
////////////////////////////////////////////////////////////////////
void MouseWatcherGroup::
update_regions() {
MutexHolder holder(_lock);
do_update_regions();
}
#endif // NDEBUG
////////////////////////////////////////////////////////////////////
// Function: MouseWatcherGroup::do_remove_region
@@ -300,10 +314,11 @@ do_remove_region(MouseWatcherRegion *region) {
////////////////////////////////////////////////////////////////////
void MouseWatcherGroup::
do_show_regions(const NodePath &render2d) {
do_hide_regions();
_show_regions = true;
_show_regions_root = render2d.attach_new_node("show_regions");
_show_regions_root.set_bin("unsorted", 0);
update_regions();
do_update_regions();
}
#endif // NDEBUG
@@ -325,26 +340,29 @@ do_hide_regions() {
#ifndef NDEBUG
////////////////////////////////////////////////////////////////////
// Function: MouseWatcherGroup::update_regions
// Access: Private
// Function: MouseWatcherGroup::do_update_regions
// Access: Protected
// Description: Internally regenerates the show_regions()
// visualization. Assumes the lock is already held.
////////////////////////////////////////////////////////////////////
void MouseWatcherGroup::
update_regions() {
do_update_regions() {
nassertv(_lock.debug_is_locked());
_show_regions_root.node()->remove_all_children();
_vizzes.clear();
_vizzes.reserve(_regions.size());
Regions::const_iterator ri;
for (ri = _regions.begin(); ri != _regions.end(); ++ri) {
_vizzes.push_back(make_viz_region(*ri));
if (_show_regions) {
_show_regions_root.node()->remove_all_children();
_vizzes.clear();
_vizzes.reserve(_regions.size());
Regions::const_iterator ri;
for (ri = _regions.begin(); ri != _regions.end(); ++ri) {
_vizzes.push_back(make_viz_region(*ri));
}
}
}
#endif // NDEBUG
#ifndef NDEBUG
////////////////////////////////////////////////////////////////////
// Function: MouseWatcherGroup::make_viz_region
+3 -1
View File
@@ -55,6 +55,8 @@ PUBLISHED:
void show_regions(const NodePath &render2d);
void set_color(const Colorf &color);
void hide_regions();
void update_regions();
#endif // NDEBUG
protected:
@@ -63,6 +65,7 @@ protected:
#ifndef NDEBUG
virtual void do_show_regions(const NodePath &render2d);
virtual void do_hide_regions();
void do_update_regions();
#endif // NDEBUG
protected:
@@ -76,7 +79,6 @@ protected:
private:
#ifndef NDEBUG
void update_regions();
PandaNode *make_viz_region(MouseWatcherRegion *region);
typedef pvector< PT(PandaNode) > Vizzes;