diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-02 18:38:53 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-11-02 18:38:53 -0400 |
commit | a59fcafb2e81f3cb40ff320b106030e8fed4bd66 (patch) | |
tree | 7e7396a9422814365a5f903a53d7391d3e7b22fd /sdl.h | |
parent | 45d6e635c880a7fae8711fba366519dd314d9faf (diff) | |
download | mazeoflife-a59fcafb2e81f3cb40ff320b106030e8fed4bd66.tar.gz mazeoflife-a59fcafb2e81f3cb40ff320b106030e8fed4bd66.tar.bz2 mazeoflife-a59fcafb2e81f3cb40ff320b106030e8fed4bd66.zip |
Diffstat (limited to 'sdl.h')
-rw-r--r-- | sdl.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/sdl.h b/sdl.h new file mode 100644 index 0000000..46d1fa4 --- /dev/null +++ b/sdl.h | |||
@@ -0,0 +1,102 @@ | |||
1 | #ifndef SDL_H_A2226476 | ||
2 | #define SDL_H_A2226476 | ||
3 | |||
4 | #include <SDL.h> | ||
5 | #include <SDL_net.h> | ||
6 | #include <SDL_ttf.h> | ||
7 | |||
8 | #include <memory> | ||
9 | |||
10 | class sdl_error : public std::logic_error { | ||
11 | public: | ||
12 | sdl_error() : std::logic_error(SDL_GetError()) {} | ||
13 | }; | ||
14 | |||
15 | class ttf_error : public std::logic_error { | ||
16 | public: | ||
17 | ttf_error() : std::logic_error(TTF_GetError()) {} | ||
18 | }; | ||
19 | |||
20 | class net_error : public std::logic_error { | ||
21 | public: | ||
22 | net_error() : std::logic_error(SDLNet_GetError()) {} | ||
23 | }; | ||
24 | |||
25 | class sdl_wrapper { | ||
26 | public: | ||
27 | sdl_wrapper() { | ||
28 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { | ||
29 | sdl_error ex; | ||
30 | SDL_Quit(); | ||
31 | |||
32 | throw ex; | ||
33 | } | ||
34 | } | ||
35 | |||
36 | ~sdl_wrapper() { SDL_Quit(); } | ||
37 | }; | ||
38 | |||
39 | class ttf_wrapper { | ||
40 | public: | ||
41 | ttf_wrapper() { | ||
42 | if (TTF_Init() == -1) { | ||
43 | ttf_error ex; | ||
44 | TTF_Quit(); | ||
45 | |||
46 | throw ex; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | ~ttf_wrapper() { TTF_Quit(); } | ||
51 | }; | ||
52 | |||
53 | class net_wrapper { | ||
54 | public: | ||
55 | net_wrapper() { | ||
56 | if (SDLNet_Init() == -1) { | ||
57 | net_error ex; | ||
58 | SDLNet_Quit(); | ||
59 | |||
60 | throw ex; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | ~net_wrapper() { SDLNet_Quit(); } | ||
65 | }; | ||
66 | |||
67 | class window_deleter { | ||
68 | public: | ||
69 | void operator()(SDL_Window* ptr) { SDL_DestroyWindow(ptr); } | ||
70 | }; | ||
71 | |||
72 | using window_ptr = std::unique_ptr<SDL_Window, window_deleter>; | ||
73 | |||
74 | class renderer_deleter { | ||
75 | public: | ||
76 | void operator()(SDL_Renderer* ptr) { SDL_DestroyRenderer(ptr); } | ||
77 | }; | ||
78 | |||
79 | using renderer_ptr = std::unique_ptr<SDL_Renderer, renderer_deleter>; | ||
80 | |||
81 | class surface_deleter { | ||
82 | public: | ||
83 | void operator()(SDL_Surface* ptr) { SDL_FreeSurface(ptr); } | ||
84 | }; | ||
85 | |||
86 | using surface_ptr = std::unique_ptr<SDL_Surface, surface_deleter>; | ||
87 | |||
88 | class texture_deleter { | ||
89 | public: | ||
90 | void operator()(SDL_Texture* ptr) { SDL_DestroyTexture(ptr); } | ||
91 | }; | ||
92 | |||
93 | using texture_ptr = std::unique_ptr<SDL_Texture, texture_deleter>; | ||
94 | |||
95 | class font_deleter { | ||
96 | public: | ||
97 | void operator()(TTF_Font* ptr) { TTF_CloseFont(ptr); } | ||
98 | }; | ||
99 | |||
100 | using font_ptr = std::unique_ptr<TTF_Font, font_deleter>; | ||
101 | |||
102 | #endif /* end of include guard: SDL_H_A2226476 */ | ||