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

Method MeasureText

Shadows/SampleFramework11/SpriteFont.cpp:270–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268}
269
270Float2 SpriteFont::MeasureText(const wchar* text) const
271{
272 Float2 size = Float2(0.0f, 0.0f);
273 Float2 curPos = Float2(0.0f, 0.0f);;
274
275 size_t length = wcslen(text);
276
277 for (uint64 i = 0; i < length; ++i)
278 {
279 wchar character = text[i];
280 if(character == ' ')
281 curPos.x += SpaceWidth();
282 else if(character == '\n')
283 {
284 curPos.y += CharHeight();
285 curPos.x = 0;
286 }
287 else
288 {
289 SpriteFont::CharDesc desc = GetCharDescriptor(character);
290 curPos.x += desc.Width + 1;
291 }
292
293 size.x = std::max(curPos.x, size.x);
294 size.y = std::max(curPos.y, size.y);
295 }
296
297 return size;
298}
299
300}

Callers 1

RenderCenteredTextMethod · 0.80

Calls 1

Float2Class · 0.85

Tested by

no test coverage detected