Gosu
Image.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <Gosu/Fwd.hpp>
7 #include <Gosu/Color.hpp>
8 #include <Gosu/GraphicsBase.hpp>
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 namespace Gosu
14 {
16  class Image
17  {
18  std::shared_ptr<ImageData> data_;
19 
20  public:
22  Image();
23 
28  explicit Image(const std::string& filename, unsigned image_flags = IF_SMOOTH);
29 
34  Image(const std::string& filename, int src_x, int src_y,
35  int src_width, int src_height, unsigned image_flags = IF_SMOOTH);
36 
38  explicit Image(const Bitmap& source, unsigned image_flags = IF_SMOOTH);
39 
41  Image(const Bitmap& source, int src_x, int src_y, int src_width,
42  int src_height, unsigned image_flags = IF_SMOOTH);
43 
45  explicit Image(std::unique_ptr<ImageData>&& data);
46 
47  unsigned width() const;
48  unsigned height() const;
49 
51  void draw(double x, double y, ZPos z = 0, double scale_x = 1, double scale_y = 1,
52  Color c = Color::WHITE, AlphaMode mode = AM_DEFAULT) const;
54  void draw_mod(double x, double y, ZPos z, double scale_x, double scale_y,
55  Color c1, Color c2, Color c3, Color c4, AlphaMode mode = AM_DEFAULT) const;
56 
66  void draw_rot(double x, double y, ZPos z = 0, double angle = 0,
67  double center_x = 0.5, double center_y = 0.5, double scale_x = 1, double scale_y = 1,
68  Color c = Color::WHITE, AlphaMode mode = AM_DEFAULT) const;
69 
70  #ifndef SWIG
71  ImageData& data() const;
73  #endif
74  };
75 
76  #ifndef SWIG
77  std::vector<Gosu::Image> load_tiles(const Bitmap& bmp,
82  int tile_width, int tile_height, unsigned image_flags = IF_SMOOTH);
83 
88  std::vector<Gosu::Image> load_tiles(const std::string& filename,
89  int tile_width, int tile_height, unsigned image_flags = IF_SMOOTH);
90  #endif
91 }
Definition: Audio.hpp:12
Represents an RGBA color value with 8 bits for each channel.
Definition: Color.hpp:16
void draw_rot(double x, double y, ZPos z=0, double angle=0, double center_x=0.5, double center_y=0.5, double scale_x=1, double scale_y=1, Color c=Color::WHITE, AlphaMode mode=AM_DEFAULT) const
Draws the image rotated by the given angle so that its rotation center is at (x; y).
std::vector< Gosu::Image > load_tiles(const Bitmap &bmp, int tile_width, int tile_height, unsigned image_flags=IF_SMOOTH)
Convenience function that slices an image file into a grid and creates images from them...
unsigned height() const
double ZPos
Represents the Z position of something drawn with Gosu&#39;s graphics system.
A two-dimensional array area of pixels, each represented by a Color value.
Definition: Bitmap.hpp:14
double angle(double from_x, double from_y, double to_x, double to_y, double def=0)
Returns the angle from point 1 to point 2 in degrees, where 0.0 means upwards.
The ImageData class is an abstract base class for drawable images.
Definition: ImageData.hpp:28
AlphaMode
Determines the way colors are combined when one is drawn onto another.
ImageData & data() const
Provides access to the underlying image data object.
Interface of the Color class.
Provides functionality for drawing rectangular images.
Definition: Image.hpp:16
void draw_mod(double x, double y, ZPos z, double scale_x, double scale_y, Color c1, Color c2, Color c3, Color c4, AlphaMode mode=AM_DEFAULT) const
Like draw(), but with modulation colors for all four corners.
void draw(double x, double y, ZPos z=0, double scale_x=1, double scale_y=1, Color c=Color::WHITE, AlphaMode mode=AM_DEFAULT) const
Draws the image so its upper left corner is at (x; y).
unsigned width() const
static const Color WHITE
Definition: Color.hpp:136
Image()
Creates an empty image. It will have a width and height of 0, and not contain anything.
Contains general typedefs and enums related to graphics.