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