Implement Font constructor from TTF_Font*

This commit is contained in:
Dmitry Marakasov 2015-01-11 06:36:11 +03:00
parent 1e5c17c95a
commit feabe1497e
2 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,6 @@
/* /*
libSDL2pp - C++11 bindings/wrapper for SDL2 libSDL2pp - C++11 bindings/wrapper for SDL2
Copyright (C) 2014 Dmitry Marakasov <amdmi3@amdmi3.ru> Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -27,6 +27,10 @@
namespace SDL2pp { namespace SDL2pp {
Font::Font(TTF_Font* font) {
font_ = font;
}
Font::Font(const std::string& file, int ptsize, long index) { Font::Font(const std::string& file, int ptsize, long index) {
if ((font_ = TTF_OpenFontIndex(file.c_str(), ptsize, index)) == nullptr) if ((font_ = TTF_OpenFontIndex(file.c_str(), ptsize, index)) == nullptr)
throw Exception("TTF_OpenFontIndex failed"); throw Exception("TTF_OpenFontIndex failed");

View File

@ -49,6 +49,14 @@ private:
TTF_Font* font_; ///< Managed TTF_Font object TTF_Font* font_; ///< Managed TTF_Font object
public: public:
////////////////////////////////////////////////////////////
/// \brief Construct from existing TTF_Font structure
///
/// \param font Existing TTF_Font to manage
///
////////////////////////////////////////////////////////////
Font(TTF_Font* font);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Loads font from .ttf or .fon file /// \brief Loads font from .ttf or .fon file
/// ///