diff --git a/SDL2pp/SDLTTF.cc b/SDL2pp/SDLTTF.cc new file mode 100644 index 0000000..ad5119c --- /dev/null +++ b/SDL2pp/SDLTTF.cc @@ -0,0 +1,38 @@ +/* + libSDL2pp - C++11 bindings/wrapper for SDL2 + Copyright (C) 2014 Dmitry Marakasov + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include + +#include +#include + +namespace SDL2pp { + +SDLTTF::SDLTTF() { + if (TTF_Init() != 0) + throw Exception("TTF_Init failed"); +} + +SDLTTF::~SDLTTF() { + TTF_Quit(); +} + +} diff --git a/SDL2pp/SDLTTF.hh b/SDL2pp/SDLTTF.hh new file mode 100644 index 0000000..5bae95a --- /dev/null +++ b/SDL2pp/SDLTTF.hh @@ -0,0 +1,82 @@ +/* + libSDL2pp - C++11 bindings/wrapper for SDL2 + Copyright (C) 2014 Dmitry Marakasov + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL2PP_SDLTTF_HH +#define SDL2PP_SDLTTF_HH + +namespace SDL2pp { + +//////////////////////////////////////////////////////////// +/// \brief Object taking care of SDL_image library (de-)initialization +/// +/// \ingroup image +/// +/// \headerfile SDL2pp/SDLTTF.hh +/// +/// To use SDL_ttf functions, SDL_ttf library must be initialized first. +/// This initialization and automatic deinitialization is handled by +/// this class. You may only use SDL_ttf (Font class) functionality +/// while SDLTTF object lives. SDL itself must not be initialized to use +/// TTF +/// +/// Usage example: +/// \code +/// int main() { +/// SDL2pp::SDLTTF ttf; +/// +/// // ...use SDL_ttf functions... +/// +/// // SDL_ttf library is automatically deinitialized before exit +/// return 0; +/// } +/// \endcode +/// +//////////////////////////////////////////////////////////// +class SDLTTF { +public: + //////////////////////////////////////////////////////////// + /// \brief Initializes SDL_ttf library + /// + /// \throws SDL2pp::Exception + /// + /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC8 + /// + //////////////////////////////////////////////////////////// + SDLTTF(); + + //////////////////////////////////////////////////////////// + /// \brief Destructor, deinitializes SDL_ttf library + /// + /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC10 + /// + //////////////////////////////////////////////////////////// + virtual ~SDLTTF(); + + // Deleted copy/move constructors and assignments + SDLTTF(const SDLTTF& other) = delete; + SDLTTF(SDLTTF&& other) = delete; + SDLTTF& operator=(const SDLTTF& other) = delete; + SDLTTF& operator=(SDLTTF&& other) = delete; +}; + +} + +#endif