MCPcopy Create free account
hub / github.com/TheRealMJP/SHforHLSL / MeasureText

Method MeasureText

SHTest/SampleFramework12/v1.04/Graphics/SpriteFont.cpp:245–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245Float2 SpriteFont::MeasureText(const wchar* text) const
246{
247 Float2 textSize = Float2(0.0f, 0.0f);
248 Float2 curPos = Float2(0.0f, 0.0f);;
249
250 size_t length = wcslen(text);
251
252 for (uint64 i = 0; i < length; ++i)
253 {
254 wchar character = text[i];
255 if(character == ' ')
256 curPos.x += SpaceWidth();
257 else if(character == '\n')
258 {
259 curPos.y += CharHeight();
260 curPos.x = 0;
261 }
262 else
263 {
264 SpriteFont::CharDesc desc = GetCharDescriptor(character);
265 curPos.x += desc.Width + 1;
266 }
267
268 textSize.x = std::max(curPos.x, textSize.x);
269 textSize.y = std::max(curPos.y, textSize.y);
270 }
271
272 return textSize;
273}
274
275}

Callers 1

RenderMethod · 0.80

Calls 1

Float2Class · 0.85

Tested by 1

RenderMethod · 0.64