• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Image.hpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 #ifndef GOSU_IMAGE_HPP
00005 #define GOSU_IMAGE_HPP
00006 
00007 #include <Gosu/Fwd.hpp>
00008 #include <Gosu/Bitmap.hpp>
00009 #include <Gosu/RotFlip.hpp>
00010 #include <boost/scoped_ptr.hpp>
00011 #include <memory>
00012 
00013 namespace Gosu
00014 {
00016     class Image
00017     {
00018         boost::scoped_ptr<ImageData> data;
00019 
00020     public:
00026         Image(Graphics& graphics, const std::wstring& filename,
00027               bool tileable = false);
00033         Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
00034               unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00035               bool tileable = false);
00036         
00039         Image(Graphics& graphics, const Bitmap& source,
00040             bool tileable = false);
00043         Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
00044             unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00045             bool tileable = false);
00046         
00048         explicit Image(std::auto_ptr<ImageData> data);
00049 
00050         ~Image();
00051         
00052         unsigned width() const;
00053         unsigned height() const;
00054 
00056         void draw(double x, double y, ZPos z,
00057             double factorX = 1, double factorY = 1,
00058             Color c = Color::WHITE,
00059             AlphaMode mode = amDefault) const;
00062         void drawMod(double x, double y, ZPos z,
00063             double factorX, double factorY,
00064             Color c1, Color c2, Color c3, Color c4,
00065             AlphaMode mode = amDefault) const;
00066 
00076         void drawRot(double x, double y, ZPos z,
00077             double angle, double centerX = 0.5, double centerY = 0.5,
00078             double factorX = 1, double factorY = 1,
00079             Color c = Color::WHITE,
00080             AlphaMode mode = amDefault) const;
00081 
00082         #ifndef SWIG
00083         void drawRotFlip(double x, double y, ZPos z,
00084             RotFlip rf,
00085             double factorX = 1, double factorY = 1,
00086             Color c = Color::WHITE,
00087             AlphaMode mode = amDefault) const;
00088         void drawRotFlipMod(double x, double y, ZPos z,
00089             RotFlip rf,
00090             double factorX, double factorY,
00091             Color c1, Color c2, Color c3, Color c4,
00092             AlphaMode mode = amDefault) const;
00093 
00095         const ImageData& getData() const;
00096         #endif
00097     };
00098 
00107     template<typename Container>
00108     void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename,
00109         int tileWidth, int tileHeight, bool tileable, Container& appendTo)
00110     {
00111         imagesFromTiledBitmap(graphics, quickLoadBitmap(filename), tileWidth, tileHeight, tileable, appendTo);
00112     }
00113 
00122     template<typename Container>
00123     void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
00124         int tileWidth, int tileHeight, bool tileable, Container& appendTo)
00125     {
00126         int tilesX, tilesY;
00127 
00128         if (tileWidth > 0)
00129             tilesX = bmp.width() / tileWidth;
00130         else
00131         {
00132             tilesX = -tileWidth;
00133             tileWidth = bmp.width() / tilesX;
00134         }
00135         
00136         if (tileHeight > 0)
00137             tilesY = bmp.height() / tileHeight;
00138         else
00139         {
00140             tilesY = -tileHeight;
00141             tileHeight = bmp.height() / tilesY;
00142         }
00143         
00144         for (int y = 0; y < tilesY; ++y)
00145             for (int x = 0; x < tilesX; ++x)
00146                 appendTo.push_back(typename Container::value_type(new Image(graphics, bmp,
00147                     x * tileWidth, y * tileHeight, tileWidth, tileHeight,
00148                     tileable)));
00149     }
00150 }
00151 
00152 #endif

Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!