00001 // Filename: pgTop.cxx 00002 // Created by: drose (13Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "pgTop.h" 00020 #include "pgMouseWatcherGroup.h" 00021 #include "pgCullTraverser.h" 00022 #include "cullBinAttrib.h" 00023 00024 #include "omniBoundingVolume.h" 00025 00026 TypeHandle PGTop::_type_handle; 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: PGTop::Constructor 00030 // Access: Published 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 PGTop:: 00034 PGTop(const string &name) : 00035 PandaNode(name) 00036 { 00037 _watcher_group = (PGMouseWatcherGroup *)NULL; 00038 00039 // A PGTop node normally has an infinite bounding volume. Screw 00040 // culling. 00041 set_bound(OmniBoundingVolume()); 00042 set_final(true); 00043 00044 // Also, screw state sorting. By default, everything under PGTop 00045 // will be unsorted: rendered in scene graph order. This is closer 00046 // to what the user wants anyway in a 2-d scene graph. 00047 00048 set_attrib(CullBinAttrib::make("unsorted", 0)); 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: PGTop::Destructor 00053 // Access: Public, Virtual 00054 // Description: 00055 //////////////////////////////////////////////////////////////////// 00056 PGTop:: 00057 ~PGTop() { 00058 set_mouse_watcher((MouseWatcher *)NULL); 00059 } 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Function: PGTop::make_copy 00063 // Access: Protected, Virtual 00064 // Description: Returns a newly-allocated Node that is a shallow copy 00065 // of this one. It will be a different Node pointer, 00066 // but its internal data may or may not be shared with 00067 // that of the original Node. 00068 //////////////////////////////////////////////////////////////////// 00069 PandaNode *PGTop:: 00070 make_copy() const { 00071 return new PGTop(*this); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: PGTop::has_cull_callback 00076 // Access: Protected, Virtual 00077 // Description: Should be overridden by derived classes to return 00078 // true if cull_callback() has been defined. Otherwise, 00079 // returns false to indicate cull_callback() does not 00080 // need to be called for this node during the cull 00081 // traversal. 00082 //////////////////////////////////////////////////////////////////// 00083 bool PGTop:: 00084 has_cull_callback() const { 00085 return true; 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: PGTop::cull_callback 00090 // Access: Protected, Virtual 00091 // Description: If has_cull_callback() returns true, this function 00092 // will be called during the cull traversal to perform 00093 // any additional operations that should be performed at 00094 // cull time. This may include additional manipulation 00095 // of render state or additional visible/invisible 00096 // decisions, or any other arbitrary operation. 00097 // 00098 // By the time this function is called, the node has 00099 // already passed the bounding-volume test for the 00100 // viewing frustum, and the node's transform and state 00101 // have already been applied to the indicated 00102 // CullTraverserData object. 00103 // 00104 // The return value is true if this node should be 00105 // visible, or false if it should be culled. 00106 //////////////////////////////////////////////////////////////////// 00107 bool PGTop:: 00108 cull_callback(CullTraverser *trav, CullTraverserData &data) { 00109 // Empty our set of regions in preparation for re-adding whichever 00110 // ones we encounter in the traversal that are current. 00111 clear_regions(); 00112 00113 // Now subsitute for the normal CullTraverser a special one of our 00114 // own choosing. This just carries around a pointer back to the 00115 // PGTop node, for the convenience of PGItems to register themselves 00116 // as they are drawn. 00117 PGCullTraverser pg_trav(this, trav); 00118 pg_trav.traverse_below(data); 00119 00120 // We've taken care of the traversal, thank you. 00121 return false; 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: PGTop::set_mouse_watcher 00126 // Access: Published 00127 // Description: Sets the MouseWatcher pointer that the PGTop object 00128 // registers its PG items with. This must be set before 00129 // the PG items are active. 00130 //////////////////////////////////////////////////////////////////// 00131 void PGTop:: 00132 set_mouse_watcher(MouseWatcher *watcher) { 00133 if (_watcher_group != (PGMouseWatcherGroup *)NULL) { 00134 _watcher_group->clear_top(this); 00135 } 00136 if (_watcher != (MouseWatcher *)NULL) { 00137 _watcher->remove_group(_watcher_group); 00138 } 00139 00140 _watcher = watcher; 00141 _watcher_group = (PGMouseWatcherGroup *)NULL; 00142 00143 if (_watcher != (MouseWatcher *)NULL) { 00144 // We create a new PGMouseWatcherGroup, but we don't own the 00145 // reference count; the watcher will own this for us. 00146 _watcher_group = new PGMouseWatcherGroup(this); 00147 _watcher->add_group(_watcher_group); 00148 } 00149 }