raylib-cpp
C++ object-oriented wrapper library for raylib.
Image.hpp
1 #ifndef RAYLIB_CPP_IMAGE_HPP_
2 #define RAYLIB_CPP_IMAGE_HPP_
3 
4 #include <string>
5 #ifdef __cplusplus
6 extern "C"{
7 #endif
8 #include "raylib.h"
9 #ifdef __cplusplus
10 }
11 #endif
12 
13 #include "./raylib-cpp-utils.hpp"
14 
15 namespace raylib {
16  class Image : public ::Image {
17  public:
18  Image() {};
19  Image(::Image image) {
20  set(image);
21  }
22  Image(const std::string& fileName) {
23  Load(fileName);
24  }
25  Image(const std::string& fileName, int width, int height, int format, int headerSize) {
26  LoadRaw(fileName, width, height, format, headerSize);
27  }
28  Image(const std::string& fileName, int* frames) {
29  LoadAnim(fileName, frames);
30  }
31  Image(::Texture2D texture) {
32  set(::GetTextureData(texture));
33  }
34  Image(int width, int height, Color color = WHITE) {
35  set(::GenImageColor(width, height, color));
36  }
37 
38  static Image Text(std::string text, int fontSize, Color color) {
39  return ::ImageText(text.c_str(), fontSize, color);
40  }
41 
42  static Image Text(Font font, std::string text, float fontSize, float spacing, Color tint) {
43  return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
44  }
45 
46  static Image GetScreenData() {
47  return Image(::GetScreenData());
48  }
49 
50  static Image GenColor(int width, int height, Color color) {
51  return ::GenImageColor(width, height, color);
52  }
53 
54  static Image GenGradientV(int width, int height, Color top, Color bottom) {
55  return ::GenImageGradientV(width, height, top, bottom);
56  }
57 
58  static Image GenGradientH(int width, int height, Color left, Color right) {
59  return ::GenImageGradientH(width, height, left, right);
60  }
61 
62  static Image GenGradientRadial(int width, int height, float density, Color inner, Color outer) {
63  return ::GenImageGradientRadial(width, height, density, inner, outer);
64  }
65 
66  static Image GenChecked(int width, int height, int checksX, int checksY, Color col1, Color col2) {
67  return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
68  }
69 
70  static Image GenWhiteNoise(int width, int height, float factor) {
71  return ::GenImageWhiteNoise(width, height, factor);
72  }
73 
74  static Image GenPerlinNoise(int width, int height, int offsetX, int offsetY, float scale) {
75  return ::GenImagePerlinNoise(width, height, offsetX, offsetY, scale);
76  }
77 
78  static Image GenCellular(int width, int height, int tileSize) {
79  return ::GenImageCellular(width, height, tileSize);
80  }
81 
82  ~Image() {
83  Unload();
84  };
85 
86  Image& operator=(const ::Image& image) {
87  set(image);
88  return *this;
89  }
90 
91  Image& operator=(const Image& image) {
92  set(image);
93  return *this;
94  }
95 
96  inline void set(::Image image) {
97  data = image.data;
98  width = image.width;
99  height = image.height;
100  mipmaps = image.mipmaps;
101  format = image.format;
102  }
103 
104  void Load(const std::string& fileName) {
105  set(::LoadImage(fileName.c_str()));
106  }
107 
108  void LoadRaw(const std::string& fileName, int width, int height, int format, int headerSize) {
109  set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
110  }
111 
112  void LoadAnim(const std::string& fileName, int* frames) {
113  set(::LoadImageAnim(fileName.c_str(), frames));
114  }
115 
116  inline void Unload() {
117  ::UnloadImage(*this);
118  };
119 
120  inline Image& Export(const std::string& fileName) {
121  ::ExportImage(*this, fileName.c_str());
122  return *this;
123  }
124  inline Image& ExportAsCode(const std::string& fileName) {
125  ::ExportImageAsCode(*this, fileName.c_str());
126  return *this;
127  }
128 
129  GETTERSETTER(void*,Data,data)
130  GETTERSETTER(int,Width,width)
131  GETTERSETTER(int,Height,height)
132  GETTERSETTER(int,Mipmaps,mipmaps)
133  GETTERSETTER(int,Format,format)
134 
135  inline Image Copy() {
136  return ::ImageCopy(*this);
137  }
138  inline Image FromImage(::Rectangle rec) {
139  return ::ImageFromImage(*this, rec);
140  }
141 
142  inline Image& ToPOT(Color fillColor) {
143  ::ImageToPOT(this, fillColor);
144  return *this;
145  }
146 
147  inline Image& Format(int newFormat) {
148  ::ImageFormat(this, newFormat);
149  return *this;
150  }
151 
152  inline Image& AlphaMask(Image alphaMask) {
153  ::ImageAlphaMask(this, alphaMask);
154  return *this;
155  }
156 
157  inline Image& AlphaCrop(float threshold) {
158  ::ImageAlphaCrop(this, threshold);
159  return *this;
160  }
161 
163  ::ImageAlphaPremultiply(this);
164  return *this;
165  }
166 
167  inline Image& Crop(::Rectangle crop) {
168  ::ImageCrop(this, crop);
169  return *this;
170  }
171  inline Image& Crop(int offsetX, int offsetY, int newWidth, int newHeight) {
172  ::ImageCrop(this, (Rectangle){ (float)offsetX, (float)offsetY, (float)newWidth, (float)newHeight });
173  return *this;
174  }
175 
176  inline Image& Resize(int newWidth, int newHeight) {
177  ::ImageResize(this, newWidth, newHeight);
178  return *this;
179  }
180  inline Image& ResizeNN(int newWidth, int newHeight) {
181  ::ImageResizeNN(this, newWidth, newHeight);
182  return *this;
183  }
184 
185  inline Image& ResizeCanvas(int newWidth, int newHeight, int offsetX, int offsetY, Color color) {
186  ::ImageResizeCanvas(this, newWidth, newHeight, offsetX, offsetY, color);
187  return *this;
188  }
189 
190  inline Image& Mipmaps() {
191  ::ImageMipmaps(this);
192  return *this;
193  }
194 
195  inline Image& Dither(int rBpp, int gBpp, int bBpp, int aBpp) {
196  ::ImageDither(this, rBpp, gBpp, bBpp, aBpp);
197  return *this;
198  }
199 
200  inline Image& FlipVertical() {
201  ::ImageFlipVertical(this);
202  return *this;
203  }
204  inline Image& FlipHorizontal() {
205  ::ImageFlipHorizontal(this);
206  return *this;
207  }
208 
209  inline Image& RotateCW() {
210  ::ImageRotateCW(this);
211  return *this;
212  }
213 
214  inline Image& RotateCCW() {
215  ::ImageRotateCCW(this);
216  return *this;
217  }
218 
219  inline Image& ColorTint(::Color color = WHITE) {
220  ::ImageColorTint(this, color);
221  return *this;
222  }
223 
224  inline Image& ColorInvert() {
225  ::ImageColorInvert(this);
226  return *this;
227  }
228 
229  inline Image& ColorGrayscale() {
230  ::ImageColorGrayscale(this);
231  return *this;
232  }
233  inline Image& ColorContrast(float contrast) {
234  ::ImageColorContrast(this, contrast);
235  return *this;
236  }
237  inline Image& ColorBrightness(int brightness) {
238  ::ImageColorBrightness(this, brightness);
239  return *this;
240  }
241  inline Image& ColorReplace(::Color color, ::Color replace) {
242  ::ImageColorReplace(this, color, replace);
243  return *this;
244  }
245 
246  inline ::Color* GetPalette(int maxPaletteSize, int *extractCount) {
247  return ::GetImagePalette(*this, maxPaletteSize, extractCount);
248  }
249 
250  inline Rectangle GetAlphaBorder(float threshold) {
251  return ::GetImageAlphaBorder(*this, threshold);
252  }
253 
254  inline Image& ClearBackground(::Color color = WHITE) {
255  ::ImageClearBackground(this, color);
256  return *this;
257  }
258 
259  inline Image& DrawPixel(int posX, int posY, ::Color color) {
260  ::ImageDrawPixel(this, posX, posY, color);
261  return *this;
262  }
263 
264  inline Image& DrawPixel(::Vector2 position, ::Color color) {
265  ::ImageDrawPixelV(this, position, color);
266  return *this;
267  }
268 
269  inline Image& DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color) {
270  ::ImageDrawLine(this, startPosX, startPosY, endPosX, endPosY, color);
271  return *this;
272  }
273 
274  inline Image& DrawLine(::Vector2 start, ::Vector2 end, ::Color color) {
275  ::ImageDrawLineV(this, start, end, color);
276  return *this;
277  }
278 
279  inline Image& DrawCircle(int centerX, int centerY, int radius, ::Color color) {
280  ::ImageDrawCircle(this, centerX, centerY, radius, color);
281  return *this;
282  }
283 
284  inline Image& DrawCircle(::Vector2 center, int radius, ::Color color) {
285  ::ImageDrawCircleV(this, center, radius, color);
286  return *this;
287  }
288  inline Image& DrawRectangle(int posX, int posY, int width, int height, ::Color color = WHITE) {
289  ::ImageDrawRectangle(this, posX, posY, width, height, color);
290  return *this;
291  }
292  inline Image& DrawRectangle(Vector2 position, Vector2 size, ::Color color = WHITE) {
293  ::ImageDrawRectangleV(this, position, size, color);
294  return *this;
295  }
296  inline Image& DrawRectangle(::Rectangle rec, ::Color color = WHITE) {
297  ::ImageDrawRectangleRec(this, rec, color);
298  return *this;
299  }
300  inline Image& DrawRectangleLines(::Rectangle rec, int thick, ::Color color) {
301  ::ImageDrawRectangleLines(this, rec, thick, color);
302  return *this;
303  }
304  inline Image& Draw(::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint = WHITE) {
305  ::ImageDraw(this, src, srcRec, dstRec, tint);
306  return *this;
307  }
308 
309  inline Image& DrawText(const std::string& text, ::Vector2 position, int fontSize, ::Color color = WHITE){
310  ::ImageDrawText(this, text.c_str(), (int)position.x, (int)position.y, fontSize, color);
311  return *this;
312  }
313  inline Image& DrawText(const std::string& text, int x, int y, int fontSize, ::Color color = WHITE){
314  ::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
315  return *this;
316  }
317  inline Image& DrawText(::Font font, const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE){
318  ::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
319  return *this;
320  }
321 
322  inline ::Color* GetImageData() {
323  return ::GetImageData(*this);
324  }
325 
326  inline ::Vector4* GetImageDataNormalized() {
327  return ::GetImageDataNormalized(*this);
328  }
329  inline operator Texture2D() {
330  return ::LoadTextureFromImage(*this);
331  }
332  };
333 }
334 
335 #endif
raylib::Image::Dither
Image & Dither(int rBpp, int gBpp, int bBpp, int aBpp)
Definition: Image.hpp:195
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:14
raylib::Image::DrawRectangle
Image & DrawRectangle(Vector2 position, Vector2 size, ::Color color=WHITE)
Definition: Image.hpp:292
raylib::Image::ColorBrightness
Image & ColorBrightness(int brightness)
Definition: Image.hpp:237
raylib::Image::set
void set(::Image image)
Definition: Image.hpp:96
raylib::Image::Image
Image(::Texture2D texture)
Definition: Image.hpp:31
raylib::Image::~Image
~Image()
Definition: Image.hpp:82
raylib::Image::GetImageData
inline ::Color * GetImageData()
Definition: Image.hpp:322
raylib::Image::Format
Image & Format(int newFormat)
Definition: Image.hpp:147
raylib::Image::GenGradientV
static Image GenGradientV(int width, int height, Color top, Color bottom)
Definition: Image.hpp:54
raylib::Image::GetPalette
inline ::Color * GetPalette(int maxPaletteSize, int *extractCount)
Definition: Image.hpp:246
raylib::Image::DrawText
Image & DrawText(const std::string &text, ::Vector2 position, int fontSize, ::Color color=WHITE)
Definition: Image.hpp:309
raylib::Image::ColorInvert
Image & ColorInvert()
Definition: Image.hpp:224
raylib::Image::ToPOT
Image & ToPOT(Color fillColor)
Definition: Image.hpp:142
raylib::Image::ColorGrayscale
Image & ColorGrayscale()
Definition: Image.hpp:229
raylib::Image
Definition: Image.hpp:16
raylib::Image::Crop
Image & Crop(::Rectangle crop)
Definition: Image.hpp:167
raylib::Image::ExportAsCode
Image & ExportAsCode(const std::string &fileName)
Definition: Image.hpp:124
raylib::Image::Image
Image(const std::string &fileName)
Definition: Image.hpp:22
raylib::Image::GetImageDataNormalized
inline ::Vector4 * GetImageDataNormalized()
Definition: Image.hpp:326
raylib::Image::Image
Image(::Image image)
Definition: Image.hpp:19
raylib::Image::GenGradientH
static Image GenGradientH(int width, int height, Color left, Color right)
Definition: Image.hpp:58
raylib::Image::GenWhiteNoise
static Image GenWhiteNoise(int width, int height, float factor)
Definition: Image.hpp:70
raylib::Image::RotateCCW
Image & RotateCCW()
Definition: Image.hpp:214
raylib::Image::DrawLine
Image & DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color)
Definition: Image.hpp:269
raylib::Image::DrawPixel
Image & DrawPixel(int posX, int posY, ::Color color)
Definition: Image.hpp:259
raylib::Image::DrawRectangle
Image & DrawRectangle(int posX, int posY, int width, int height, ::Color color=WHITE)
Definition: Image.hpp:288
raylib::Image::FlipVertical
Image & FlipVertical()
Definition: Image.hpp:200
raylib::Image::ColorContrast
Image & ColorContrast(float contrast)
Definition: Image.hpp:233
raylib::Image::DrawRectangleLines
Image & DrawRectangleLines(::Rectangle rec, int thick, ::Color color)
Definition: Image.hpp:300
raylib::Image::ClearBackground
Image & ClearBackground(::Color color=WHITE)
Definition: Image.hpp:254
raylib::Image::DrawCircle
Image & DrawCircle(::Vector2 center, int radius, ::Color color)
Definition: Image.hpp:284
raylib::Image::LoadRaw
void LoadRaw(const std::string &fileName, int width, int height, int format, int headerSize)
Definition: Image.hpp:108
raylib::Image::operator=
Image & operator=(const ::Image &image)
Definition: Image.hpp:86
raylib::Image::AlphaPremultiply
Image & AlphaPremultiply()
Definition: Image.hpp:162
raylib::Image::Crop
Image & Crop(int offsetX, int offsetY, int newWidth, int newHeight)
Definition: Image.hpp:171
raylib::Image::GetScreenData
static Image GetScreenData()
Definition: Image.hpp:46
raylib::Image::DrawText
Image & DrawText(::Font font, const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE)
Definition: Image.hpp:317
raylib::Image::Mipmaps
Image & Mipmaps()
Definition: Image.hpp:190
raylib::Image::Image
Image(const std::string &fileName, int width, int height, int format, int headerSize)
Definition: Image.hpp:25
raylib::Image::DrawPixel
Image & DrawPixel(::Vector2 position, ::Color color)
Definition: Image.hpp:264
raylib::Rectangle
Definition: Rectangle.hpp:16
raylib::Font
Definition: Font.hpp:17
raylib::Vector2
Definition: Vector2.hpp:22
raylib::Image::Text
static Image Text(std::string text, int fontSize, Color color)
Definition: Image.hpp:38
raylib::Color
Definition: Color.hpp:18
raylib::Image::GenGradientRadial
static Image GenGradientRadial(int width, int height, float density, Color inner, Color outer)
Definition: Image.hpp:62
raylib::Image::GenPerlinNoise
static Image GenPerlinNoise(int width, int height, int offsetX, int offsetY, float scale)
Definition: Image.hpp:74
raylib::Image::LoadAnim
void LoadAnim(const std::string &fileName, int *frames)
Definition: Image.hpp:112
raylib::Image::AlphaMask
Image & AlphaMask(Image alphaMask)
Definition: Image.hpp:152
raylib::Image::Load
void Load(const std::string &fileName)
Definition: Image.hpp:104
raylib::Image::Image
Image(const std::string &fileName, int *frames)
Definition: Image.hpp:28
raylib::Image::DrawText
Image & DrawText(const std::string &text, int x, int y, int fontSize, ::Color color=WHITE)
Definition: Image.hpp:313
raylib::Image::ColorTint
Image & ColorTint(::Color color=WHITE)
Definition: Image.hpp:219
raylib::Image::GetAlphaBorder
Rectangle GetAlphaBorder(float threshold)
Definition: Image.hpp:250
raylib::Image::AlphaCrop
Image & AlphaCrop(float threshold)
Definition: Image.hpp:157
raylib::Image::Resize
Image & Resize(int newWidth, int newHeight)
Definition: Image.hpp:176
raylib::Image::GenCellular
static Image GenCellular(int width, int height, int tileSize)
Definition: Image.hpp:78
raylib::Image::Copy
Image Copy()
Definition: Image.hpp:135
raylib::Image::ResizeCanvas
Image & ResizeCanvas(int newWidth, int newHeight, int offsetX, int offsetY, Color color)
Definition: Image.hpp:185
raylib::Image::Unload
void Unload()
Definition: Image.hpp:116
raylib::Image::FlipHorizontal
Image & FlipHorizontal()
Definition: Image.hpp:204
raylib::Image::DrawCircle
Image & DrawCircle(int centerX, int centerY, int radius, ::Color color)
Definition: Image.hpp:279
raylib::Image::ResizeNN
Image & ResizeNN(int newWidth, int newHeight)
Definition: Image.hpp:180
raylib::Image::Image
Image(int width, int height, Color color=WHITE)
Definition: Image.hpp:34
raylib::Image::operator=
Image & operator=(const Image &image)
Definition: Image.hpp:91
raylib::Image::Export
Image & Export(const std::string &fileName)
Definition: Image.hpp:120
raylib::Image::GenChecked
static Image GenChecked(int width, int height, int checksX, int checksY, Color col1, Color col2)
Definition: Image.hpp:66
raylib::Image::RotateCW
Image & RotateCW()
Definition: Image.hpp:209
raylib::Texture2D
Definition: Texture2D.hpp:19
raylib::Image::Image
Image()
Definition: Image.hpp:18
raylib::Image::Text
static Image Text(Font font, std::string text, float fontSize, float spacing, Color tint)
Definition: Image.hpp:42
raylib::Image::Draw
Image & Draw(::Image &src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint=WHITE)
Definition: Image.hpp:304
raylib::Image::DrawLine
Image & DrawLine(::Vector2 start, ::Vector2 end, ::Color color)
Definition: Image.hpp:274
raylib::Image::ColorReplace
Image & ColorReplace(::Color color, ::Color replace)
Definition: Image.hpp:241
raylib::Image::DrawRectangle
Image & DrawRectangle(::Rectangle rec, ::Color color=WHITE)
Definition: Image.hpp:296
raylib::Image::FromImage
Image FromImage(::Rectangle rec)
Definition: Image.hpp:138
raylib::Image::GenColor
static Image GenColor(int width, int height, Color color)
Definition: Image.hpp:50