SDL_helpers.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_SDL2_HELPERS_HPP
30 #define NOMLIB_SDL2_HELPERS_HPP
31 
32 #include <memory>
33 
34 #include "SDL.h"
35 #include "SDL_ttf.h"
36 
37 #include "nomlib/config.hpp"
38 #include "nomlib/math/Color.hpp"
39 #include "nomlib/math/Coords.hpp"
40 #include "nomlib/math/Rect-inl.hpp"
41 #include "nomlib/math/Point2-inl.hpp"
42 
43 namespace nom {
44 
46 namespace SDL_WINDOW
47 {
48  typedef std::unique_ptr<SDL_Window, void (*)(SDL_Window*)> UniquePtr;
49  typedef SDL_Window* RawPtr;
50 }
51 
53 namespace SDL_RENDERER
54 {
55  typedef std::unique_ptr<SDL_Renderer, void(*)(SDL_Renderer*)> UniquePtr;
56  typedef SDL_Renderer* RawPtr;
57 }
58 
60 namespace SDL_PIXELFORMAT
61 {
62  typedef SDL_PixelFormat* RawPtr;
63 }
64 
66 namespace SDL_SURFACE
67 {
68  typedef std::unique_ptr<SDL_Surface, void(*) (SDL_Surface*)> UniquePtr;
69  typedef std::shared_ptr<SDL_Surface> SharedPtr;
70  typedef SDL_Surface* RawPtr;
71 }
72 
74 namespace SDL_TEXTURE
75 {
76  typedef std::shared_ptr<SDL_Texture> SharedPtr;
77  typedef SDL_Texture* RawPtr;
78 }
79 
83 SDL_bool SDL_BOOL ( bool value );
84 
88 SDL_Rect SDL_RECT ( const Coords& coords );
89 
95 template <typename T>
96 SDL_Rect SDL_RECT ( const Rect<T>& )
97 {
98  SDL_Rect null;
99  return null;
100 }
101 
107 template <typename T>
108 SDL_Point SDL_POINT ( const Point2<T>& )
109 {
110  SDL_Point null;
111  return null;
112 }
113 
117 SDL_Color SDL_COLOR ( const Color& color );
118 
122 const Color pixel ( uint32 pixel, const SDL_PixelFormat* fmt );
123 
127 const Color alpha_pixel ( uint32 pixel, const SDL_PixelFormat* fmt );
128 
135 uint32 RGB ( const Color& color, const SDL_PixelFormat* fmt );
136 
143 uint32 RGB ( const Color& color, uint32 fmt );
144 
151 uint32 RGBA ( const Color& color, const SDL_PixelFormat* fmt );
152 
159 uint32 RGBA ( const Color& color, uint32 fmt );
160 
164 uint32 ticks ( void );
165 
173 const std::string hint ( const std::string& name );
174 
184 bool set_hint ( const std::string& name, const std::string& value );
185 
186 namespace priv {
187 
189 void FreeWindow ( SDL_Window* );
190 
192 void FreeRenderTarget ( SDL_Renderer* );
193 
195 void FreeTexture ( SDL_Texture* );
196 
198 void FreeSurface ( SDL_Surface* );
199 
201 void TTF_FreeFont ( TTF_Font* );
202 
204 void Free_Joystick ( SDL_Joystick* );
205 
206 } // namespace priv
207 } // namespace nom
208 
209 #endif // include guard defined
Rectangle class container (template version)
Definition: Rect-inl.hpp:38
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44