CNeutrinoFonts: Add 'getDynFontExt()' for create custom fonts...

...in external plugins
This commit is contained in:
M. Liebmann
2015-11-27 12:11:41 +01:00
parent 7caf055ea0
commit 56d76f4ebc
2 changed files with 84 additions and 7 deletions

View File

@@ -69,17 +69,22 @@ CNeutrinoFonts::CNeutrinoFonts()
InitDynFonts();
}
void CNeutrinoFonts::clearDynFontStruct(dyn_font_t* f)
{
f->dx = 0;
f->dy = 0;
f->size = 0;
f->style = 0;
f->text = "";
f->font = NULL;
f->useDigitOffset = false;
}
void CNeutrinoFonts::InitDynFonts()
{
for (int i = 0; i < FONT_ID_MAX; i++) {
dyn_font_t dyn_font;
dyn_font.dx = 0;
dyn_font.dy = 0;
dyn_font.size = 0;
dyn_font.style = 0;
dyn_font.text = "";
dyn_font.font = NULL;
dyn_font.useDigitOffset = false;
clearDynFontStruct(&dyn_font);
v_dyn_fonts.push_back(dyn_font);
}
}
@@ -97,6 +102,8 @@ CNeutrinoFonts::~CNeutrinoFonts()
delete v_dyn_fonts[i].font;
v_dyn_fonts.clear();
}
deleteDynFontExtAll();
}
CNeutrinoFonts* CNeutrinoFonts::getInstance()
@@ -344,6 +351,66 @@ Font **CNeutrinoFonts::getDynFontWithID(int &dx, int &dy, std::string text, int
return ret;
}
void CNeutrinoFonts::initDynFontExt()
{
for (int i = 0; i < DYNFONTEXT_MAX; i++) {
dyn_font_t dyn_font;
clearDynFontStruct(&dyn_font);
v_dyn_fonts_ext.push_back(dyn_font);
}
}
void CNeutrinoFonts::deleteDynFontExtAll()
{
if (!v_dyn_fonts_ext.empty()) {
for (size_t i = 0; i < v_dyn_fonts_ext.size(); ++i) {
if (v_dyn_fonts_ext[i].font != NULL)
delete v_dyn_fonts_ext[i].font;
}
v_dyn_fonts_ext.clear();
}
}
Font *CNeutrinoFonts::getDynFontExt(int &dx, int &dy, unsigned int f_id, std::string text/*=""*/, int style/*=FONT_STYLE_REGULAR*/)
{
if ((dx <= 0) && (dy <= 0))
return NULL;
if ((fontDescr.name.empty()) || (fontDescr.filename.empty()))
SetupNeutrinoFonts();
if (g_dynFontRenderer == NULL)
SetupDynamicFonts();
if (v_dyn_fonts_ext.empty())
initDynFontExt();
int dynSize = getDynFontSize(dx, dy, text, style);
Font *dynFont = NULL;
Font *ret = NULL;
if (f_id < v_dyn_fonts_ext.size()) {
dynFont = g_dynFontRenderer->getFont(fontDescr.name.c_str(), dynFontStyle[style].c_str(), dynSize);
if (v_dyn_fonts_ext[f_id].font != NULL)
delete v_dyn_fonts_ext[f_id].font;
v_dyn_fonts_ext[f_id].dx = dx;
v_dyn_fonts_ext[f_id].dy = dy;
v_dyn_fonts_ext[f_id].size = dynSize;
v_dyn_fonts_ext[f_id].style = style;
v_dyn_fonts_ext[f_id].text = text;
v_dyn_fonts_ext[f_id].font = dynFont;
v_dyn_fonts_ext[f_id].useDigitOffset = useDigitOffset;
ret = v_dyn_fonts_ext[f_id].font;
}
else
return NULL;
dy = ret->getHeight();
if (!text.empty())
dx = ret->getRenderWidth(text);
#ifdef DEBUG_NFONTS
printf("##### [%s] dx: %d, dy: %d, dynSize: %d, dynFont: %p, ret: %p, FontID: %d\n", __FUNCTION__, dx, dy, dynSize, *ret, ret, f_id);
#endif
return ret;
}
Font **CNeutrinoFonts::getDynFontShare(int &dx, int &dy, std::string text, int style)
{
if ((dx <= 0) && (dy <= 0))