Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CEGUIImagesetManager.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIImagesetManager.cpp
00003         created:        21/2/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implements the ImagesetManager class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "CEGUIImagesetManager.h"
00027 #include "CEGUIExceptions.h"
00028 #include "CEGUILogger.h"
00029 #include "CEGUIImageset.h"
00030 
00031 // Start of CEGUI namespace section
00032 namespace CEGUI
00033 {
00034 /*************************************************************************
00035         Static Data Definitions
00036 *************************************************************************/
00037 // singleton instance pointer
00038 template<> ImagesetManager* Singleton<ImagesetManager>::ms_Singleton    = NULL;
00039 
00040 
00041 /*************************************************************************
00042         Constructor
00043 *************************************************************************/
00044 ImagesetManager::ImagesetManager(void)
00045 {
00046         Logger::getSingleton().logEvent((utf8*)"CEGUI::ImagesetManager singleton created");
00047 }
00048 
00049 
00050 /*************************************************************************
00051         Destructor
00052 *************************************************************************/
00053 ImagesetManager::~ImagesetManager(void)
00054 {
00055         Logger::getSingleton().logEvent((utf8*)"---- Begining cleanup of Imageset system ----");
00056 
00057         destroyAllImagesets();
00058 
00059         Logger::getSingleton().logEvent((utf8*)"CEGUI::ImagesetManager singleton destroyed");
00060 }
00061 
00062 
00063 /*************************************************************************
00064         Create an empty Imageset that has the given name and uses the
00065         given Texture
00066 *************************************************************************/
00067 Imageset* ImagesetManager::createImageset(const String& name, Texture* texture)
00068 {
00069         Logger::getSingleton().logEvent((utf8*)"Attempting to create Imageset '" + name +"' with texture only.");
00070 
00071         if (isImagesetPresent(name))
00072         {
00073                 throw   AlreadyExistsException("ImagesetManager::createImageset - An Imageset object named '" + name + "' already exists.");
00074         }
00075 
00076         Imageset* temp = new Imageset(name, texture);
00077         d_imagesets[name] = temp;
00078 
00079         return temp;
00080 }
00081 
00082 
00083 /*************************************************************************
00084         Create an Imageset object from the specified file
00085 *************************************************************************/
00086 Imageset* ImagesetManager::createImageset(const String& filename, const String& resourceGroup)
00087 {
00088         Logger::getSingleton().logEvent((utf8*)"Attempting to create an Imageset from the information specified in file '" + filename + "'.");
00089 
00090         Imageset* temp = new Imageset(filename, resourceGroup);
00091 
00092         String  name = temp->getName();
00093 
00094         if (isImagesetPresent(name))
00095         {
00096                 delete temp;
00097 
00098                 throw   AlreadyExistsException("ImagesetManager::createImageset - An Imageset object named '" + name + "' already exists.");
00099         }
00100 
00101         d_imagesets[name] = temp;
00102 
00103         return temp;
00104 }
00105 
00106 
00107 /*************************************************************************
00108         Destroys the Imageset with the specified name
00109 *************************************************************************/
00110 void ImagesetManager::destroyImageset(const String& name)
00111 {
00112         ImagesetRegistry::iterator      pos = d_imagesets.find(name);
00113 
00114         if (pos != d_imagesets.end())
00115         {
00116                 String tmpName(name);
00117 
00118                 delete pos->second;
00119                 d_imagesets.erase(pos);
00120 
00121                 Logger::getSingleton().logEvent((utf8*)"Imageset '" + tmpName +"' has been destroyed.", Informative);
00122         }
00123 
00124 }
00125 
00126 
00127 /*************************************************************************
00128         Destroys the given Imageset object
00129 *************************************************************************/
00130 void ImagesetManager::destroyImageset(Imageset* imageset)
00131 {
00132         if (imageset != NULL)
00133         {
00134                 destroyImageset(imageset->getName());
00135         }
00136 
00137 }
00138 
00139 
00140 /*************************************************************************
00141         Destroy all Imageset objects
00142 *************************************************************************/
00143 void ImagesetManager::destroyAllImagesets(void)
00144 {
00145         while (!d_imagesets.empty())
00146         {
00147                 destroyImageset(d_imagesets.begin()->first);
00148         }
00149 }
00150 
00151 /*************************************************************************
00152         Returns a pointer to the Imageset object with the specified name
00153 *************************************************************************/
00154 Imageset* ImagesetManager::getImageset(const String& name) const
00155 {
00156         ImagesetRegistry::const_iterator        pos = d_imagesets.find(name);
00157 
00158         if (pos == d_imagesets.end())
00159         {
00160                 throw UnknownObjectException("ImagesetManager::getImageset - No Imageset named '" + name + "' is present in the system.");
00161         }
00162 
00163         return pos->second;
00164 }
00165 
00166 
00167 /*************************************************************************
00168         Notify the ImagesetManager of the current (usually new) display
00169         resolution.
00170 *************************************************************************/
00171 void ImagesetManager::notifyScreenResolution(const Size& size)
00172 {
00173         // notify all attached Imageset objects of the change in resolution
00174         ImagesetRegistry::iterator pos = d_imagesets.begin(), end = d_imagesets.end();
00175 
00176         for (; pos != end; ++pos)
00177         {
00178                 pos->second->notifyScreenResolution(size);
00179         }
00180 
00181 }
00182 
00183 
00184 ImagesetManager& ImagesetManager::getSingleton(void)
00185 {
00186         return Singleton<ImagesetManager>::getSingleton();
00187 }
00188 
00189 
00190 ImagesetManager* ImagesetManager::getSingletonPtr(void)
00191 {
00192         return Singleton<ImagesetManager>::getSingletonPtr();
00193 }
00194 
00195 
00196 /*************************************************************************
00197         Return a ImagesetManager::ImagesetIterator object to iterate over
00198         the available Imageset objects.
00199 *************************************************************************/
00200 ImagesetManager::ImagesetIterator ImagesetManager::getIterator(void) const
00201 {
00202         return ImagesetIterator(d_imagesets.begin(), d_imagesets.end());
00203 }
00204 
00205 
00206 } // End of  CEGUI namespace section

Generated on Wed Feb 16 12:41:06 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1