Panda3D
pgTop.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pgTop.cxx
10  * @author drose
11  * @date 2002-03-13
12  */
13 
14 #include "pgTop.h"
15 #include "pgMouseWatcherGroup.h"
16 #include "pgCullTraverser.h"
17 #include "cullBinAttrib.h"
18 
19 #include "omniBoundingVolume.h"
20 
21 TypeHandle PGTop::_type_handle;
22 
23 /**
24  *
25  */
26 PGTop::
27 PGTop(const std::string &name) :
28  PandaNode(name)
29 {
30  set_cull_callback();
31 
32  _start_sort = 0;
33 
34  // A PGTop node normally has an infinite bounding volume. Screw culling.
35  set_internal_bounds(new OmniBoundingVolume());
36  set_final(true);
37 
38  // Also, screw state sorting. By default, everything under PGTop will be
39  // unsorted: rendered in scene graph order. This is closer to what the user
40  // wants anyway in a 2-d scene graph.
41 
42  set_attrib(CullBinAttrib::make("unsorted", 0));
43 }
44 
45 /**
46  *
47  */
48 PGTop::
49 ~PGTop() {
50  set_mouse_watcher(nullptr);
51 }
52 
53 /**
54  * Returns a newly-allocated Node that is a shallow copy of this one. It will
55  * be a different Node pointer, but its internal data may or may not be shared
56  * with that of the original Node.
57  */
59 make_copy() const {
60  return new PGTop(*this);
61 }
62 
63 /**
64  * This function will be called during the cull traversal to perform any
65  * additional operations that should be performed at cull time. This may
66  * include additional manipulation of render state or additional
67  * visible/invisible decisions, or any other arbitrary operation.
68  *
69  * Note that this function will *not* be called unless set_cull_callback() is
70  * called in the constructor of the derived class. It is necessary to call
71  * set_cull_callback() to indicated that we require cull_callback() to be
72  * called.
73  *
74  * By the time this function is called, the node has already passed the
75  * bounding-volume test for the viewing frustum, and the node's transform and
76  * state have already been applied to the indicated CullTraverserData object.
77  *
78  * The return value is true if this node should be visible, or false if it
79  * should be culled.
80  */
81 bool PGTop::
83  // We create a new MouseWatcherGroup for the purposes of collecting a new
84  // set of regions visible onscreen.
85  PT(PGMouseWatcherGroup) old_watcher_group;
86  if (_watcher_group != nullptr) {
87  _watcher_group->clear_top(this);
88  old_watcher_group = _watcher_group;
89  _watcher_group = new PGMouseWatcherGroup(this);
90  }
91 
92  // Now subsitute for the normal CullTraverser a special one of our own
93  // choosing. This just carries around a pointer back to the PGTop node, for
94  // the convenience of PGItems to register themselves as they are drawn.
95  PGCullTraverser pg_trav(this, trav);
96  pg_trav.local_object();
97  pg_trav._sort_index = _start_sort;
98  pg_trav.traverse_below(data);
99  pg_trav.end_traverse();
100 
101  // Now tell the watcher about the new set of regions. Strictly speaking, we
102  // shouldn't do this until the frame that we're about to render has been
103  // presented; otherwise, we may make regions active before they are actually
104  // visible. But no one has complained about this so far.
105  if (_watcher_group != nullptr) {
106  nassertr(_watcher != nullptr, false);
107  _watcher->replace_group(old_watcher_group, _watcher_group);
108  }
109 
110  // We've taken care of the traversal, thank you.
111  return false;
112 }
113 
114 /**
115  * Returns true if there is some value to visiting this particular node during
116  * the cull traversal for any camera, false otherwise. This will be used to
117  * optimize the result of get_net_draw_show_mask(), so that any subtrees that
118  * contain only nodes for which is_renderable() is false need not be visited.
119  */
120 bool PGTop::
121 is_renderable() const {
122  // We flag the PGTop as renderable, even though it technically doesn't have
123  // anything to render, but we do need the traverser to visit it every frame.
124  return true;
125 }
126 
127 /**
128  * Sets the MouseWatcher pointer that the PGTop object registers its PG items
129  * with. This must be set before the PG items are active.
130  */
131 void PGTop::
133  if (_watcher_group != nullptr) {
134  _watcher_group->clear_top(this);
135  }
136  if (_watcher != nullptr) {
137  _watcher->remove_group(_watcher_group);
138  }
139 
140  _watcher = watcher;
141  _watcher_group = nullptr;
142 
143  if (_watcher != nullptr) {
144  _watcher_group = new PGMouseWatcherGroup(this);
145  _watcher->add_group(_watcher_group);
146  }
147 }
The "top" node of the new Panda GUI system.
Definition: pgTop.h:38
This TFormer maintains a list of rectangular regions on the screen that are considered special mouse ...
Definition: mouseWatcher.h:61
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
virtual void end_traverse()
Should be called when the traverser has finished traversing its scene, this gives it a chance to do a...
virtual void traverse_below(CullTraverserData &data)
Traverses all the children of the indicated node, with the given data, which has been converted into ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Definition: pgTop.cxx:82
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a specialization on MouseWatcherGroup, to associate it with a PGTop.
This is a specialization of CullTraverser for use within the pgui system.
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
Definition: pgTop.cxx:59
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_attrib(const RenderAttrib *attrib, int override=0)
Adds the indicated render attribute to the scene graph on this node.
Definition: pandaNode.cxx:944
void local_object()
This function should be called, once, immediately after creating a new instance of some ReferenceCoun...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a special kind of GeometricBoundingVolume that fills all of space.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
void set_mouse_watcher(MouseWatcher *watcher)
Sets the MouseWatcher pointer that the PGTop object registers its PG items with.
Definition: pgTop.cxx:132
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pgTop.cxx:121