From dc6b1cbe79d0278f5dc08bc7e4b7e116c562ebe0 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 14 Jul 2006 21:06:26 +0000 Subject: [PATCH] fix sticky rollover buttons --- panda/src/tform/mouseWatcher.cxx | 26 +++++++++++++++++++++----- panda/src/tform/mouseWatcher.h | 5 ++++- panda/src/tform/mouseWatcherGroup.cxx | 9 +++++---- panda/src/tform/mouseWatcherGroup.h | 6 ++++-- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx index b693c7910e..b9871eef14 100644 --- a/panda/src/tform/mouseWatcher.cxx +++ b/panda/src/tform/mouseWatcher.cxx @@ -102,6 +102,9 @@ remove_region(MouseWatcherRegion *region) { remove_region_from(_current_regions, region); if (region == _preferred_region) { + if (_preferred_region != (MouseWatcherRegion *)NULL) { + exit_region(_preferred_region, MouseWatcherParameter()); + } _preferred_region = (MouseWatcherRegion *)NULL; } if (region == _preferred_button_down_region) { @@ -160,7 +163,8 @@ add_group(MouseWatcherGroup *group) { #ifndef NDEBUG if (!_show_regions_render2d.is_empty()) { - group->show_regions(_show_regions_render2d); + group->show_regions(_show_regions_render2d, _show_regions_bin_name, + _show_regions_draw_order); } #endif // NDEBUG @@ -188,6 +192,9 @@ remove_group(MouseWatcherGroup *group) { _current_regions.swap(only_a); if (has_region_in(both, _preferred_region)) { + if (_preferred_region != (MouseWatcherRegion *)NULL) { + exit_region(_preferred_region, MouseWatcherParameter()); + } _preferred_region = (MouseWatcherRegion *)NULL; } if (has_region_in(both, _preferred_button_down_region)) { @@ -241,7 +248,8 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) { #ifndef NDEBUG if (!_show_regions_render2d.is_empty()) { old_group->do_hide_regions(); - new_group->do_show_regions(_show_regions_render2d); + new_group->do_show_regions(_show_regions_render2d, _show_regions_bin_name, + _show_regions_draw_order); } #endif // NDEBUG @@ -258,6 +266,9 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) { _current_regions.swap(only_a); if (has_region_in(both, _preferred_region)) { + if (_preferred_region != (MouseWatcherRegion *)NULL) { + exit_region(_preferred_region, MouseWatcherParameter()); + } _preferred_region = (MouseWatcherRegion *)NULL; } if (has_region_in(both, _preferred_button_down_region)) { @@ -598,14 +609,17 @@ clear_current_regions() { // assumes the lock is already held. //////////////////////////////////////////////////////////////////// void MouseWatcher:: -do_show_regions(const NodePath &render2d) { - MouseWatcherGroup::do_show_regions(render2d); +do_show_regions(const NodePath &render2d, const string &bin_name, + int draw_order) { + MouseWatcherGroup::do_show_regions(render2d, bin_name, draw_order); _show_regions_render2d = render2d; + _show_regions_bin_name = bin_name; + _show_regions_draw_order = draw_order; Groups::const_iterator gi; for (gi = _groups.begin(); gi != _groups.end(); ++gi) { MouseWatcherGroup *group = (*gi); - group->show_regions(render2d); + group->show_regions(render2d, bin_name, draw_order); } } #endif // NDEBUG @@ -621,6 +635,8 @@ void MouseWatcher:: do_hide_regions() { MouseWatcherGroup::do_hide_regions(); _show_regions_render2d = NodePath(); + _show_regions_bin_name = string(); + _show_regions_draw_order = 0; Groups::const_iterator gi; for (gi = _groups.begin(); gi != _groups.end(); ++gi) { diff --git a/panda/src/tform/mouseWatcher.h b/panda/src/tform/mouseWatcher.h index a1c39fd9f2..e6e44caf2e 100644 --- a/panda/src/tform/mouseWatcher.h +++ b/panda/src/tform/mouseWatcher.h @@ -127,7 +127,8 @@ protected: void clear_current_regions(); #ifndef NDEBUG - virtual void do_show_regions(const NodePath &render2d); + virtual void do_show_regions(const NodePath &render2d, + const string &bin_name, int draw_order); virtual void do_hide_regions(); #endif // NDEBUG @@ -201,6 +202,8 @@ private: #ifndef NDEBUG NodePath _show_regions_render2d; + string _show_regions_bin_name; + int _show_regions_draw_order; #endif protected: diff --git a/panda/src/tform/mouseWatcherGroup.cxx b/panda/src/tform/mouseWatcherGroup.cxx index 42c6b27871..e822b9efeb 100644 --- a/panda/src/tform/mouseWatcherGroup.cxx +++ b/panda/src/tform/mouseWatcherGroup.cxx @@ -220,9 +220,9 @@ write(ostream &out, int indent_level) const { // for the window. //////////////////////////////////////////////////////////////////// void MouseWatcherGroup:: -show_regions(const NodePath &render2d) { +show_regions(const NodePath &render2d, const string &bin_name, int draw_order) { MutexHolder holder(_lock); - do_show_regions(render2d); + do_show_regions(render2d, bin_name, draw_order); } #endif // NDEBUG @@ -313,11 +313,12 @@ do_remove_region(MouseWatcherRegion *region) { // assumes the lock is already held. //////////////////////////////////////////////////////////////////// void MouseWatcherGroup:: -do_show_regions(const NodePath &render2d) { +do_show_regions(const NodePath &render2d, const string &bin_name, + int draw_order) { do_hide_regions(); _show_regions = true; _show_regions_root = render2d.attach_new_node("show_regions"); - _show_regions_root.set_bin("unsorted", 0); + _show_regions_root.set_bin(bin_name, draw_order); do_update_regions(); } #endif // NDEBUG diff --git a/panda/src/tform/mouseWatcherGroup.h b/panda/src/tform/mouseWatcherGroup.h index f639d1f65d..ad6572c4c6 100644 --- a/panda/src/tform/mouseWatcherGroup.h +++ b/panda/src/tform/mouseWatcherGroup.h @@ -52,7 +52,8 @@ PUBLISHED: void write(ostream &out, int indent_level = 0) const; #ifndef NDEBUG - void show_regions(const NodePath &render2d); + void show_regions(const NodePath &render2d, + const string &bin_name, int draw_order); void set_color(const Colorf &color); void hide_regions(); @@ -63,7 +64,8 @@ protected: bool do_remove_region(MouseWatcherRegion *region); #ifndef NDEBUG - virtual void do_show_regions(const NodePath &render2d); + virtual void do_show_regions(const NodePath &render2d, + const string &bin_name, int draw_order); virtual void do_hide_regions(); void do_update_regions(); #endif // NDEBUG