| 243 | } |
| 244 | |
| 245 | Float2 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 | } |