Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
ImageManager.h
1 /***********************************************************************
2  created: Wed Feb 16 2011
3  author: Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #ifndef _CEGUIImageManager_h_
28 #define _CEGUIImageManager_h_
29 
30 #include "CEGUI/Singleton.h"
31 #include "CEGUI/ChainedXMLHandler.h"
32 #include "CEGUI/String.h"
33 #include "CEGUI/Size.h"
34 #include "CEGUI/ImageFactory.h"
35 #include "CEGUI/Logger.h"
36 #include "CEGUI/Exceptions.h"
37 #include "CEGUI/IteratorBase.h"
38 #include <map>
39 
40 #if defined(_MSC_VER)
41 # pragma warning(push)
42 # pragma warning(disable : 4251)
43 #endif
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
48 class CEGUIEXPORT ImageManager :
49  public Singleton<ImageManager>,
50  public AllocatedObject<ImageManager>,
51  public ChainedXMLHandler
52 {
53 public:
54  ImageManager();
55  ~ImageManager();
56 
77  template <typename T>
78  void addImageType(const String& name);
79 
97  void removeImageType(const String& name);
98 
111  bool isImageTypeAvailable(const String& name) const;
112 
132  Image& create(const String& type, const String& name);
133 
134  Image& create(const XMLAttributes& attributes);
135 
136  void destroy(Image& image);
137  void destroy(const String& name);
138  void destroyAll();
139 
140  Image& get(const String& name) const;
141  bool isDefined(const String& name) const;
142 
143  uint getImageCount() const;
144 
145  void loadImageset(const String& filename, const String& resource_group = "");
146  void loadImagesetFromString(const String& source);
147 
148  void destroyImageCollection(const String& prefix,
149  const bool delete_texture = true);
150 
151  void addFromImageFile(const String& name,
152  const String& filename,
153  const String& resource_group = "");
154 
162  void notifyDisplaySizeChanged(const Sizef& size);
163 
171  static void setImagesetDefaultResourceGroup(const String& resourceGroup)
172  { d_imagesetDefaultResourceGroup = resourceGroup; }
173 
182  static const String& getImagesetDefaultResourceGroup()
183  { return d_imagesetDefaultResourceGroup; }
184 
185  // XMLHandler overrides
186  const String& getSchemaName() const;
187  const String& getDefaultResourceGroup() const;
188 
190  typedef std::pair<Image*, ImageFactory*> ImagePair;
191 
193  typedef std::map<String, ImagePair,
195  CEGUI_MAP_ALLOC(String, Image*)> ImageMap;
196 
199 
205  ImageIterator getIterator() const;
206 
207 private:
208  // implement chained xml handler abstract interface
209  void elementStartLocal(const String& element, const XMLAttributes& attributes);
210  void elementEndLocal(const String& element);
211 
213  typedef std::map<String, ImageFactory*, StringFastLessCompare
214  CEGUI_MAP_ALLOC(String, ImageFactory*)> ImageFactoryRegistry;
215 
217  void destroy(ImageMap::iterator& iter);
218 
219  // XML parsing helper functions.
220  void elementImagesetStart(const XMLAttributes& attributes);
221  void elementImageStart(const XMLAttributes& attributes);
223  void validateImagesetFileVersion(const XMLAttributes& attrs);
224 
226  static String d_imagesetDefaultResourceGroup;
227 
229  ImageFactoryRegistry d_factories;
231  ImageMap d_images;
232 };
233 
234 //---------------------------------------------------------------------------//
235 template <typename T>
237 {
238  if (isImageTypeAvailable(name))
239  CEGUI_THROW(AlreadyExistsException(
240  "Image type already exists: " + name));
241 
242  d_factories[name] = CEGUI_NEW_AO TplImageFactory<T>;
243 
244  Logger::getSingleton().logEvent(
245  "[CEGUI::ImageManager] Registered Image type: " + name);
246 }
247 
248 //---------------------------------------------------------------------------//
249 } // End of CEGUI namespace section
250 
251 #if defined(_MSC_VER)
252 # pragma warning(pop)
253 #endif
254 
255 #endif // end of guard _CEGUIImageManager_h_
256