Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: Wed Feb 16 2011 00003 author: Paul D Turner <paul@cegui.org.uk> 00004 *************************************************************************/ 00005 /*************************************************************************** 00006 * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining 00009 * a copy of this software and associated documentation files (the 00010 * "Software"), to deal in the Software without restriction, including 00011 * without limitation the rights to use, copy, modify, merge, publish, 00012 * distribute, sublicense, and/or sell copies of the Software, and to 00013 * permit persons to whom the Software is furnished to do so, subject to 00014 * the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be 00017 * included in all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00020 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00021 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00022 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00023 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00024 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00025 * OTHER DEALINGS IN THE SOFTWARE. 00026 ***************************************************************************/ 00027 #ifndef _CEGUIImageManager_h_ 00028 #define _CEGUIImageManager_h_ 00029 00030 #include "CEGUI/Singleton.h" 00031 #include "CEGUI/ChainedXMLHandler.h" 00032 #include "CEGUI/String.h" 00033 #include "CEGUI/Size.h" 00034 #include "CEGUI/ImageFactory.h" 00035 #include "CEGUI/Logger.h" 00036 #include "CEGUI/Exceptions.h" 00037 #include "CEGUI/IteratorBase.h" 00038 #include <map> 00039 00040 #if defined(_MSC_VER) 00041 # pragma warning(push) 00042 # pragma warning(disable : 4251) 00043 #endif 00044 00045 // Start of CEGUI namespace section 00046 namespace CEGUI 00047 { 00048 class CEGUIEXPORT ImageManager : 00049 public Singleton<ImageManager>, 00050 public AllocatedObject<ImageManager>, 00051 public ChainedXMLHandler 00052 { 00053 public: 00054 ImageManager(); 00055 ~ImageManager(); 00056 00077 template <typename T> 00078 void addImageType(const String& name); 00079 00097 void removeImageType(const String& name); 00098 00111 bool isImageTypeAvailable(const String& name) const; 00112 00132 Image& create(const String& type, const String& name); 00133 00134 Image& create(const XMLAttributes& attributes); 00135 00136 void destroy(Image& image); 00137 void destroy(const String& name); 00138 void destroyAll(); 00139 00140 Image& get(const String& name) const; 00141 bool isDefined(const String& name) const; 00142 00143 uint getImageCount() const; 00144 00145 void loadImageset(const String& filename, const String& resource_group = ""); 00146 void loadImagesetFromString(const String& source); 00147 00148 void destroyImageCollection(const String& prefix, 00149 const bool delete_texture = true); 00150 00151 void addFromImageFile(const String& name, 00152 const String& filename, 00153 const String& resource_group = ""); 00154 00162 void notifyDisplaySizeChanged(const Sizef& size); 00163 00171 static void setImagesetDefaultResourceGroup(const String& resourceGroup) 00172 { d_imagesetDefaultResourceGroup = resourceGroup; } 00173 00182 static const String& getImagesetDefaultResourceGroup() 00183 { return d_imagesetDefaultResourceGroup; } 00184 00185 // XMLHandler overrides 00186 const String& getSchemaName() const; 00187 const String& getDefaultResourceGroup() const; 00188 00190 typedef std::pair<Image*, ImageFactory*> ImagePair; 00191 00193 typedef std::map<String, ImagePair, 00194 StringFastLessCompare 00195 CEGUI_MAP_ALLOC(String, Image*)> ImageMap; 00196 00198 typedef ConstMapIterator<ImageMap> ImageIterator; 00199 00205 ImageIterator getIterator() const; 00206 00207 private: 00208 // implement chained xml handler abstract interface 00209 void elementStartLocal(const String& element, const XMLAttributes& attributes); 00210 void elementEndLocal(const String& element); 00211 00213 typedef std::map<String, ImageFactory*, StringFastLessCompare 00214 CEGUI_MAP_ALLOC(String, ImageFactory*)> ImageFactoryRegistry; 00215 00217 void destroy(ImageMap::iterator& iter); 00218 00219 // XML parsing helper functions. 00220 void elementImagesetStart(const XMLAttributes& attributes); 00221 void elementImageStart(const XMLAttributes& attributes); 00223 void validateImagesetFileVersion(const XMLAttributes& attrs); 00224 00226 static String d_imagesetDefaultResourceGroup; 00227 00229 ImageFactoryRegistry d_factories; 00231 ImageMap d_images; 00232 }; 00233 00234 //---------------------------------------------------------------------------// 00235 template <typename T> 00236 void ImageManager::addImageType(const String& name) 00237 { 00238 if (isImageTypeAvailable(name)) 00239 CEGUI_THROW(AlreadyExistsException( 00240 "Image type already exists: " + name)); 00241 00242 d_factories[name] = CEGUI_NEW_AO TplImageFactory<T>; 00243 00244 Logger::getSingleton().logEvent( 00245 "[CEGUI::ImageManager] Registered Image type: " + name); 00246 } 00247 00248 //---------------------------------------------------------------------------// 00249 } // End of CEGUI namespace section 00250 00251 #if defined(_MSC_VER) 00252 # pragma warning(pop) 00253 #endif 00254 00255 #endif // end of guard _CEGUIImageManager_h_ 00256