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

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     Create an Imageset object from the specified image file.
00109 *************************************************************************/
00110 Imageset* ImagesetManager::createImagesetFromImageFile(const String& name, const String& filename, const String& resourceGroup)
00111 {
00112     Logger::getSingleton().logEvent((utf8*)"Attempting to create Imageset '" + name + "' using image file '" + filename + "'.");
00113 
00114     if (isImagesetPresent(name))
00115     {
00116         throw   AlreadyExistsException("ImagesetManager::createImageset - An Imageset object named '" + name + "' already exists.");
00117     }
00118 
00119     Imageset* temp = new Imageset(name, filename, resourceGroup);
00120     d_imagesets[name] = temp;
00121 
00122     return temp;
00123 }
00124 
00125 
00126 /*************************************************************************
00127         Destroys the Imageset with the specified name
00128 *************************************************************************/
00129 void ImagesetManager::destroyImageset(const String& name)
00130 {
00131         ImagesetRegistry::iterator      pos = d_imagesets.find(name);
00132 
00133         if (pos != d_imagesets.end())
00134         {
00135                 String tmpName(name);
00136 
00137                 delete pos->second;
00138                 d_imagesets.erase(pos);
00139 
00140                 Logger::getSingleton().logEvent((utf8*)"Imageset '" + tmpName +"' has been destroyed.", Informative);
00141         }
00142 
00143 }
00144 
00145 
00146 /*************************************************************************
00147         Destroys the given Imageset object
00148 *************************************************************************/
00149 void ImagesetManager::destroyImageset(Imageset* imageset)
00150 {
00151         if (imageset != NULL)
00152         {
00153                 destroyImageset(imageset->getName());
00154         }
00155 
00156 }
00157 
00158 
00159 /*************************************************************************
00160         Destroy all Imageset objects
00161 *************************************************************************/
00162 void ImagesetManager::destroyAllImagesets(void)
00163 {
00164         while (!d_imagesets.empty())
00165         {
00166                 destroyImageset(d_imagesets.begin()->first);
00167         }
00168 }
00169 
00170 /*************************************************************************
00171         Returns a pointer to the Imageset object with the specified name
00172 *************************************************************************/
00173 Imageset* ImagesetManager::getImageset(const String& name) const
00174 {
00175         ImagesetRegistry::const_iterator        pos = d_imagesets.find(name);
00176 
00177         if (pos == d_imagesets.end())
00178         {
00179                 throw UnknownObjectException("ImagesetManager::getImageset - No Imageset named '" + name + "' is present in the system.");
00180         }
00181 
00182         return pos->second;
00183 }
00184 
00185 
00186 /*************************************************************************
00187         Notify the ImagesetManager of the current (usually new) display
00188         resolution.
00189 *************************************************************************/
00190 void ImagesetManager::notifyScreenResolution(const Size& size)
00191 {
00192         // notify all attached Imageset objects of the change in resolution
00193         ImagesetRegistry::iterator pos = d_imagesets.begin(), end = d_imagesets.end();
00194 
00195         for (; pos != end; ++pos)
00196         {
00197                 pos->second->notifyScreenResolution(size);
00198         }
00199 
00200 }
00201 
00202 
00203 ImagesetManager& ImagesetManager::getSingleton(void)
00204 {
00205         return Singleton<ImagesetManager>::getSingleton();
00206 }
00207 
00208 
00209 ImagesetManager* ImagesetManager::getSingletonPtr(void)
00210 {
00211         return Singleton<ImagesetManager>::getSingletonPtr();
00212 }
00213 
00214 
00215 /*************************************************************************
00216         Return a ImagesetManager::ImagesetIterator object to iterate over
00217         the available Imageset objects.
00218 *************************************************************************/
00219 ImagesetManager::ImagesetIterator ImagesetManager::getIterator(void) const
00220 {
00221         return ImagesetIterator(d_imagesets.begin(), d_imagesets.end());
00222 }
00223 
00224 
00225 void ImagesetManager::writeImagesetToStream(const String& imageset, OutStream& out_stream) const
00226 {
00227     const Imageset* iset = getImageset(imageset);
00228 
00229     // output xml header
00230     out_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
00231 
00232     // output imageset data
00233     iset->writeXMLToStream(out_stream);
00234 }
00235 
00236 
00237 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:32 2005 for Crazy Eddies GUI System by  doxygen 1.4.3