-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrect.hh
More file actions
37 lines (30 loc) · 712 Bytes
/
Copy pathrect.hh
File metadata and controls
37 lines (30 loc) · 712 Bytes
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
#include <SDL2/SDL_rect.h>
template<class T, bool control(T)>
class ControlledRef{
public:
constexpr ControlledRef(T& t) : m_t{ t }{
assert(control(t));
};
constexpr operator T() const{ return m_t; };
constexpr ControlledRef& operator=(T& value){
assert(control(value));
m_t = value;
return *this;
}
private:
T m_t;
};
bool positive(int i){ return i >= 0; }
namespace sdl{
class Rect final{
using PositiveIntRef = ControlledRef<int, positive>;
SDL_Rect m;
public:
Rect(int w, int h) : m{ 0, 0, w, h } {}
PositiveIntRef x(){ return {m.x}; }
int const& x() const{ return m.x; }
operator SDL_Rect() const noexcept{
return m;
}
};
}