Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / 3d / text_context.cpp
blob1399ac31c8857460ebf9e05bfac47f5bb7be0ae9
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010-2018 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "std3d.h"
22 #include "nel/3d/text_context.h"
23 #include "nel/3d/font_generator.h"
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 namespace NL3D {
31 // ------------------------------------------------------------------------------------------------
32 // Constructor
33 // ------------------------------------------------------------------------------------------------
34 CTextContext::CTextContext()
36 _Driver = NULL;
37 _FontManager = NULL;
38 _FontGen = NULL;
40 _FontSize = 12;
41 _Embolden = false;
42 _Oblique = false;
44 _Color = NLMISC::CRGBA(0,0,0);
46 _HotSpot = CComputedString::BottomLeft;
48 _ScaleX = 1.0f;
49 _ScaleZ = 1.0f;
51 _Shaded = false;
52 _ShadeOutline = false;
53 _ShadeExtentX = 0.001f;
54 _ShadeExtentY = 0.001f;
55 _ShadeColor = NLMISC::CRGBA(0,0,0);
57 _Keep800x600Ratio= true;
59 _CacheNbFreePlaces = 0;
62 // ------------------------------------------------------------------------------------------------
63 CTextContext::~CTextContext()
65 if (_FontGen)
66 delete _FontGen;
67 if (_FontManager)
68 _FontManager->invalidate();
71 // ------------------------------------------------------------------------------------------------
72 uint32 CTextContext::textPush (const char *format, ...)
74 nlassert(_FontGen);
76 // convert the string.
77 char *str;
78 NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize);
80 return textPush(NLMISC::CUtfStringView(str));
83 // ------------------------------------------------------------------------------------------------
84 uint32 CTextContext::textPush (NLMISC::CUtfStringView sv)
86 nlassert(_FontGen);
88 if (_CacheNbFreePlaces == 0)
90 CComputedString csTmp;
92 _CacheStrings.push_back (csTmp);
93 if (_CacheFreePlaces.empty())
94 _CacheFreePlaces.resize (1);
95 _CacheFreePlaces[0] = (uint32)_CacheStrings.size()-1;
96 _CacheNbFreePlaces = 1;
99 // compute the string.
100 uint32 index = _CacheFreePlaces[_CacheNbFreePlaces-1];
101 nlassert (index < _CacheStrings.size());
102 CComputedString &strToFill = _CacheStrings[index];
104 _FontManager->computeString (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, strToFill, _Keep800x600Ratio);
105 // just compute letters, glyphs are rendered on demand before first draw
106 //_FontManager->computeStringInfo(str, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, strToFill, _Keep800x600Ratio);
108 _CacheNbFreePlaces--;
110 return index;
113 // ------------------------------------------------------------------------------------------------
114 void CTextContext::erase (uint32 i)
116 nlassertex ((i < _CacheStrings.size()), ("try to erase an unknown text"));
117 _CacheStrings[i].LetterColors.clear();
118 if (_CacheFreePlaces.size() == _CacheNbFreePlaces)
120 _CacheFreePlaces.push_back (i);
122 else
124 _CacheFreePlaces[_CacheNbFreePlaces] = i;
126 _CacheNbFreePlaces++;
130 // ------------------------------------------------------------------------------------------------
131 void CTextContext::clear ()
133 _CacheFreePlaces.clear();
134 _CacheNbFreePlaces = 0;
135 _CacheStrings.clear();
139 // ------------------------------------------------------------------------------------------------
140 void CTextContext::setFontGenerator(const std::string &fontFileName, const std::string &fontExFileName)
142 CFontGenerator *oldFontGen = _FontGen;
143 _FontGen = new NL3D::CFontGenerator(fontFileName, fontExFileName);
144 if (oldFontGen) delete oldFontGen;
147 // ------------------------------------------------------------------------------------------------
148 void CTextContext::setLetterColors(CLetterColors * letterColors, uint index)
150 if(/*index>=0 &&*/ index<_CacheStrings.size())
152 _CacheStrings[index].LetterColors.clear();
153 _CacheStrings[index].LetterColors = *letterColors;
157 // ------------------------------------------------------------------------------------------------
158 bool CTextContext::isSameLetterColors(CLetterColors * letterColors, uint index)
160 if(/*index>=0 &&*/ index<_CacheStrings.size())
162 CLetterColors & strLetterColors = _CacheStrings[index].LetterColors;
163 return strLetterColors.isSameLetterColors(letterColors);
166 return false;
169 } // NL3D