* Focuses the text edit when it's pressed on. * @param action Pointer to an action. * @param state State that the action handlers belong to. */
| 365 | * @param state State that the action handlers belong to. |
| 366 | */ |
| 367 | void TextEdit::mousePress(Action *action, State *state) |
| 368 | { |
| 369 | if (action->getDetails()->button.button == SDL_BUTTON_LEFT) |
| 370 | { |
| 371 | if (!_isFocused) |
| 372 | { |
| 373 | setFocus(true); |
| 374 | } |
| 375 | else |
| 376 | { |
| 377 | double mouseX = action->getRelativeXMouse(); |
| 378 | double scaleX = action->getXScale(); |
| 379 | double w = 0; |
| 380 | int c = 0; |
| 381 | for (std::wstring::iterator i = _value.begin(); i < _value.end(); ++i) |
| 382 | { |
| 383 | if (mouseX <= w) |
| 384 | { |
| 385 | break; |
| 386 | } |
| 387 | w += (double)_text->getFont()->getCharSize(*i).w / 2 * scaleX; |
| 388 | if (mouseX <= w) |
| 389 | { |
| 390 | break; |
| 391 | } |
| 392 | c++; |
| 393 | w += (double) _text->getFont()->getCharSize(*i).w / 2 * scaleX; |
| 394 | } |
| 395 | _caretPos = c; |
| 396 | } |
| 397 | } |
| 398 | InteractiveSurface::mousePress(action, state); |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Changes the text edit according to keyboard input, and |
nothing calls this directly
no test coverage detected