Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/tform/mouseWatcherGroup.cxx

Go to the documentation of this file.
00001 // Filename: mouseWatcherGroup.cxx
00002 // Created by:  drose (02Jul01)
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 "mouseWatcherGroup.h"
00020 
00021 
00022 TypeHandle MouseWatcherGroup::_type_handle;
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: MouseWatcherGroup::Destructor
00026 //       Access: Public, Virtual
00027 //  Description: 
00028 ////////////////////////////////////////////////////////////////////
00029 MouseWatcherGroup::
00030 ~MouseWatcherGroup() {
00031 }
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //     Function: MouseWatcherGroup::add_region
00035 //       Access: Published
00036 //  Description: Adds the indicated region to the set of regions in
00037 //               the group.  Returns true if it was successfully
00038 //               added, or false if it was already on the list.
00039 ////////////////////////////////////////////////////////////////////
00040 bool MouseWatcherGroup::
00041 add_region(MouseWatcherRegion *region) {
00042   //return _regions.insert(region).second;
00043 
00044   PT(MouseWatcherRegion) pt = region;
00045 
00046   // We will only bother to check for duplicates in the region list if
00047   // we are building opt 1 or 2.  The overhead for doing this may be
00048   // too high if we have many regions.
00049 #ifdef _DEBUG
00050   // See if the region is in the set/vector already
00051   Regions::const_iterator ri = 
00052     find(_regions.begin(), _regions.end(), pt);
00053   if (ri != _regions.end()) {
00054     // Already in the set, return false
00055     return false;
00056   }
00057 #endif
00058 
00059   // Not in the set, add it and return true
00060   _regions.push_back(pt);
00061   return true;
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: MouseWatcherGroup::has_region
00066 //       Access: Published
00067 //  Description: Returns true if the indicated region has already been
00068 //               added to the MouseWatcherGroup, false otherwise.
00069 ////////////////////////////////////////////////////////////////////
00070 bool MouseWatcherGroup::
00071 has_region(MouseWatcherRegion *region) const {
00072   // See if the region is in the set/vector
00073   PT(MouseWatcherRegion) pt = region;
00074   Regions::const_iterator ri = 
00075     find(_regions.begin(), _regions.end(), pt);
00076   if (ri != _regions.end()) {
00077     // Found it
00078     return true;
00079   }
00080   // Did not find the region 
00081   return false;
00082 }
00083 
00084 ////////////////////////////////////////////////////////////////////
00085 //     Function: MouseWatcherGroup::remove_region
00086 //       Access: Published
00087 //  Description: Removes the indicated region from the group.
00088 //               Returns true if it was successfully removed, or false
00089 //               if it wasn't there in the first place.
00090 ////////////////////////////////////////////////////////////////////
00091 bool MouseWatcherGroup::
00092 remove_region(MouseWatcherRegion *region) {
00093   //return _regions.erase(region) != 0;
00094 
00095   // See if the region is in the set/vector
00096   PT(MouseWatcherRegion) pt = region;
00097   Regions::iterator ri = 
00098     find(_regions.begin(), _regions.end(), pt);
00099   if (ri != _regions.end()) {
00100     // Found it, now erase it
00101     _regions.erase(ri);
00102     return true;
00103   }
00104 
00105   // Did not find the region to erase
00106   return false;
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: MouseWatcherGroup::find_region
00111 //       Access: Published
00112 //  Description: Returns a pointer to the first region found with the
00113 //               indicated name.  If multiple regions share the same
00114 //               name, the one that is returned is indeterminate.
00115 ////////////////////////////////////////////////////////////////////
00116 MouseWatcherRegion *MouseWatcherGroup::
00117 find_region(const string &name) const {
00118   Regions::const_iterator ri;
00119   for (ri = _regions.begin(); ri != _regions.end(); ++ri) {
00120     MouseWatcherRegion *region = (*ri);
00121     if (region->get_name() == name) {
00122       return region;
00123     }
00124   }
00125 
00126   return (MouseWatcherRegion *)NULL;
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: MouseWatcherGroup::clear_regions
00131 //       Access: Published
00132 //  Description: Removes all the regions from the group.
00133 ////////////////////////////////////////////////////////////////////
00134 void MouseWatcherGroup::
00135 clear_regions() {
00136   _regions.clear();
00137 }

Generated on Fri May 2 00:44:28 2003 for Panda by doxygen1.3