1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010-2018 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
22 #include "nel/3d/text_context.h"
23 #include "nel/3d/font_generator.h"
31 // ------------------------------------------------------------------------------------------------
33 // ------------------------------------------------------------------------------------------------
34 CTextContext::CTextContext()
44 _Color
= NLMISC::CRGBA(0,0,0);
46 _HotSpot
= CComputedString::BottomLeft
;
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()
68 _FontManager
->invalidate();
71 // ------------------------------------------------------------------------------------------------
72 uint32
CTextContext::textPush (const char *format
, ...)
76 // convert the string.
78 NLMISC_CONVERT_VARGS (str
, format
, NLMISC::MaxCStringSize
);
80 return textPush(NLMISC::CUtfStringView(str
));
83 // ------------------------------------------------------------------------------------------------
84 uint32
CTextContext::textPush (NLMISC::CUtfStringView sv
)
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
--;
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
);
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
);