00001 00002 00003 00004 #ifndef GOSU_IMAGE_HPP 00005 #define GOSU_IMAGE_HPP 00006 00007 #include <Gosu/Fwd.hpp> 00008 #include <Gosu/Color.hpp> 00009 #include <Gosu/GraphicsBase.hpp> 00010 #include <Gosu/TR1.hpp> 00011 #include <memory> 00012 #include <vector> 00013 00014 namespace Gosu 00015 { 00017 class Image 00018 { 00019 std::tr1::shared_ptr<ImageData> data; 00020 00021 public: 00027 Image(Graphics& graphics, const std::wstring& filename, 00028 bool tileable = false); 00034 Image(Graphics& graphics, const std::wstring& filename, unsigned srcX, 00035 unsigned srcY, unsigned srcWidth, unsigned srcHeight, 00036 bool tileable = false); 00037 00040 Image(Graphics& graphics, const Bitmap& source, 00041 bool tileable = false); 00044 Image(Graphics& graphics, const Bitmap& source, unsigned srcX, 00045 unsigned srcY, unsigned srcWidth, unsigned srcHeight, 00046 bool tileable = false); 00047 00049 explicit Image(std::auto_ptr<ImageData> data); 00050 00051 unsigned width() const; 00052 unsigned height() const; 00053 00055 void draw(double x, double y, ZPos z, 00056 double factorX = 1, double factorY = 1, 00057 Color c = Color::WHITE, 00058 AlphaMode mode = amDefault) const; 00061 void drawMod(double x, double y, ZPos z, 00062 double factorX, double factorY, 00063 Color c1, Color c2, Color c3, Color c4, 00064 AlphaMode mode = amDefault) const; 00065 00075 void drawRot(double x, double y, ZPos z, 00076 double angle, double centerX = 0.5, double centerY = 0.5, 00077 double factorX = 1, double factorY = 1, 00078 Color c = Color::WHITE, 00079 AlphaMode mode = amDefault) const; 00080 00082 ImageData& getData() const; 00083 }; 00084 00085 std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable); 00086 std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable); 00087 00096 template<typename Container> 00097 void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo) 00098 { 00099 std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable); 00100 for (int i = 0, num = tiles.size(); i < num; ++i) 00101 appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i]))); 00102 } 00103 00112 template<typename Container> 00113 void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp, 00114 int tileWidth, int tileHeight, bool tileable, Container& appendTo) 00115 { 00116 std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, tileWidth, tileHeight, tileable); 00117 for (int i = 0, num = tiles.size(); i < num; ++i) 00118 appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i]))); 00119 } 00120 } 00121 00122 #endif