libwtk-sdl2  0.0.1
sdl_util.hpp
1 #ifndef LIBWTK_SDL2_UTIL
2 #define LIBWTK_SDL2_UTIL
3 #include <memory>
4 
5 #include <SDL2/SDL_rect.h>
6 #include <SDL2/SDL_surface.h>
7 
8 #include "geometry.hpp"
9 
11 {
12  void operator()(SDL_Surface * s);
13 };
14 
15 typedef std::unique_ptr<SDL_Surface, surface_deleter> unique_surface_ptr;
16 
18 {
19  void operator()(SDL_Texture * t);
20 };
21 
22 typedef std::unique_ptr<SDL_Texture, texture_destroyer> unique_texture_ptr;
23 
24 unique_texture_ptr load_texture_from_image(SDL_Renderer * r, std::string filename);
25 
26 SDL_Renderer * renderer_from_window(SDL_Window * window);
27 SDL_Rect box_from_renderer(SDL_Renderer * renderer);
28 
29 void print_rect(SDL_Rect const & r);
30 
31 SDL_Rect pad_rect(SDL_Rect box, int padding);
32 
33 // create a surface with similar properties
34 SDL_Surface * create_surface(uint32_t pfe, int width, int height);
35 SDL_Surface * create_surface(SDL_PixelFormat const * pf, int width, int height);
36 
37 // Scale a source rectangle that it fits into the target while preserving aspect
38 // ratio. Also returns the uncovered rectangles.
39 std::tuple<SDL_Rect, SDL_Rect, SDL_Rect> scale_preserve_ar(vec size, SDL_Rect target);
40 
41 // blit a surface to another surface while preserving aspect ratio
42 void blit_preserve_ar(SDL_Surface * source, SDL_Surface * dest, SDL_Rect const * destrect);
43 
44 vec texture_dim(SDL_Texture * tex);
45 
46 #endif
47 
Definition: sdl_util.hpp:17
Definition: padding.hpp:6
Definition: geometry.hpp:12
Definition: sdl_util.hpp:10
Definition: box.hpp:11