-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrect_tools.hpp
49 lines (42 loc) · 1007 Bytes
/
rect_tools.hpp
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
48
49
#ifndef RECT_TOOLS_HPP
#define RECT_TOOLS_HPP
#include <SDL.h>
SDL_Rect inline add_margin(SDL_Rect rect, int left, int top, int right, int bottom)
{
rect.x += left;
rect.y += top;
rect.w -= (left + right);
rect.h -= (top + bottom);
return rect;
}
SDL_Rect inline add_margin(SDL_Rect rect, int margin_h, int margin_v)
{
return add_margin(rect, margin_h, margin_v, margin_h, margin_v);
}
SDL_Rect inline add_margin(SDL_Rect rect, int margin_all)
{
return add_margin(rect, margin_all, margin_all);
}
auto inline split_horizontal(SDL_Rect rect, int diff)
{
SDL_Rect left, right;
left = rect;
right = rect;
left.w = diff;
right.x += diff;
right.w -= diff;
struct { SDL_Rect left, right; } result { left, right };
return result;
}
auto inline split_vertical(SDL_Rect rect, int diff)
{
SDL_Rect top, bottom;
top = rect;
bottom = rect;
top.h = diff;
bottom.y += diff;
bottom.h -= diff;
struct { SDL_Rect top, bottom; } result { top, bottom };
return result;
}
#endif // RECT_TOOLS_HPP