mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-10 01:09:34 +00:00
Added: Possible to use multiple fonts at the same time
This commit is contained in:
parent
eb877f41ad
commit
9f104a27ba
2 changed files with 54 additions and 1 deletions
|
@ -586,8 +586,12 @@ namespace NLGUI
|
||||||
static NL3D::UDriver *driver;
|
static NL3D::UDriver *driver;
|
||||||
static NL3D::UTextContext *textcontext;
|
static NL3D::UTextContext *textcontext;
|
||||||
|
|
||||||
|
typedef CHashMap< std::string, NL3D::UTextContext* > TFontsList;
|
||||||
|
static TFontsList fonts;
|
||||||
|
|
||||||
public:
|
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
|
/// Set of hw cursor images
|
||||||
static std::set< std::string > *hwCursors;
|
static std::set< std::string > *hwCursors;
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace NLGUI
|
||||||
NL3D::UTextContext* CViewRenderer::textcontext = NULL;
|
NL3D::UTextContext* CViewRenderer::textcontext = NULL;
|
||||||
std::set< std::string >* CViewRenderer::hwCursors = NULL;
|
std::set< std::string >* CViewRenderer::hwCursors = NULL;
|
||||||
float CViewRenderer::hwCursorScale = 1.0f;
|
float CViewRenderer::hwCursorScale = 1.0f;
|
||||||
|
CViewRenderer::TFontsList CViewRenderer::fonts;
|
||||||
|
|
||||||
CViewRenderer::CViewRenderer()
|
CViewRenderer::CViewRenderer()
|
||||||
{
|
{
|
||||||
|
@ -214,17 +215,65 @@ namespace NLGUI
|
||||||
ite++;
|
ite++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TFontsList::iterator iteFonts = fonts.begin();
|
||||||
|
while (iteFonts != fonts.end())
|
||||||
|
{
|
||||||
|
driver->deleteTextContext(iteFonts->second);
|
||||||
|
++iteFonts;
|
||||||
|
}
|
||||||
|
|
||||||
_GlobalTextures.clear();
|
_GlobalTextures.clear();
|
||||||
_SImages.clear();
|
_SImages.clear();
|
||||||
_SImageIterators.clear();
|
_SImageIterators.clear();
|
||||||
_TextureMap.clear();
|
_TextureMap.clear();
|
||||||
_IndexesToTextureIds.clear();
|
_IndexesToTextureIds.clear();
|
||||||
|
fonts.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
NL3D::UDriver* CViewRenderer::getDriver(){
|
NL3D::UDriver* CViewRenderer::getDriver(){
|
||||||
return driver;
|
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)
|
void CViewRenderer::setTextContext(NL3D::UTextContext *textcontext)
|
||||||
{
|
{
|
||||||
CViewRenderer::textcontext = textcontext;
|
CViewRenderer::textcontext = textcontext;
|
||||||
|
|
Loading…
Reference in a new issue