Crazy Eddie's GUI System  0.8.7
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 
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 
Functor that can be used as comparator in a std::map with String keys. It's faster than using the def...
Definition: String.h:5579
Definition: MemoryAllocatedObject.h:109
Templatised ImageFactory subclass used internally by the system.
Definition: ImageFactory.h:64
void addImageType(const String &name)
Register an Image subclass with the system and associate it with the identifier name.
Definition: ImageManager.h:236
Interface for Image.
Definition: Image.h:158
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
Exception class used when an attempt is made create a named object of a particular type when an objec...
Definition: Exceptions.h:483
static void setImagesetDefaultResourceGroup(const String &resourceGroup)
Sets the default resource group to be used when loading imageset data.
Definition: ImageManager.h:171
ConstMapIterator< ImageMap > ImageIterator
ConstBaseIterator type definition.
Definition: ImageManager.h:198
Definition: Singleton.h:55
Definition: ImageManager.h:48
Class representing a block of attributes associated with an XML element.
Definition: XMLAttributes.h:46
iterator class for maps
Definition: IteratorBase.h:196
std::map< String, ImagePair, StringFastLessCompare CEGUI_MAP_ALLOC(String, Image *)> ImageMap
container type used to hold the images.
Definition: ImageManager.h:195
std::pair< Image *, ImageFactory * > ImagePair
One entry in the image container.
Definition: ImageManager.h:190
bool isImageTypeAvailable(const String &name) const
Return whether an Image subclass has been registered using the identifier name.
static const String & getImagesetDefaultResourceGroup()
Returns the default resource group currently set for Imagesets.
Definition: ImageManager.h:182
Interface for factory objects that create instances of classes derived from the Image class...
Definition: ImageFactory.h:43
Abstract XMLHandler based class.
Definition: ChainedXMLHandler.h:36
String class used within the GUI system.
Definition: String.h:62