aboutsummaryrefslogtreecommitdiff
path: root/src/framework/image.hpp
blob: 0715318a8baeaa7df8b1e47a38ff76986b62eef3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <string>
#include <SDL2/SDL_image.h>

namespace Framework {
	class Image {
	public:
		Image(int x, int y, int w, int h, 
			const std::string& File, int Padding = 12)
			: Destination{
				x + Padding/2, y + Padding/2, w - Padding, h - Padding } {
		ImageSurface = IMG_Load(File.c_str());
#ifdef SHOW_DEBUG_HELPERS
			Utils::CheckSDLError("Image::Image::IMG_Load");
#endif
		}

		void Render(SDL_Surface* Surface) {
			SDL_BlitScaled(ImageSurface, nullptr, Surface, &Destination);
		}

		~Image() {
			ReleaseImageSurface();
		}

		Image(const Image&){}
		/* TODO: THIS IS INCOMPLETE */
		Image& operator=(const Image& other) {
			if (this != &other) {
				ReleaseImageSurface();
			}
			return *this;
		}

	private:
		SDL_Surface* ImageSurface{ nullptr };
		SDL_Rect Destination{ 0, 0, 0, 0 };

		void ReleaseImageSurface() {
			if (ImageSurface) {
				SDL_FreeSurface(ImageSurface);
				ImageSurface = nullptr;
			}
		}
	};
}

(git 2.53.0) at 2026-05-13 17:18:21 +0000