Image.hpp
Go to the documentation of this file.
1 
4 #ifndef GOSU_IMAGE_HPP
5 #define GOSU_IMAGE_HPP
6 
7 #include <Gosu/Fwd.hpp>
8 #include <Gosu/Color.hpp>
9 #include <Gosu/GraphicsBase.hpp>
10 #include <Gosu/TR1.hpp>
11 #include <memory>
12 #include <vector>
13 
14 namespace Gosu
15 {
17  class Image
18  {
19  std::tr1::shared_ptr<ImageData> data;
20 
21  public:
27  Image(Graphics& graphics, const std::wstring& filename,
28  bool tileable = false);
34  Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
35  unsigned srcY, unsigned srcWidth, unsigned srcHeight,
36  bool tileable = false);
37 
40  Image(Graphics& graphics, const Bitmap& source,
41  bool tileable = false);
44  Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
45  unsigned srcY, unsigned srcWidth, unsigned srcHeight,
46  bool tileable = false);
47 
49  explicit Image(GOSU_UNIQUE_PTR<ImageData> data);
50 
51  unsigned width() const;
52  unsigned height() const;
53 
55  void draw(double x, double y, ZPos z,
56  double factorX = 1, double factorY = 1,
57  Color c = Color::WHITE,
58  AlphaMode mode = amDefault) const;
61  void drawMod(double x, double y, ZPos z,
62  double factorX, double factorY,
63  Color c1, Color c2, Color c3, Color c4,
64  AlphaMode mode = amDefault) const;
65 
75  void drawRot(double x, double y, ZPos z,
76  double angle, double centerX = 0.5, double centerY = 0.5,
77  double factorX = 1, double factorY = 1,
78  Color c = Color::WHITE,
79  AlphaMode mode = amDefault) const;
80 
82  ImageData& getData() const;
83  };
84 
85  std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable);
86  std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable);
87 
96  template<typename Container>
97  void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo)
98  {
99  std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable);
100  for (int i = 0, num = tiles.size(); i < num; ++i)
101  appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
102  }
103 
112  template<typename Container>
113  void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
114  int tileWidth, int tileHeight, bool tileable, Container& appendTo)
115  {
116  std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, tileWidth, tileHeight, tileable);
117  for (int i = 0, num = tiles.size(); i < num; ++i)
118  appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
119  }
120 }
121 
122 #endif
std::vector< Gosu::Image > loadTiles(Graphics &graphics, const Bitmap &bmp, int tileWidth, int tileHeight, bool tileable)
void imagesFromTiledBitmap(Graphics &graphics, const std::wstring &filename, int tileWidth, int tileHeight, bool tileable, Container &appendTo)
Convenience function that splits a BMP or PNG file into an array of small rectangles and creates imag...
Definition: Image.hpp:97
Includes all parts of C++03 (TR1) that are relevant for Gosu.
void drawMod(double x, double y, ZPos z, double factorX, double factorY, Color c1, Color c2, Color c3, Color c4, AlphaMode mode=amDefault) const
Like draw(), but allows to give modulation colors for all four corners.
ImageData & getData() const
Provides access to the underlying image data object.
Contains declarations of all of Gosu&#39;s available classes.
void drawRot(double x, double y, ZPos z, double angle, double centerX=0.5, double centerY=0.5, double factorX=1, double factorY=1, Color c=Color::WHITE, AlphaMode mode=amDefault) const
Draws the image rotated by the given angle so that its rotation center is at (x; y).
Represents an RGBA color value with 8 bits for each channel.
Definition: Color.hpp:18
unsigned width() const
double ZPos
Represents the Z position of something drawn with Gosu&#39;s graphics system.
Rectangular area of pixels, each represented by a Color value.
Definition: Bitmap.hpp:20
unsigned height() const
The color&#39;s channels will be interpolated.
The ImageData class is an abstract base class for drawable images.
Definition: ImageData.hpp:28
Image(Graphics &graphics, const std::wstring &filename, bool tileable=false)
Loads an image from a given filename that can be drawn onto graphics.
Serves as the target of all drawing and provides primitive drawing functionality. ...
Definition: Graphics.hpp:49
AlphaMode
Determines the way colors are combined when one is drawn onto another.
Interface of the Color class.
Provides functionality for drawing rectangular images.
Definition: Image.hpp:17
static const Color WHITE
Definition: Color.hpp:150
void draw(double x, double y, ZPos z, double factorX=1, double factorY=1, Color c=Color::WHITE, AlphaMode mode=amDefault) const
Draws the image so its upper left corner is at (x; y).
double angle(double fromX, double fromY, double toX, double toY, double def=0)
Returns the angle from point 1 to point 2 in degrees, where 0.0 means upwards.
Contains general typedefs and enums related to graphics.