MiniEngine/SDLEngine/src/sdl_engine_font.hpp

62 lines
1.1 KiB
C++
Raw Normal View History

2017-01-05 13:25:09 +08:00
Font::Font()
{
pimpl=new impl;
}
Font::Font(const char* FontFileName,int sz) : Font()
{
use(FontFileName,sz);
}
Font::Font(const Font& inc) : Font()
{
*pimpl=*(inc.pimpl);
}
Font& Font::operator = (const Font& inc)
{
*pimpl=*(inc.pimpl);
return *this;
}
Font::Font(Font&& inc)
{
pimpl=inc.pimpl;
inc.pimpl=nullptr;
}
Font& Font::operator = (Font&& inc)
{
*pimpl=*(inc.pimpl);
inc.pimpl=nullptr;
return *this;
}
Font::~Font()
{
delete pimpl;
}
2017-01-05 13:25:09 +08:00
int Font::use(const char* FontFileName,int sz)
{
TTF_Font* font=TTF_OpenFont(FontFileName,sz);
if(font==NULL) return -1;
pimpl->sTTF.reset(font,TTF_CloseFont);
return 0;
}
2017-01-05 13:25:09 +08:00
Texture Font::renderText(Renderer rnd,const char* Word,RGBA fg)
{
Surface surf;
2017-01-07 09:52:56 +08:00
surf.pimpl->set(TTF_RenderText_Blended(pimpl->sTTF.get(),Word,fg.toSDLColor()));
Texture t=rnd.render(surf);
return t;
}
Texture Font::renderUTF8(Renderer rnd,const char* Word,RGBA fg)
{
Surface surf;
surf.pimpl->set(TTF_RenderUTF8_Blended(pimpl->sTTF.get(),Word,fg.toSDLColor()));
2017-01-05 13:25:09 +08:00
Texture t=rnd.render(surf);
return t;
}