| 280 | } |
| 281 | |
| 282 | size_t TextView::getCursorPosition(const IntPoint& _value) const |
| 283 | { |
| 284 | size_t result = 0; |
| 285 | int top = 0; |
| 286 | |
| 287 | for (VectorLineInfo::const_iterator line = mLineInfo.begin(); line != mLineInfo.end(); ++line) |
| 288 | { |
| 289 | bool lastline = line + 1 == mLineInfo.end(); |
| 290 | |
| 291 | // наша строчка |
| 292 | if (top + mFontHeight <= _value.top && !lastline) |
| 293 | { |
| 294 | top += mFontHeight; |
| 295 | result += line->count + 1; |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | float left = (float)line->offset; |
| 300 | int count = 0; |
| 301 | |
| 302 | // ищем символ |
| 303 | for (const auto& sym : line->symbols) |
| 304 | { |
| 305 | if (sym.isColour()) |
| 306 | continue; |
| 307 | |
| 308 | float fullAdvance = sym.getAdvance() + sym.getBearingX(); |
| 309 | if (left + fullAdvance / 2.0f > _value.left) |
| 310 | { |
| 311 | break; |
| 312 | } |
| 313 | left += fullAdvance; |
| 314 | count++; |
| 315 | } |
| 316 | |
| 317 | result += count; |
| 318 | break; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | return result; |
| 323 | } |
| 324 | |
| 325 | IntPoint TextView::getCursorPoint(size_t _position) const |
| 326 | { |
no test coverage detected