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& Resize(int newWidth, int newHeight) {
172  ::ImageResize(this, newWidth, newHeight);
173  return *this;
174  }
175  inline Image& ResizeNN(int newWidth, int newHeight) {
176  ::ImageResizeNN(this, newWidth, newHeight);
177  return *this;
178  }
179  inline Image& ResizeCanvas(int newWidth, int newHeight, int offsetX, int offsetY, Color color) {
180  ::ImageResizeCanvas(this, newWidth, newHeight, offsetX, offsetY, color);
181  return *this;
182  }
183  inline Image& Mipmaps() {
184  ::ImageMipmaps(this);
185  return *this;
186  }
187  inline Image& Dither(int rBpp, int gBpp, int bBpp, int aBpp) {
188  ::ImageDither(this, rBpp, gBpp, bBpp, aBpp);
189  return *this;
190  }
191 
192  inline Image& FlipVertical() {
193  ::ImageFlipVertical(this);
194  return *this;
195  }
196  inline Image& FlipHorizontal() {
197  ::ImageFlipHorizontal(this);
198  return *this;
199  }
200 
201  inline Image& RotateCW() {
202  ::ImageRotateCW(this);
203  return *this;
204  }
205  inline Image& RotateCCW() {
206  ::ImageRotateCCW(this);
207  return *this;
208  }
209  inline Image& ColorTint(::Color color = WHITE) {
210  ::ImageColorTint(this, color);
211  return *this;
212  }
213  inline Image& ColorInvert() {
214  ::ImageColorInvert(this);
215  return *this;
216  }
217  inline Image& ColorGrayscale() {
218  ::ImageColorGrayscale(this);
219  return *this;
220  }
221  inline Image& ColorContrast(float contrast) {
222  ::ImageColorContrast(this, contrast);
223  return *this;
224  }
225  inline Image& ColorBrightness(int brightness) {
226  ::ImageColorBrightness(this, brightness);
227  return *this;
228  }
229  inline Image& ColorReplace(::Color color, ::Color replace) {
230  ::ImageColorReplace(this, color, replace);
231  return *this;
232  }
233 
234  inline ::Color* GetPalette(int maxPaletteSize, int *extractCount) {
235  return ::GetImagePalette(*this, maxPaletteSize, extractCount);
236  }
237 
238  inline Rectangle GetAlphaBorder(float threshold) {
239  return ::GetImageAlphaBorder(*this, threshold);
240  }
241 
242  inline Image& ClearBackground(::Color color = WHITE) {
243  ::ImageClearBackground(this, color);
244  return *this;
245  }
246 
247  inline Image& DrawPixel(int posX, int posY, ::Color color) {
248  ::ImageDrawPixel(this, posX, posY, color);
249  return *this;
250  }
251 
252  inline Image& DrawPixel(::Vector2 position, ::Color color) {
253  ::ImageDrawPixelV(this, position, color);
254  return *this;
255  }
256 
257  inline Image& DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color) {
258  ::ImageDrawLine(this, startPosX, startPosY, endPosX, endPosY, color);
259  return *this;
260  }
261 
262  inline Image& DrawLine(::Vector2 start, ::Vector2 end, ::Color color) {
263  ::ImageDrawLineV(this, start, end, color);
264  return *this;
265  }
266 
267  inline Image& DrawCircle(int centerX, int centerY, int radius, ::Color color) {
268  ::ImageDrawCircle(this, centerX, centerY, radius, color);
269  return *this;
270  }
271 
272  inline Image& DrawCircle(::Vector2 center, int radius, ::Color color) {
273  ::ImageDrawCircleV(this, center, radius, color);
274  return *this;
275  }
276  inline Image& DrawRectangle(int posX, int posY, int width, int height, ::Color color = WHITE) {
277  ::ImageDrawRectangle(this, posX, posY, width, height, color);
278  return *this;
279  }
280  inline Image& DrawRectangle(Vector2 position, Vector2 size, ::Color color = WHITE) {
281  ::ImageDrawRectangleV(this, position, size, color);
282  return *this;
283  }
284  inline Image& DrawRectangle(::Rectangle rec, ::Color color = WHITE) {
285  ::ImageDrawRectangleRec(this, rec, color);
286  return *this;
287  }
288  inline Image& DrawRectangleLines(::Rectangle rec, int thick, ::Color color) {
289  ::ImageDrawRectangleLines(this, rec, thick, color);
290  return *this;
291  }
292  inline Image& Draw(::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint = WHITE) {
293  ::ImageDraw(this, src, srcRec, dstRec, tint);
294  return *this;
295  }
296 
297  inline Image& DrawText(const std::string& text, ::Vector2 position, int fontSize, ::Color color = WHITE){
298  ::ImageDrawText(this, text.c_str(), (int)position.x, (int)position.y, fontSize, color);
299  return *this;
300  }
301  inline Image& DrawText(const std::string& text, int x, int y, int fontSize, ::Color color = WHITE){
302  ::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
303  return *this;
304  }
305  inline Image& DrawText(::Font font, const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE){
306  ::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
307  return *this;
308  }
309 
310  inline ::Color* GetImageData() {
311  return ::GetImageData(*this);
312  }
313 
314  inline ::Vector4* GetImageDataNormalized() {
315  return ::GetImageDataNormalized(*this);
316  }
317  inline operator Texture2D() {
318  return ::LoadTextureFromImage(*this);
319  }
320  };
321 }
322 
323 #endif
raylib::Image::Dither
Image & Dither(int rBpp, int gBpp, int bBpp, int aBpp)
Definition: Image.hpp:187
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:280
raylib::Image::ColorBrightness
Image & ColorBrightness(int brightness)
Definition: Image.hpp:225
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:310
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:234
raylib::Image::DrawText
Image & DrawText(const std::string &text, ::Vector2 position, int fontSize, ::Color color=WHITE)
Definition: Image.hpp:297
raylib::Image::ColorInvert
Image & ColorInvert()
Definition: Image.hpp:213
raylib::Image::ToPOT
Image & ToPOT(Color fillColor)
Definition: Image.hpp:142
raylib::Image::ColorGrayscale
Image & ColorGrayscale()
Definition: Image.hpp:217
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:314
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:205
raylib::Image::DrawLine
Image & DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color)
Definition: Image.hpp:257
raylib::Image::DrawPixel
Image & DrawPixel(int posX, int posY, ::Color color)
Definition: Image.hpp:247
raylib::Image::DrawRectangle
Image & DrawRectangle(int posX, int posY, int width, int height, ::Color color=WHITE)
Definition: Image.hpp:276
raylib::Image::FlipVertical
Image & FlipVertical()
Definition: Image.hpp:192
raylib::Image::ColorContrast
Image & ColorContrast(float contrast)
Definition: Image.hpp:221
raylib::Image::DrawRectangleLines
Image & DrawRectangleLines(::Rectangle rec, int thick, ::Color color)
Definition: Image.hpp:288
raylib::Image::ClearBackground
Image & ClearBackground(::Color color=WHITE)
Definition: Image.hpp:242
raylib::Image::DrawCircle
Image & DrawCircle(::Vector2 center, int radius, ::Color color)
Definition: Image.hpp:272
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::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:305
raylib::Image::Mipmaps
Image & Mipmaps()
Definition: Image.hpp:183
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:252
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:301
raylib::Image::ColorTint
Image & ColorTint(::Color color=WHITE)
Definition: Image.hpp:209
raylib::Image::GetAlphaBorder
Rectangle GetAlphaBorder(float threshold)
Definition: Image.hpp:238
raylib::Image::AlphaCrop
Image & AlphaCrop(float threshold)
Definition: Image.hpp:157
raylib::Image::Resize
Image & Resize(int newWidth, int newHeight)
Definition: Image.hpp:171
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:179
raylib::Image::Unload
void Unload()
Definition: Image.hpp:116
raylib::Image::FlipHorizontal
Image & FlipHorizontal()
Definition: Image.hpp:196
raylib::Image::DrawCircle
Image & DrawCircle(int centerX, int centerY, int radius, ::Color color)
Definition: Image.hpp:267
raylib::Image::ResizeNN
Image & ResizeNN(int newWidth, int newHeight)
Definition: Image.hpp:175
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:201
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:292
raylib::Image::DrawLine
Image & DrawLine(::Vector2 start, ::Vector2 end, ::Color color)
Definition: Image.hpp:262
raylib::Image::ColorReplace
Image & ColorReplace(::Color color, ::Color replace)
Definition: Image.hpp:229
raylib::Image::DrawRectangle
Image & DrawRectangle(::Rectangle rec, ::Color color=WHITE)
Definition: Image.hpp:284
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