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
|
#pragma once
#include <SDL2/SDL.h>
namespace Framework {
class Rectangle {
public:
Rectangle(int x, int y, int w, int h, SDL_Color Color = {0, 0, 0, 255})
: Rect{ x, y, w, h }, Color{ Color }{}
virtual void Render(SDL_Surface* Surface) {
SDL_FillRect(Surface, &Rect, SDL_MapRGB(Surface->format, Color.r,
Color.g, Color.b));
}
void SetColor(SDL_Color C) { Color = C; }
bool IsWithinBounds(int x, int y) const {
if (x < Rect.x
|| x > Rect.x + Rect.w
|| y < Rect.y
|| y > Rect.y + Rect.h) return false;
return true;
}
SDL_Rect* GetRect() { return &Rect; }
virtual ~Rectangle () = default;
private:
SDL_Rect Rect{ 0, 0, 0, 0 };
SDL_Color Color{ 0, 0, 0, 0 };
};
}
|