mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-29 23:25:59 +00:00
Added: Possible to use multiple fonts at the same time
This commit is contained in:
parent
83104a7f15
commit
6fc2f7d603
2 changed files with 54 additions and 1 deletions
|
@ -586,8 +586,12 @@ namespace NLGUI
|
|||
static NL3D::UDriver *driver;
|
||||
static NL3D::UTextContext *textcontext;
|
||||
|
||||
typedef CHashMap< std::string, NL3D::UTextContext* > TFontsList;
|
||||
static TFontsList fonts;
|
||||
|
||||
public:
|
||||
static NL3D::UTextContext* getTextContext(){ return textcontext; }
|
||||
static NL3D::UTextContext* getTextContext(const std::string &name="");
|
||||
static bool registerFont(const std::string &name, const std::string &font);
|
||||
|
||||
/// Set of hw cursor images
|
||||
static std::set< std::string > *hwCursors;
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace NLGUI
|
|||
NL3D::UTextContext* CViewRenderer::textcontext = NULL;
|
||||
std::set< std::string >* CViewRenderer::hwCursors = NULL;
|
||||
float CViewRenderer::hwCursorScale = 1.0f;
|
||||
CViewRenderer::TFontsList CViewRenderer::fonts;
|
||||
|
||||
CViewRenderer::CViewRenderer()
|
||||
{
|
||||
|
@ -214,17 +215,65 @@ namespace NLGUI
|
|||
ite++;
|
||||
}
|
||||
|
||||
TFontsList::iterator iteFonts = fonts.begin();
|
||||
while (iteFonts != fonts.end())
|
||||
{
|
||||
driver->deleteTextContext(iteFonts->second);
|
||||
++iteFonts;
|
||||
}
|
||||
|
||||
_GlobalTextures.clear();
|
||||
_SImages.clear();
|
||||
_SImageIterators.clear();
|
||||
_TextureMap.clear();
|
||||
_IndexesToTextureIds.clear();
|
||||
fonts.clear();
|
||||
}
|
||||
|
||||
NL3D::UDriver* CViewRenderer::getDriver(){
|
||||
return driver;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
NL3D::UTextContext* CViewRenderer::getTextContext(const std::string &name)
|
||||
{
|
||||
if (name.size() > 0 && fonts.count(name) > 0)
|
||||
return fonts[name];
|
||||
|
||||
return textcontext;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
bool CViewRenderer::registerFont(const std::string &name, const std::string &font)
|
||||
{
|
||||
nlassert(driver != NULL);
|
||||
|
||||
// free existing font
|
||||
if (fonts.count(name) > 0)
|
||||
driver->deleteTextContext(fonts[name]);
|
||||
|
||||
std::string fontFile = CPath::lookup(font, false);
|
||||
if (fontFile.size() == 0)
|
||||
{
|
||||
nlwarning("Font file '%s' not found", font.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
NL3D::UTextContext *context;
|
||||
context = driver->createTextContext(fontFile);
|
||||
if (context == NULL)
|
||||
{
|
||||
nlwarning("Cannot create a TextContext with font '%s'.", font.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
context->setKeep800x600Ratio(false);
|
||||
|
||||
fonts[name] = context;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CViewRenderer::setTextContext(NL3D::UTextContext *textcontext)
|
||||
{
|
||||
CViewRenderer::textcontext = textcontext;
|
||||
|
|
Loading…
Reference in a new issue