26 _lock(
"MouseWatcherBase")
30 _show_regions =
false;
31 _color.set(0.4, 0.6f, 1.0f, 1.0f);
52 if (UNLIKELY(_show_regions)) {
55 Regions::const_iterator ri =
56 std::find(_regions.begin(), _regions.end(), region);
58 if (ri == _regions.end()) {
59 nassertv(_vizzes.size() == _regions.size());
60 _vizzes.push_back(make_viz_region(region));
67 _regions.push_back(std::move(region));
83 Regions::const_iterator ri = lower_bound(_regions.begin(), _regions.end(), ptr);
84 return (ri != _regions.end() && (*ri) == ptr);
88 Regions::const_iterator ri = find(_regions.begin(), _regions.end(), ptr);
89 return (ri != _regions.end());
99 return do_remove_region(region);
112 if (region->get_name() == name) {
132 _show_regions_root.node()->remove_all_children();
148 return _regions.size();
158 LightMutexHolder holder(_lock);
160 ((MouseWatcherBase *)
this)->do_sort_regions();
162 if (n < _regions.size()) {
171void MouseWatcherBase::
172output(std::ostream &out)
const {
173 out <<
"MouseWatcherGroup (" << _regions.size() <<
" regions)";
179void MouseWatcherBase::
180write(std::ostream &out,
int indent_level)
const {
181 LightMutexHolder holder(_lock);
183 for (MouseWatcherRegion *region : _regions) {
184 region->write(out, indent_level);
188#if !defined(NDEBUG) || !defined(CPPPARSER)
198 do_show_regions(render2d, bin_name, draw_order);
203#if !defined(NDEBUG) || !defined(CPPPARSER)
219#if !defined(NDEBUG) || !defined(CPPPARSER)
232#if !defined(NDEBUG) || !defined(CPPPARSER)
250void MouseWatcherBase::
253 _regions.sort_unique();
262bool MouseWatcherBase::
265 PT(MouseWatcherRegion) ptr = region;
266 Regions::iterator ri;
270 ri = lower_bound(_regions.begin(), _regions.end(), ptr);
273 ri = find(_regions.begin(), _regions.end(), ptr);
276 if (ri != _regions.end() && (*ri) == ptr) {
281 nassertr(_vizzes.size() == _regions.size(),
false);
282 size_t index = ri - _regions.begin();
283 Vizzes::iterator vi = _vizzes.begin() + index;
284 _show_regions_root.node()->remove_child(*vi);
302void MouseWatcherBase::
303do_show_regions(
const NodePath &render2d,
const std::string &bin_name,
306 _show_regions =
true;
308 _show_regions_root.
set_bin(bin_name, draw_order);
318void MouseWatcherBase::
320 _show_regions_root.remove_node();
321 _show_regions =
false;
331void MouseWatcherBase::
333 nassertv(_lock.debug_is_locked());
339 _show_regions_root.node()->remove_all_children();
341 _vizzes.reserve(_regions.size());
343 for (MouseWatcherRegion *region : _regions) {
344 _vizzes.push_back(make_viz_region(region));
359 nassertr(_lock.debug_is_locked(),
nullptr);
361 LineSegs ls(
"show_regions");
362 ls.set_color(_color);
364 const LVecBase4 &f = region->get_frame();
366 ls.move_to(LVector3::rfu(f[0], 0.0f, f[2]));
367 ls.draw_to(LVector3::rfu(f[1], 0.0f, f[2]));
368 ls.draw_to(LVector3::rfu(f[1], 0.0f, f[3]));
369 ls.draw_to(LVector3::rfu(f[0], 0.0f, f[3]));
370 ls.draw_to(LVector3::rfu(f[0], 0.0f, f[2]));
372 PT(PandaNode) node = ls.create();
373 _show_regions_root.attach_new_node(node);
Similar to MutexHolder, but for a light mutex.
This represents a collection of MouseWatcherRegions that may be managed as a group.
bool remove_region(MouseWatcherRegion *region)
Removes the indicated region from the group.
get_num_regions
Returns the number of regions in the group.
void clear_regions()
Removes all the regions from the group.
void add_region(PT(MouseWatcherRegion) region)
Adds the indicated region to the set of regions in the group.
void show_regions(const NodePath &render2d, const std::string &bin_name, int draw_order)
Enables the visualization of all of the regions handled by this MouseWatcherBase.
MouseWatcherRegion * find_region(const std::string &name) const
Returns a pointer to the first region found with the indicated name.
get_region
Returns the nth region of the group; returns NULL if there is no nth region.
void set_color(const LColor &color)
Specifies the color used to draw the region rectangles for the regions visualized by show_regions().
void update_regions()
Refreshes the visualization created by show_regions().
void hide_regions()
Stops the visualization created by a previous call to show_regions().
bool has_region(MouseWatcherRegion *region) const
Returns true if the indicated region has already been added to the MouseWatcherBase,...
This is the class that defines a rectangular region on the screen for the MouseWatcher.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
void set_bin(const std::string &bin_name, int draw_order, int priority=0)
Assigns the geometry at this level and below to the named rendering bin.
A basic node of the scene graph or data graph.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.