• 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 
00012 namespace Gosu
00013 {
00015     class Image
00016     {
00017         boost::scoped_ptr<ImageData> data;
00018 
00019     public:
00025         Image(Graphics& graphics, const std::wstring& filename,
00026               bool tileable = false);
00032         Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
00033               unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00034               bool tileable = false);
00035         
00038         Image(Graphics& graphics, const Bitmap& source,
00039             bool tileable = false);
00042         Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
00043             unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00044             bool tileable = false);
00045 
00046         ~Image();
00047 
00048         unsigned width() const;
00049         unsigned height() const;
00050 
00052         void draw(double x, double y, ZPos z,
00053             double factorX = 1, double factorY = 1,
00054             Color c = Colors::white,
00055             AlphaMode mode = amDefault) const;
00058         void drawMod(double x, double y, ZPos z,
00059             double factorX, double factorY,
00060             Color c1, Color c2, Color c3, Color c4,
00061             AlphaMode mode = amDefault) const;
00062 
00072         void drawRot(double x, double y, ZPos z,
00073             double angle, double centerX = 0.5, double centerY = 0.5,
00074             double factorX = 1, double factorY = 1,
00075             Color c = Colors::white,
00076             AlphaMode mode = amDefault) const;
00077 
00078         #ifndef SWIG
00079         void drawRotFlip(double x, double y, ZPos z,
00080             RotFlip rf,
00081             double factorX = 1, double factorY = 1,
00082             Color c = Colors::white,
00083             AlphaMode mode = amDefault) const;
00084         void drawRotFlipMod(double x, double y, ZPos z,
00085             RotFlip rf,
00086             double factorX, double factorY,
00087             Color c1, Color c2, Color c3, Color c4,
00088             AlphaMode mode = amDefault) const;
00089 
00091         const ImageData& getData() const;
00092         #endif
00093     };
00094 
00103     template<typename Container>
00104     void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename,
00105         int tileWidth, int tileHeight, bool tileable, Container& appendTo)
00106     {
00107         imagesFromTiledBitmap(graphics, quickLoadBitmap(filename), tileWidth, tileHeight, tileable, appendTo);
00108     }
00109 
00118     template<typename Container>
00119     void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
00120         int tileWidth, int tileHeight, bool tileable, Container& appendTo)
00121     {
00122         int tilesX, tilesY;
00123 
00124         if (tileWidth > 0)
00125             tilesX = bmp.width() / tileWidth;
00126         else
00127         {
00128             tilesX = -tileWidth;
00129             tileWidth = bmp.width() / tilesX;
00130         }
00131         
00132         if (tileHeight > 0)
00133             tilesY = bmp.height() / tileHeight;
00134         else
00135         {
00136             tilesY = -tileHeight;
00137             tileHeight = bmp.height() / tilesY;
00138         }
00139         
00140         for (int y = 0; y < tilesY; ++y)
00141             for (int x = 0; x < tilesX; ++x)
00142                 appendTo.push_back(typename Container::value_type(new Image(graphics, bmp,
00143                     x * tileWidth, y * tileHeight, tileWidth, tileHeight,
00144                     tileable)));
00145     }
00146 }
00147 
00148 #endif

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