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 <boost/shared_ptr.hpp> 00010 #include <memory> 00011 00012 namespace Gosu 00013 { 00015 class Image 00016 { 00017 boost::shared_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 00047 explicit Image(std::auto_ptr<ImageData> data); 00048 00049 unsigned width() const; 00050 unsigned height() const; 00051 00053 void draw(double x, double y, ZPos z, 00054 double factorX = 1, double factorY = 1, 00055 Color c = Color::WHITE, 00056 AlphaMode mode = amDefault) const; 00059 void drawMod(double x, double y, ZPos z, 00060 double factorX, double factorY, 00061 Color c1, Color c2, Color c3, Color c4, 00062 AlphaMode mode = amDefault) const; 00063 00073 void drawRot(double x, double y, ZPos z, 00074 double angle, double centerX = 0.5, double centerY = 0.5, 00075 double factorX = 1, double factorY = 1, 00076 Color c = Color::WHITE, 00077 AlphaMode mode = amDefault) const; 00078 00080 ImageData& getData() const; 00081 }; 00082 00091 template<typename Container> 00092 void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, 00093 int tileWidth, int tileHeight, bool tileable, Container& appendTo) 00094 { 00095 imagesFromTiledBitmap(graphics, loadImageFile(filename), tileWidth, tileHeight, tileable, appendTo); 00096 } 00097 00106 template<typename Container> 00107 void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp, 00108 int tileWidth, int tileHeight, bool tileable, Container& appendTo) 00109 { 00110 int tilesX, tilesY; 00111 00112 if (tileWidth > 0) 00113 tilesX = bmp.width() / tileWidth; 00114 else 00115 { 00116 tilesX = -tileWidth; 00117 tileWidth = bmp.width() / tilesX; 00118 } 00119 00120 if (tileHeight > 0) 00121 tilesY = bmp.height() / tileHeight; 00122 else 00123 { 00124 tilesY = -tileHeight; 00125 tileHeight = bmp.height() / tilesY; 00126 } 00127 00128 for (int y = 0; y < tilesY; ++y) 00129 for (int x = 0; x < tilesX; ++x) 00130 appendTo.push_back(typename Container::value_type(new Image(graphics, bmp, 00131 x * tileWidth, y * tileHeight, tileWidth, tileHeight, 00132 tileable))); 00133 } 00134 } 00135 00136 #endif
Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!