Crazy Eddies GUI System  0.6.2
CEGUIImageset.h
1 /***********************************************************************
2  filename: CEGUIImageset.h
3  created: 21/2/2004
4  author: Paul D Turner
5 
6  purpose: Defines the interface for the Imageset class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIImageset_h_
31 #define _CEGUIImageset_h_
32 
33 #include "CEGUIBase.h"
34 #include "CEGUIString.h"
35 #include "CEGUIRect.h"
36 #include "CEGUIColourRect.h"
37 #include "CEGUIImagesetManager.h"
38 #include "CEGUIImage.h"
39 #include "CEGUIIteratorBase.h"
40 #include "CEGUIXMLSerializer.h"
41 
42 #include <map>
43 
44 
45 #if defined(_MSC_VER)
46 # pragma warning(push)
47 # pragma warning(disable : 4251)
48 #endif
49 
50 
51 // Start of CEGUI namespace section
52 namespace CEGUI
53 {
54 
63 class CEGUIEXPORT Imageset
64 {
65  friend class Imageset_xmlHandler;
66 private:
67  typedef std::map<String, Image, String::FastLessCompare> ImageRegistry;
68 
69  /*************************************************************************
70  Friends to allow access to constructors and destructors
71  *************************************************************************/
72  friend Imageset* ImagesetManager::createImageset(const String& name, Texture* texture);
73  friend Imageset* ImagesetManager::createImageset(const String& filename, const String& resourceGroup);
74  friend Imageset* ImagesetManager::createImagesetFromImageFile(const String& name, const String& filename, const String& resourceGroup);
75  friend void ImagesetManager::destroyImageset(const String& name);
76 
77 
78  /*************************************************************************
79  Construction and Destruction (private, only ImagesetManager can
80  create and destroy Imageset objects).
81  *************************************************************************/
89  Imageset(const String& name, Texture* texture);
90 
91 
105  Imageset(const String& filename, const String& resourceGroup);
106 
107 
133  Imageset(const String& name, const String& filename, const String& resourceGroup);
134 
135 
136 public: // For luabind support
141  ~Imageset(void);
142 
143 
144 public:
146 
147  /*************************************************************************
148  Public interface
149  *************************************************************************/
157  Texture* getTexture(void) const {return d_texture;}
158 
159 
167  const String& getName(void) const {return d_name;}
168 
169 
177  uint getImageCount(void) const {return (uint)d_images.size();}
178 
179 
190  bool isImageDefined(const String& name) const {return d_images.find(name) != d_images.end();}
191 
192 
205  const Image& getImage(const String& name) const;
206 
207 
217  void undefineImage(const String& name);
218 
226  void undefineAllImages(void);
227 
228 
241  Size getImageSize(const String& name) const {return getImage(name).getSize();}
242 
243 
256  float getImageWidth(const String& name) const {return getImage(name).getWidth();}
257 
258 
271  float getImageHeight(const String& name) const {return getImage(name).getHeight();}
272 
273 
286  Point getImageOffset(const String& name) const {return getImage(name).getOffsets();}
287 
288 
301  float getImageOffsetX(const String& name) const {return getImage(name).getOffsetX();}
302 
303 
316  float getImageOffsetY(const String& name) const {return getImage(name).getOffsetY();}
317 
318 
340  void defineImage(const String& name, const Point& position, const Size& size, const Point& render_offset)
341  {
342  defineImage(name, Rect(position.d_x, position.d_y, position.d_x + size.d_width, position.d_y + size.d_height), render_offset);
343  }
344 
345 
364  void defineImage(const String& name, const Rect& image_rect, const Point& render_offset);
365 
366 
392  void draw(const Rect& source_rect, const Rect& dest_rect, float z, const Rect& clip_rect,const ColourRect& colours, QuadSplitMode quad_split_mode) const;
393 
394 
429  void draw(const Rect& source_rect, const Rect& dest_rect, float z, const Rect& clip_rect, const colour& top_left_colour = 0xFFFFFFFF, const colour& top_right_colour = 0xFFFFFFFF, const colour& bottom_left_colour = 0xFFFFFFFF, const colour& bottom_right_colour = 0xFFFFFFFF, QuadSplitMode quad_split_mode = TopLeftToBottomRight) const
430  {
431  draw(source_rect, dest_rect, z, clip_rect, ColourRect(top_left_colour, top_right_colour, bottom_left_colour, bottom_right_colour), quad_split_mode);
432  }
433 
434 
442  bool isAutoScaled(void) const {return d_autoScale;}
443 
444 
452  Size getNativeResolution(void) const {return Size(d_nativeHorzRes, d_nativeVertRes);}
453 
454 
465  void setAutoScalingEnabled(bool setting);
466 
467 
478  void setNativeResolution(const Size& size);
479 
480 
491  void notifyScreenResolution(const Size& size);
492 
493 
498  ImageIterator getIterator(void) const;
499 
500 
514  void writeXMLToStream(XMLSerializer& xml_stream) const;
515 
526  static void setDefaultResourceGroup(const String& resourceGroup)
527  { d_defaultResourceGroup = resourceGroup; }
528 
537  static const String& getDefaultResourceGroup()
538  { return d_defaultResourceGroup; }
539 
540 protected:
541  /*************************************************************************
542  Implementation Constants
543  *************************************************************************/
544  static const char ImagesetSchemaName[];
545 
546 
547  /*************************************************************************
548  Implementation Functions
549  *************************************************************************/
566  void load(const String& filename, const String& resourceGroup);
567 
568 
573  void unload(void);
574 
575 
588  void setTexture(Texture* texture);
589 
590 
598  void updateImageScalingFactors(void);
599 
600  /*************************************************************************
601  Implementation Data
602  *************************************************************************/
604  ImageRegistry d_images;
607 
608  // auto-scaling fields
609  bool d_autoScale;
615 };
616 
617 } // End of CEGUI namespace section
618 
619 #if defined(_MSC_VER)
620 # pragma warning(pop)
621 #endif
622 
623 #endif // end of guard _CEGUIImageset_h_