TextControls.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /*
  2. * TextControls.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "TextControls.h"
  12. #include "Slider.h"
  13. #include "Images.h"
  14. #include "../CPlayerInterface.h"
  15. #include "../gui/CGuiHandler.h"
  16. #include "../gui/Shortcut.h"
  17. #include "../windows/CMessage.h"
  18. #include "../adventureMap/CInGameConsole.h"
  19. #include "../renderSDL/SDL_Extensions.h"
  20. #include "../render/Canvas.h"
  21. #include "../../lib/TextOperations.h"
  22. #ifdef VCMI_ANDROID
  23. #include "lib/CAndroidVMHelper.h"
  24. #endif
  25. std::list<CFocusable*> CFocusable::focusables;
  26. CFocusable * CFocusable::inputWithFocus;
  27. std::string CLabel::visibleText()
  28. {
  29. return text;
  30. }
  31. void CLabel::showAll(Canvas & to)
  32. {
  33. CIntObject::showAll(to);
  34. if(!visibleText().empty())
  35. blitLine(to, pos, visibleText());
  36. }
  37. CLabel::CLabel(int x, int y, EFonts Font, ETextAlignment Align, const SDL_Color & Color, const std::string & Text)
  38. : CTextContainer(Align, Font, Color), text(Text)
  39. {
  40. type |= REDRAW_PARENT;
  41. autoRedraw = true;
  42. pos.x += x;
  43. pos.y += y;
  44. pos.w = pos.h = 0;
  45. if(alignment == ETextAlignment::TOPLEFT) // causes issues for MIDDLE
  46. {
  47. pos.w = (int)graphics->fonts[font]->getStringWidth(visibleText().c_str());
  48. pos.h = (int)graphics->fonts[font]->getLineHeight();
  49. }
  50. }
  51. Point CLabel::getBorderSize()
  52. {
  53. return Point(0, 0);
  54. }
  55. std::string CLabel::getText()
  56. {
  57. return text;
  58. }
  59. void CLabel::setAutoRedraw(bool value)
  60. {
  61. autoRedraw = value;
  62. }
  63. void CLabel::setText(const std::string & Txt)
  64. {
  65. text = Txt;
  66. if(autoRedraw)
  67. {
  68. if(background || !parent)
  69. redraw();
  70. else
  71. parent->redraw();
  72. }
  73. }
  74. void CLabel::setColor(const SDL_Color & Color)
  75. {
  76. color = Color;
  77. if(autoRedraw)
  78. {
  79. if(background || !parent)
  80. redraw();
  81. else
  82. parent->redraw();
  83. }
  84. }
  85. size_t CLabel::getWidth()
  86. {
  87. return graphics->fonts[font]->getStringWidth(visibleText());;
  88. }
  89. CMultiLineLabel::CMultiLineLabel(Rect position, EFonts Font, ETextAlignment Align, const SDL_Color & Color, const std::string & Text) :
  90. CLabel(position.x, position.y, Font, Align, Color, Text),
  91. visibleSize(0, 0, position.w, position.h)
  92. {
  93. pos.w = position.w;
  94. pos.h = position.h;
  95. splitText(Text, true);
  96. }
  97. void CMultiLineLabel::setVisibleSize(Rect visibleSize, bool redrawElement)
  98. {
  99. this->visibleSize = visibleSize;
  100. if(redrawElement)
  101. redraw();
  102. }
  103. void CMultiLineLabel::scrollTextBy(int distance)
  104. {
  105. scrollTextTo(visibleSize.y + distance);
  106. }
  107. void CMultiLineLabel::scrollTextTo(int distance, bool redrawAfterScroll)
  108. {
  109. Rect size = visibleSize;
  110. size.y = distance;
  111. setVisibleSize(size, redrawAfterScroll);
  112. }
  113. void CMultiLineLabel::setText(const std::string & Txt)
  114. {
  115. splitText(Txt, false); //setText used below can handle redraw
  116. CLabel::setText(Txt);
  117. }
  118. void CTextContainer::blitLine(Canvas & to, Rect destRect, std::string what)
  119. {
  120. const auto f = graphics->fonts[font];
  121. Point where = destRect.topLeft();
  122. const std::string delimeters = "{}";
  123. auto delimitersCount = std::count_if(what.cbegin(), what.cend(), [&delimeters](char c)
  124. {
  125. return delimeters.find(c) != std::string::npos;
  126. });
  127. //We should count delimiters length from string to correct centering later.
  128. delimitersCount *= f->getStringWidth(delimeters)/2;
  129. // input is rect in which given text should be placed
  130. // calculate proper position for top-left corner of the text
  131. if(alignment == ETextAlignment::TOPLEFT)
  132. {
  133. where.x += getBorderSize().x;
  134. where.y += getBorderSize().y;
  135. }
  136. if(alignment == ETextAlignment::CENTER)
  137. {
  138. where.x += (int(destRect.w) - int(f->getStringWidth(what) - delimitersCount)) / 2;
  139. where.y += (int(destRect.h) - int(f->getLineHeight())) / 2;
  140. }
  141. if(alignment == ETextAlignment::BOTTOMRIGHT)
  142. {
  143. where.x += getBorderSize().x + destRect.w - ((int)f->getStringWidth(what) - delimitersCount);
  144. where.y += getBorderSize().y + destRect.h - (int)f->getLineHeight();
  145. }
  146. size_t begin = 0;
  147. size_t currDelimeter = 0;
  148. do
  149. {
  150. size_t end = what.find_first_of(delimeters[currDelimeter % 2], begin);
  151. if(begin != end)
  152. {
  153. std::string toPrint = what.substr(begin, end - begin);
  154. if(currDelimeter % 2) // Enclosed in {} text - set to yellow
  155. to.drawText(where, font, Colors::YELLOW, ETextAlignment::TOPLEFT, toPrint);
  156. else // Non-enclosed text, use default color
  157. to.drawText(where, font, color, ETextAlignment::TOPLEFT, toPrint);
  158. begin = end;
  159. where.x += (int)f->getStringWidth(toPrint);
  160. }
  161. currDelimeter++;
  162. } while(begin++ != std::string::npos);
  163. }
  164. CTextContainer::CTextContainer(ETextAlignment alignment, EFonts font, SDL_Color color) :
  165. alignment(alignment),
  166. font(font),
  167. color(color)
  168. {
  169. }
  170. void CMultiLineLabel::showAll(Canvas & to)
  171. {
  172. CIntObject::showAll(to);
  173. const auto f = graphics->fonts[font];
  174. // calculate which lines should be visible
  175. int totalLines = static_cast<int>(lines.size());
  176. int beginLine = visibleSize.y;
  177. int endLine = getTextLocation().h + visibleSize.y;
  178. if(beginLine < 0)
  179. beginLine = 0;
  180. else
  181. beginLine /= (int)f->getLineHeight();
  182. if(endLine < 0)
  183. endLine = 0;
  184. else
  185. endLine /= (int)f->getLineHeight();
  186. endLine++;
  187. // and where they should be displayed
  188. Point lineStart = getTextLocation().topLeft() - visibleSize + Point(0, beginLine * (int)f->getLineHeight());
  189. Point lineSize = Point(getTextLocation().w, (int)f->getLineHeight());
  190. CSDL_Ext::CClipRectGuard guard(to.getInternalSurface(), getTextLocation()); // to properly trim text that is too big to fit
  191. for(int i = beginLine; i < std::min(totalLines, endLine); i++)
  192. {
  193. if(!lines[i].empty()) //non-empty line
  194. blitLine(to, Rect(lineStart, lineSize), lines[i]);
  195. lineStart.y += (int)f->getLineHeight();
  196. }
  197. }
  198. void CMultiLineLabel::splitText(const std::string & Txt, bool redrawAfter)
  199. {
  200. lines.clear();
  201. const auto f = graphics->fonts[font];
  202. int lineHeight = static_cast<int>(f->getLineHeight());
  203. lines = CMessage::breakText(Txt, pos.w, font);
  204. textSize.y = lineHeight * (int)lines.size();
  205. textSize.x = 0;
  206. for(const std::string & line : lines)
  207. vstd::amax(textSize.x, f->getStringWidth(line.c_str()));
  208. if(redrawAfter)
  209. redraw();
  210. }
  211. Rect CMultiLineLabel::getTextLocation()
  212. {
  213. // this method is needed for vertical alignment alignment of text
  214. // when height of available text is smaller than height of widget
  215. // in this case - we should add proper offset to display text at required position
  216. if(pos.h <= textSize.y)
  217. return pos;
  218. Point textSize(pos.w, (int)graphics->fonts[font]->getLineHeight() * (int)lines.size());
  219. Point textOffset(pos.w - textSize.x, pos.h - textSize.y);
  220. switch(alignment)
  221. {
  222. case ETextAlignment::TOPLEFT: return Rect(pos.topLeft(), textSize);
  223. case ETextAlignment::CENTER: return Rect(pos.topLeft() + textOffset / 2, textSize);
  224. case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSize);
  225. }
  226. assert(0);
  227. return Rect();
  228. }
  229. CLabelGroup::CLabelGroup(EFonts Font, ETextAlignment Align, const SDL_Color & Color)
  230. : font(Font), align(Align), color(Color)
  231. {
  232. defActions = 255 - DISPOSE;
  233. }
  234. void CLabelGroup::add(int x, int y, const std::string & text)
  235. {
  236. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
  237. labels.push_back(std::make_shared<CLabel>(x, y, font, align, color, text));
  238. }
  239. size_t CLabelGroup::currentSize() const
  240. {
  241. return labels.size();
  242. }
  243. CTextBox::CTextBox(std::string Text, const Rect & rect, int SliderStyle, EFonts Font, ETextAlignment Align, const SDL_Color & Color) :
  244. sliderStyle(SliderStyle),
  245. slider(nullptr)
  246. {
  247. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  248. label = std::make_shared<CMultiLineLabel>(rect, Font, Align, Color);
  249. type |= REDRAW_PARENT;
  250. pos.x += rect.x;
  251. pos.y += rect.y;
  252. pos.h = rect.h;
  253. pos.w = rect.w;
  254. assert(pos.w >= 40); //we need some space
  255. setText(Text);
  256. }
  257. void CTextBox::sliderMoved(int to)
  258. {
  259. label->scrollTextTo(to);
  260. }
  261. void CTextBox::resize(Point newSize)
  262. {
  263. pos.w = newSize.x;
  264. pos.h = newSize.y;
  265. label->pos.w = pos.w;
  266. label->pos.h = pos.h;
  267. slider.reset();
  268. setText(label->getText()); // force refresh
  269. }
  270. void CTextBox::setText(const std::string & text)
  271. {
  272. label->pos.w = pos.w; // reset to default before textSize.y check
  273. label->setText(text);
  274. if(label->textSize.y <= label->pos.h && slider)
  275. {
  276. // slider is no longer needed
  277. slider.reset();
  278. }
  279. else if(slider)
  280. {
  281. // decrease width again if slider still used
  282. label->pos.w = pos.w - 32;
  283. label->setText(text);
  284. slider->setAmount(label->textSize.y);
  285. }
  286. else if(label->textSize.y > label->pos.h)
  287. {
  288. // create slider and update widget
  289. label->pos.w = pos.w - 32;
  290. label->setText(text);
  291. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
  292. slider = std::make_shared<CSlider>(Point(pos.w - 32, 0), pos.h, std::bind(&CTextBox::sliderMoved, this, _1),
  293. label->pos.h, label->textSize.y, 0, false, CSlider::EStyle(sliderStyle));
  294. slider->setScrollStep((int)graphics->fonts[label->font]->getLineHeight());
  295. }
  296. }
  297. void CGStatusBar::setEnteringMode(bool on)
  298. {
  299. consoleText.clear();
  300. if (on)
  301. {
  302. //assert(enteringText == false);
  303. alignment = ETextAlignment::TOPLEFT;
  304. GH.startTextInput(pos);
  305. setText(consoleText);
  306. }
  307. else
  308. {
  309. //assert(enteringText == true);
  310. alignment = ETextAlignment::CENTER;
  311. GH.stopTextInput();
  312. setText(hoverText);
  313. }
  314. enteringText = on;
  315. }
  316. void CGStatusBar::setEnteredText(const std::string & text)
  317. {
  318. assert(enteringText == true);
  319. consoleText = text;
  320. setText(text);
  321. }
  322. void CGStatusBar::write(const std::string & Text)
  323. {
  324. hoverText = Text;
  325. if (enteringText == false)
  326. setText(hoverText);
  327. }
  328. void CGStatusBar::clearIfMatching(const std::string & Text)
  329. {
  330. if (hoverText == Text)
  331. clear();
  332. }
  333. void CGStatusBar::clear()
  334. {
  335. write({});
  336. }
  337. CGStatusBar::CGStatusBar(std::shared_ptr<CIntObject> background_, EFonts Font, ETextAlignment Align, const SDL_Color & Color)
  338. : CLabel(background_->pos.x, background_->pos.y, Font, Align, Color, "")
  339. , enteringText(false)
  340. {
  341. addUsedEvents(LCLICK);
  342. background = background_;
  343. addChild(background.get());
  344. pos = background->pos;
  345. getBorderSize();
  346. autoRedraw = false;
  347. }
  348. CGStatusBar::CGStatusBar(int x, int y, std::string name, int maxw)
  349. : CLabel(x, y, FONT_SMALL, ETextAlignment::CENTER)
  350. , enteringText(false)
  351. {
  352. addUsedEvents(LCLICK);
  353. OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
  354. auto backgroundImage = std::make_shared<CPicture>(name);
  355. background = backgroundImage;
  356. pos = background->pos;
  357. if((unsigned)maxw < (unsigned)pos.w) //(insigned)-1 > than any correct value of pos.w
  358. {
  359. //execution of this block when maxw is incorrect breaks text centralization (issue #3151)
  360. vstd::amin(pos.w, maxw);
  361. backgroundImage->srcRect = Rect(0, 0, maxw, pos.h);
  362. }
  363. autoRedraw = false;
  364. }
  365. CGStatusBar::~CGStatusBar()
  366. {
  367. assert(GH.statusbar().get() != this);
  368. }
  369. void CGStatusBar::show(Canvas & to)
  370. {
  371. showAll(to);
  372. }
  373. void CGStatusBar::clickLeft(tribool down, bool previousState)
  374. {
  375. if(!down)
  376. {
  377. if(LOCPLINT && LOCPLINT->cingconsole->isActive())
  378. LOCPLINT->cingconsole->startEnteringText();
  379. }
  380. }
  381. void CGStatusBar::activate()
  382. {
  383. GH.setStatusbar(shared_from_this());
  384. CIntObject::activate();
  385. }
  386. void CGStatusBar::deactivate()
  387. {
  388. assert(GH.statusbar().get() == this);
  389. GH.setStatusbar(nullptr);
  390. if (enteringText)
  391. LOCPLINT->cingconsole->endEnteringText(false);
  392. CIntObject::deactivate();
  393. }
  394. Point CGStatusBar::getBorderSize()
  395. {
  396. //Width of borders where text should not be printed
  397. static const Point borderSize(5, 1);
  398. switch(alignment)
  399. {
  400. case ETextAlignment::TOPLEFT: return Point(borderSize.x, borderSize.y);
  401. case ETextAlignment::CENTER: return Point(pos.w / 2, pos.h / 2);
  402. case ETextAlignment::BOTTOMRIGHT: return Point(pos.w - borderSize.x, pos.h - borderSize.y);
  403. }
  404. assert(0);
  405. return Point();
  406. }
  407. CTextInput::CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(const std::string &)> & CB)
  408. : CLabel(Pos.x, Pos.y, font, ETextAlignment::CENTER),
  409. cb(CB),
  410. CFocusable(std::make_shared<CKeyboardFocusListener>(this))
  411. {
  412. type |= REDRAW_PARENT;
  413. pos.h = Pos.h;
  414. pos.w = Pos.w;
  415. captureAllKeys = true;
  416. background.reset();
  417. addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
  418. #if !defined(VCMI_MOBILE)
  419. giveFocus();
  420. #endif
  421. }
  422. CTextInput::CTextInput(const Rect & Pos, const Point & bgOffset, const std::string & bgName, const CFunctionList<void(const std::string &)> & CB)
  423. :cb(CB), CFocusable(std::make_shared<CKeyboardFocusListener>(this))
  424. {
  425. pos += Pos.topLeft();
  426. pos.h = Pos.h;
  427. pos.w = Pos.w;
  428. captureAllKeys = true;
  429. OBJ_CONSTRUCTION;
  430. background = std::make_shared<CPicture>(bgName, bgOffset.x, bgOffset.y);
  431. addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
  432. #if !defined(VCMI_MOBILE)
  433. giveFocus();
  434. #endif
  435. }
  436. CTextInput::CTextInput(const Rect & Pos, std::shared_ptr<IImage> srf)
  437. :CFocusable(std::make_shared<CKeyboardFocusListener>(this))
  438. {
  439. pos += Pos.topLeft();
  440. captureAllKeys = true;
  441. OBJ_CONSTRUCTION;
  442. background = std::make_shared<CPicture>(srf, Pos);
  443. pos.w = background->pos.w;
  444. pos.h = background->pos.h;
  445. background->pos = pos;
  446. addUsedEvents(LCLICK | KEYBOARD | TEXTINPUT);
  447. #if !defined(VCMI_MOBILE)
  448. giveFocus();
  449. #endif
  450. }
  451. std::atomic<int> CKeyboardFocusListener::usageIndex(0);
  452. CKeyboardFocusListener::CKeyboardFocusListener(CTextInput * textInput)
  453. :textInput(textInput)
  454. {
  455. }
  456. void CKeyboardFocusListener::focusGot()
  457. {
  458. GH.startTextInput(textInput->pos);
  459. usageIndex++;
  460. }
  461. void CKeyboardFocusListener::focusLost()
  462. {
  463. if(0 == --usageIndex)
  464. {
  465. GH.stopTextInput();
  466. }
  467. }
  468. std::string CTextInput::visibleText()
  469. {
  470. return focus ? text + newText + "_" : text;
  471. }
  472. void CTextInput::clickLeft(tribool down, bool previousState)
  473. {
  474. if(down && !focus)
  475. giveFocus();
  476. }
  477. void CTextInput::keyPressed(EShortcut key)
  478. {
  479. if(!focus)
  480. return;
  481. if(key == EShortcut::GLOBAL_MOVE_FOCUS)
  482. {
  483. moveFocus();
  484. return;
  485. }
  486. bool redrawNeeded = false;
  487. switch(key)
  488. {
  489. case EShortcut::GLOBAL_BACKSPACE:
  490. if(!newText.empty())
  491. {
  492. TextOperations::trimRightUnicode(newText);
  493. redrawNeeded = true;
  494. }
  495. else if(!text.empty())
  496. {
  497. TextOperations::trimRightUnicode(text);
  498. redrawNeeded = true;
  499. }
  500. break;
  501. default:
  502. break;
  503. }
  504. if(redrawNeeded)
  505. {
  506. redraw();
  507. cb(text);
  508. }
  509. }
  510. void CTextInput::setText(const std::string & nText)
  511. {
  512. setText(nText, false);
  513. }
  514. void CTextInput::setText(const std::string & nText, bool callCb)
  515. {
  516. CLabel::setText(nText);
  517. if(callCb)
  518. cb(text);
  519. }
  520. bool CTextInput::captureThisKey(EShortcut key)
  521. {
  522. if(key == EShortcut::GLOBAL_RETURN)
  523. return false;
  524. if (!focus)
  525. return false;
  526. return true;
  527. }
  528. void CTextInput::textInputed(const std::string & enteredText)
  529. {
  530. if(!focus)
  531. return;
  532. std::string oldText = text;
  533. text += enteredText;
  534. filters(text, oldText);
  535. if(text != oldText)
  536. {
  537. redraw();
  538. cb(text);
  539. }
  540. newText.clear();
  541. }
  542. void CTextInput::textEdited(const std::string & enteredText)
  543. {
  544. if(!focus)
  545. return;
  546. newText = enteredText;
  547. redraw();
  548. cb(text + newText);
  549. }
  550. void CTextInput::filenameFilter(std::string & text, const std::string &)
  551. {
  552. static const std::string forbiddenChars = "<>:\"/\\|?*\r\n"; //if we are entering a filename, some special characters won't be allowed
  553. size_t pos;
  554. while((pos = text.find_first_of(forbiddenChars)) != std::string::npos)
  555. text.erase(pos, 1);
  556. }
  557. void CTextInput::numberFilter(std::string & text, const std::string & oldText, int minValue, int maxValue)
  558. {
  559. assert(minValue < maxValue);
  560. if(text.empty())
  561. text = "0";
  562. size_t pos = 0;
  563. if(text[0] == '-') //allow '-' sign as first symbol only
  564. pos++;
  565. while(pos < text.size())
  566. {
  567. if(text[pos] < '0' || text[pos] > '9')
  568. {
  569. text = oldText;
  570. return; //new text is not number.
  571. }
  572. pos++;
  573. }
  574. try
  575. {
  576. int value = boost::lexical_cast<int>(text);
  577. if(value < minValue)
  578. text = std::to_string(minValue);
  579. else if(value > maxValue)
  580. text = std::to_string(maxValue);
  581. }
  582. catch(boost::bad_lexical_cast &)
  583. {
  584. //Should never happen. Unless I missed some cases
  585. logGlobal->warn("Warning: failed to convert %s to number!", text);
  586. text = oldText;
  587. }
  588. }
  589. CFocusable::CFocusable()
  590. :CFocusable(std::make_shared<IFocusListener>())
  591. {
  592. }
  593. CFocusable::CFocusable(std::shared_ptr<IFocusListener> focusListener)
  594. : focusListener(focusListener)
  595. {
  596. focus = false;
  597. focusables.push_back(this);
  598. }
  599. CFocusable::~CFocusable()
  600. {
  601. if(hasFocus())
  602. {
  603. inputWithFocus = nullptr;
  604. focusListener->focusLost();
  605. }
  606. focusables -= this;
  607. }
  608. bool CFocusable::hasFocus() const
  609. {
  610. return inputWithFocus == this;
  611. }
  612. void CFocusable::giveFocus()
  613. {
  614. focus = true;
  615. focusListener->focusGot();
  616. redraw();
  617. if(inputWithFocus)
  618. {
  619. inputWithFocus->focus = false;
  620. inputWithFocus->focusListener->focusLost();
  621. inputWithFocus->redraw();
  622. }
  623. inputWithFocus = this;
  624. }
  625. void CFocusable::moveFocus()
  626. {
  627. auto i = vstd::find(focusables, this),
  628. ourIt = i;
  629. for(i++; i != ourIt; i++)
  630. {
  631. if(i == focusables.end())
  632. i = focusables.begin();
  633. if((*i)->isActive())
  634. {
  635. (*i)->giveFocus();
  636. break;
  637. }
  638. }
  639. }