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/TR1.hpp> 00010 #include <memory> 00011 00012 namespace Gosu 00013 { 00015 class Image 00016 { 00017 std::tr1::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 Bitmap bmp; 00096 loadImageFile(bmp, filename); 00097 imagesFromTiledBitmap(graphics, bmp, tileWidth, tileHeight, tileable, appendTo); 00098 } 00099 00108 template<typename Container> 00109 void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp, 00110 int tileWidth, int tileHeight, bool tileable, Container& appendTo) 00111 { 00112 int tilesX, tilesY; 00113 00114 if (tileWidth > 0) 00115 tilesX = bmp.width() / tileWidth; 00116 else 00117 { 00118 tilesX = -tileWidth; 00119 tileWidth = bmp.width() / tilesX; 00120 } 00121 00122 if (tileHeight > 0) 00123 tilesY = bmp.height() / tileHeight; 00124 else 00125 { 00126 tilesY = -tileHeight; 00127 tileHeight = bmp.height() / tilesY; 00128 } 00129 00130 for (int y = 0; y < tilesY; ++y) 00131 for (int x = 0; x < tilesX; ++x) 00132 appendTo.push_back(typename Container::value_type(new Image(graphics, bmp, 00133 x * tileWidth, y * tileHeight, tileWidth, tileHeight, 00134 tileable))); 00135 } 00136 } 00137 00138 #endif