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