[New] Font support rendering to Surface

Now Font support rendering to Surface instead of Texture. If Renderer
not passed in, Font will generate a Surface.
This commit is contained in:
Kirigaya Kazuto 2017-04-12 08:55:25 +08:00
parent e7372dcf5f
commit a315daa453
2 changed files with 76 additions and 24 deletions

View File

@ -772,60 +772,102 @@ namespace MiniEngine
return 0;
}
Texture Font::renderText(Renderer rnd, std::string Text, RGBA fg)
/// rendering surfaces...
Surface Font::renderText(std::string Text,RGBA fg)
{
Surface surf;
surf._set(TTF_RenderText_Blended(_get(), Text.c_str(), fg.toSDLColor()));
return rnd.render(surf);
return surf;
}
Surface Font::renderTextWrapped(std::string Text, RGBA fg, int WrapLength)
{
Surface surf;
surf._set(TTF_RenderText_Blended_Wrapped(_get(), Text.c_str(), fg.toSDLColor(), WrapLength));
return surf;
}
Surface Font::renderTextShaded(std::string Text, RGBA fg,RGBA bg)
{
Surface surf;
surf._set(TTF_RenderText_Shaded(_get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()));
return surf;
}
Surface Font::renderTextSolid(std::string Text,RGBA fg)
{
Surface surf;
surf._set(TTF_RenderText_Solid(_get(), Text.c_str(), fg.toSDLColor()));
return surf;
}
Surface Font::renderUTF8(std::string Text,RGBA fg)
{
Surface surf;
surf._set(TTF_RenderUTF8_Blended(_get(), Text.c_str(), fg.toSDLColor()));
return surf;
}
Surface Font::renderUTF8Wrapped(std::string Text, RGBA fg, int WrapLength)
{
Surface surf;
surf._set(TTF_RenderUTF8_Blended_Wrapped(_get(), Text.c_str(), fg.toSDLColor(), WrapLength));
return surf;
}
Surface Font::renderUTF8Shaded(std::string Text, RGBA fg,RGBA bg)
{
Surface surf;
surf._set(TTF_RenderUTF8_Shaded(_get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()));
return surf;
}
Surface Font::renderUTF8Solid(std::string Text,RGBA fg)
{
Surface surf;
surf._set(TTF_RenderUTF8_Solid(_get(), Text.c_str(), fg.toSDLColor()));
return surf;
}
/// rendering textures...
Texture Font::renderText(Renderer rnd, std::string Text, RGBA fg)
{
return rnd.render(renderText(Text,fg));
}
Texture Font::renderTextWrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength)
{
Surface surf;
surf._set(TTF_RenderText_Blended_Wrapped(_get(), Text.c_str(), fg.toSDLColor(), WrapLength));
return rnd.render(surf);
return rnd.render(renderTextWrapped(Text,fg,WrapLength));
}
Texture Font::renderTextShaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg)
{
Surface surf;
surf._set(TTF_RenderText_Shaded(_get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()));
return rnd.render(surf);
return rnd.render(renderTextShaded(Text,fg,bg));
}
Texture Font::renderTextSolid(Renderer rnd, std::string Text, RGBA fg)
{
Surface surf;
surf._set(TTF_RenderText_Solid(_get(), Text.c_str(), fg.toSDLColor()));
return rnd.render(surf);
return rnd.render(renderTextSolid(Text,fg));
}
Texture Font::renderUTF8(Renderer rnd, std::string Text, RGBA fg)
{
Surface surf;
surf._set(TTF_RenderUTF8_Blended(_get(), Text.c_str(), fg.toSDLColor()));
return rnd.render(surf);
return rnd.render(renderUTF8(Text,fg));
}
Texture Font::renderUTF8Wrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength)
{
Surface surf;
surf._set(TTF_RenderUTF8_Blended_Wrapped(_get(), Text.c_str(), fg.toSDLColor(), WrapLength));
return rnd.render(surf);
return rnd.render(renderUTF8Wrapped(Text,fg,WrapLength));
}
Texture Font::renderUTF8Shaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg)
{
Surface surf;
surf._set(TTF_RenderUTF8_Shaded(_get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()));
return rnd.render(surf);
return rnd.render(renderUTF8Shaded(Text,fg,bg));
}
Texture Font::renderUTF8Solid(Renderer rnd, std::string Text, RGBA fg)
{
Surface surf;
surf._set(TTF_RenderUTF8_Solid(_get(), Text.c_str(), fg.toSDLColor()));
return rnd.render(surf);
return rnd.render(renderUTF8Solid(Text,fg));
}
void LogSystem::d(const char* fmt,...)

View File

@ -302,6 +302,16 @@ namespace MiniEngine
std::tuple<Style> getFontStyles();
Surface renderText(std::string Text, RGBA fg);
Surface renderTextWrapped(std::string Text, RGBA fg, int WrapLength);
Surface renderTextShaded(std::string Text, RGBA fg, RGBA bg);
Surface renderTextSolid(std::string Text, RGBA fg);
Surface renderUTF8(std::string Text, RGBA fg);
Surface renderUTF8Wrapped(std::string Text, RGBA fg, int WrapLength);
Surface renderUTF8Shaded(std::string Text, RGBA fg, RGBA bg);
Surface renderUTF8Solid(std::string Text, RGBA fg);
Texture renderText(Renderer rnd, std::string Text, RGBA fg);
Texture renderTextWrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength);
Texture renderTextShaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg);