MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / mousePress

Method mousePress

src/Interface/TextEdit.cpp:367–399  ·  view source on GitHub ↗

* Focuses the text edit when it's pressed on. * @param action Pointer to an action. * @param state State that the action handlers belong to. */

Source from the content-addressed store, hash-verified

365 * @param state State that the action handlers belong to.
366 */
367void 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

Callers

nothing calls this directly

Calls 5

getDetailsMethod · 0.80
getRelativeXMouseMethod · 0.80
getCharSizeMethod · 0.80
getXScaleMethod · 0.45
getFontMethod · 0.45

Tested by

no test coverage detected