TextControls.cpp 16 KB

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