mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 10:55:57 -04:00
Add SDLTTF class for SDL_ttf init/deinit
This commit is contained in:
parent
9e4bdac8cf
commit
4fff7d6cf9
38
SDL2pp/SDLTTF.cc
Normal file
38
SDL2pp/SDLTTF.cc
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
libSDL2pp - C++11 bindings/wrapper for SDL2
|
||||
Copyright (C) 2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
||||
|
||||
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 <SDL2/SDL_ttf.h>
|
||||
|
||||
#include <SDL2pp/SDLTTF.hh>
|
||||
#include <SDL2pp/Exception.hh>
|
||||
|
||||
namespace SDL2pp {
|
||||
|
||||
SDLTTF::SDLTTF() {
|
||||
if (TTF_Init() != 0)
|
||||
throw Exception("TTF_Init failed");
|
||||
}
|
||||
|
||||
SDLTTF::~SDLTTF() {
|
||||
TTF_Quit();
|
||||
}
|
||||
|
||||
}
|
82
SDL2pp/SDLTTF.hh
Normal file
82
SDL2pp/SDLTTF.hh
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
libSDL2pp - C++11 bindings/wrapper for SDL2
|
||||
Copyright (C) 2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user