TextControls.cpp 16 KB

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