@@ -47,6 +47,20 @@ class Image : public ::Image {
4747 set (::ImageTextEx (font, text.c_str (), fontSize, spacing, tint));
4848 }
4949
50+ Image (const Image& other) {
51+ set (other.Copy ());
52+ }
53+
54+ Image (Image&& other) {
55+ set (other);
56+
57+ other.data = nullptr ;
58+ other.width = 0 ;
59+ other.height = 0 ;
60+ other.mipmaps = 0 ;
61+ other.format = 0 ;
62+ }
63+
5064 static ::Image Text (const std::string& text, int fontSize,
5165 ::Color color = {255 , 255 , 255 , 255 }) {
5266 return ::ImageText (text.c_str (), fontSize, color);
@@ -132,6 +146,32 @@ class Image : public ::Image {
132146 return *this ;
133147 }
134148
149+ Image& operator =(const Image& other) {
150+ if (this == &other) {
151+ return *this ;
152+ }
153+
154+ Unload ();
155+ set (other.Copy ());
156+ }
157+
158+ Image& operator =(Image&& other) {
159+ if (this == &other) {
160+ return *this ;
161+ }
162+
163+ Unload ();
164+ set (other);
165+
166+ other.data = nullptr ;
167+ other.width = 0 ;
168+ other.height = 0 ;
169+ other.mipmaps = 0 ;
170+ other.format = 0 ;
171+
172+ return *this ;
173+ }
174+
135175 /* *
136176 * Load image from file into CPU memory (RAM)
137177 */
@@ -167,24 +207,24 @@ class Image : public ::Image {
167207 * Unload image from CPU memory (RAM)
168208 */
169209 inline void Unload () {
170- if (data != NULL ) {
210+ if (data != nullptr ) {
171211 ::UnloadImage (*this );
172- data = NULL ;
212+ data = nullptr ;
173213 }
174214 }
175215
176216 /* *
177217 * Export image data to file, returns true on success
178218 */
179- inline bool Export (const std::string& fileName) {
219+ inline bool Export (const std::string& fileName) const {
180220 // TODO(RobLoach): Switch to an invalid loading exception on false.
181221 return ::ExportImage (*this , fileName.c_str ());
182222 }
183223
184224 /* *
185225 * Export image as code file defining an array of bytes, returns true on success
186226 */
187- inline bool ExportAsCode (const std::string& fileName) {
227+ inline bool ExportAsCode (const std::string& fileName) const {
188228 return ::ExportImageAsCode (*this , fileName.c_str ());
189229 }
190230
@@ -197,21 +237,21 @@ class Image : public ::Image {
197237 /* *
198238 * Retrieve the width and height of the image.
199239 */
200- inline ::Vector2 GetSize () {
240+ inline ::Vector2 GetSize () const {
201241 return {static_cast <float >(width), static_cast <float >(height)};
202242 }
203243
204244 /* *
205245 * Create an image duplicate (useful for transformations)
206246 */
207- inline ::Image Copy () {
247+ inline ::Image Copy () const {
208248 return ::ImageCopy (*this );
209249 }
210250
211251 /* *
212252 * Create an image from another image piece
213253 */
214- inline ::Image FromImage (::Rectangle rec) {
254+ inline ::Image FromImage (::Rectangle rec) const {
215255 return ::ImageFromImage (*this , rec);
216256 }
217257
@@ -517,35 +557,35 @@ class Image : public ::Image {
517557 /* *
518558 * Load color data from image as a Color array (RGBA - 32bit)
519559 */
520- inline ::Color* LoadColors () {
560+ inline ::Color* LoadColors () const {
521561 return ::LoadImageColors (*this );
522562 }
523563
524564 /* *
525565 * Load colors palette from image as a Color array (RGBA - 32bit)
526566 */
527- inline ::Color* LoadPalette (int maxPaletteSize, int *colorsCount) {
567+ inline ::Color* LoadPalette (int maxPaletteSize, int *colorsCount) const {
528568 return ::LoadImagePalette (*this , maxPaletteSize, colorsCount);
529569 }
530570
531571 /* *
532572 * Unload color data loaded with LoadImageColors()
533573 */
534- inline void UnloadColors (::Color* colors) {
574+ inline void UnloadColors (::Color* colors) const {
535575 ::UnloadImageColors (colors);
536576 }
537577
538578 /* *
539579 * Unload colors palette loaded with LoadImagePalette()
540580 */
541- inline void UnloadPalette (::Color* colors) {
581+ inline void UnloadPalette (::Color* colors) const {
542582 ::UnloadImagePalette (colors);
543583 }
544584
545585 /* *
546586 * Load texture from image data
547587 */
548- inline ::Texture2D LoadTexture () {
588+ inline ::Texture2D LoadTexture () const {
549589 return ::LoadTextureFromImage (*this );
550590 }
551591
@@ -568,7 +608,7 @@ class Image : public ::Image {
568608 *
569609 * @return The pixel data size of the image.
570610 */
571- int GetPixelDataSize () {
611+ int GetPixelDataSize () const {
572612 return ::GetPixelDataSize (width, height, format);
573613 }
574614
0 commit comments