From afc08d2efd28643d8082639fadb80fde0af6dc8d Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sun, 24 Jul 2016 16:03:37 +0300 Subject: [PATCH] Added: Possible to use multiple fonts at the same time --HG-- branch : develop --- code/nel/include/nel/gui/view_renderer.h | 6 ++- code/nel/src/gui/view_renderer.cpp | 49 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/code/nel/include/nel/gui/view_renderer.h b/code/nel/include/nel/gui/view_renderer.h index a54708b04..3c643bf39 100644 --- a/code/nel/include/nel/gui/view_renderer.h +++ b/code/nel/include/nel/gui/view_renderer.h @@ -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; diff --git a/code/nel/src/gui/view_renderer.cpp b/code/nel/src/gui/view_renderer.cpp index 0b4d837f3..4c5d7c501 100644 --- a/code/nel/src/gui/view_renderer.cpp +++ b/code/nel/src/gui/view_renderer.cpp @@ -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;