CComponent.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * CComponent.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 "CComponent.h"
  12. #include "Images.h"
  13. #include "../GameEngine.h"
  14. #include "../gui/CursorHandler.h"
  15. #include "../gui/TextAlignment.h"
  16. #include "../gui/Shortcut.h"
  17. #include "../render/Canvas.h"
  18. #include "../render/IFont.h"
  19. #include "../render/IRenderHandler.h"
  20. #include "../render/Graphics.h"
  21. #include "../windows/CMessage.h"
  22. #include "../windows/InfoWindows.h"
  23. #include "../widgets/TextControls.h"
  24. #include "../../lib/ArtifactUtils.h"
  25. #include "../../lib/entities/building/CBuilding.h"
  26. #include "../../lib/entities/faction/CFaction.h"
  27. #include "../../lib/entities/faction/CTown.h"
  28. #include "../../lib/entities/faction/CTownHandler.h"
  29. #include "../../lib/networkPacks/Component.h"
  30. #include "../../lib/spells/CSpellHandler.h"
  31. #include "../../lib/CCreatureHandler.h"
  32. #include "../../lib/CSkillHandler.h"
  33. #include "../../lib/texts/CGeneralTextHandler.h"
  34. #include "../../lib/CArtHandler.h"
  35. #include "../../lib/CArtifactInstance.h"
  36. #include "../../lib/GameLibrary.h"
  37. #include <vcmi/spells/Service.h>
  38. #include <vcmi/spells/Spell.h>
  39. #include <vcmi/HeroTypeService.h>
  40. #include <vcmi/HeroType.h>
  41. CComponent::CComponent(ComponentType Type, ComponentSubType Subtype, std::optional<int32_t> Val, ESize imageSize, EFonts font)
  42. {
  43. init(Type, Subtype, Val, imageSize, font, "");
  44. }
  45. CComponent::CComponent(ComponentType Type, ComponentSubType Subtype, const std::string & Val, ESize imageSize, EFonts font)
  46. {
  47. init(Type, Subtype, std::nullopt, imageSize, font, Val);
  48. }
  49. CComponent::CComponent(const Component & c, ESize imageSize, EFonts font)
  50. {
  51. init(c.type, c.subType, c.value, imageSize, font, "");
  52. }
  53. void CComponent::init(ComponentType Type, ComponentSubType Subtype, std::optional<int32_t> Val, ESize imageSize, EFonts fnt, const std::string & ValText)
  54. {
  55. OBJECT_CONSTRUCTION;
  56. addUsedEvents(SHOW_POPUP);
  57. data.type = Type;
  58. data.subType = Subtype;
  59. data.value = Val;
  60. customSubtitle = ValText;
  61. size = imageSize;
  62. font = fnt;
  63. newLine = false;
  64. assert(size < sizeInvalid);
  65. setSurface(getFileName()[size], (int)getIndex());
  66. pos.w = image->pos.w;
  67. pos.h = image->pos.h;
  68. if (imageSize < small)
  69. font = FONT_TINY; //for tiny images - tiny font
  70. pos.h += 4; //distance between text and image
  71. // WARNING: too low values will lead to bad line-breaks in CPlayerOptionTooltipBox - check right-click on starting town in pregame
  72. int max = 80;
  73. if (size < large)
  74. max = 72;
  75. if (size < medium)
  76. max = 60;
  77. if (size < small)
  78. max = 55;
  79. if(Type == ComponentType::RESOURCE && !ValText.empty())
  80. max = 80;
  81. std::vector<std::string> textLines = CMessage::breakText(getSubtitle(), std::max<int>(max, pos.w), font);
  82. const auto & fontPtr = ENGINE->renderHandler().loadFont(font);
  83. const int height = static_cast<int>(fontPtr->getLineHeight());
  84. for(auto & line : textLines)
  85. {
  86. auto label = std::make_shared<CLabel>(pos.w/2, pos.h + height/2, font, ETextAlignment::CENTER, Colors::WHITE, line);
  87. pos.h += height;
  88. if(label->pos.w > pos.w)
  89. {
  90. pos.x -= (label->pos.w - pos.w)/2;
  91. pos.w = label->pos.w;
  92. }
  93. lines.push_back(label);
  94. }
  95. }
  96. std::vector<AnimationPath> CComponent::getFileName() const
  97. {
  98. static const std::array<std::string, 4> primSkillsArr = {"PSKIL32", "PSKIL32", "PSKIL42", "PSKILL"};
  99. static const std::array<std::string, 4> secSkillsArr = {"SECSK32", "SECSK32", "SECSKILL", "SECSK82"};
  100. static const std::array<std::string, 4> resourceArr = {"SMALRES", "RESOURCE", "RESOURCE", "RESOUR82"};
  101. static const std::array<std::string, 4> creatureArr = {"CPRSMALL", "CPRSMALL", "CPRSMALL", "TWCRPORT"};
  102. static const std::array<std::string, 4> artifactArr = {"Artifact", "Artifact", "Artifact", "Artifact"};
  103. static const std::array<std::string, 4> spellsArr = {"SpellInt", "SpellInt", "SpellInt", "SPELLSCR"};
  104. static const std::array<std::string, 4> moraleArr = {"IMRL22", "IMRL30", "IMRL42", "imrl82"};
  105. static const std::array<std::string, 4> luckArr = {"ILCK22", "ILCK30", "ILCK42", "ilck82"};
  106. static const std::array<std::string, 4> heroArr = {"PortraitsSmall", "PortraitsSmall", "PortraitsSmall", "PortraitsLarge"};
  107. static const std::array<std::string, 4> flagArr = {"CREST58", "CREST58", "CREST58", "CREST58"};
  108. auto gen = [](const std::array<std::string, 4> & arr) -> std::vector<AnimationPath>
  109. {
  110. return { AnimationPath::builtin(arr[0]), AnimationPath::builtin(arr[1]), AnimationPath::builtin(arr[2]), AnimationPath::builtin(arr[3]) };
  111. };
  112. switch(data.type)
  113. {
  114. case ComponentType::PRIM_SKILL:
  115. case ComponentType::EXPERIENCE:
  116. case ComponentType::MANA:
  117. case ComponentType::LEVEL:
  118. return gen(primSkillsArr);
  119. case ComponentType::NONE:
  120. case ComponentType::SEC_SKILL:
  121. return gen(secSkillsArr);
  122. case ComponentType::RESOURCE:
  123. case ComponentType::RESOURCE_PER_DAY:
  124. return gen(resourceArr);
  125. case ComponentType::CREATURE:
  126. return gen(creatureArr);
  127. case ComponentType::ARTIFACT:
  128. return gen(artifactArr);
  129. case ComponentType::SPELL_SCROLL:
  130. case ComponentType::SPELL:
  131. return gen(spellsArr);
  132. case ComponentType::MORALE:
  133. return gen(moraleArr);
  134. case ComponentType::LUCK:
  135. return gen(luckArr);
  136. case ComponentType::BUILDING:
  137. return std::vector<AnimationPath>(4, (*LIBRARY->townh)[data.subType.as<BuildingTypeUniqueID>().getFaction()]->town->clientInfo.buildingsIcons);
  138. case ComponentType::HERO_PORTRAIT:
  139. return gen(heroArr);
  140. case ComponentType::FLAG:
  141. return gen(flagArr);
  142. default:
  143. assert(0);
  144. return {};
  145. }
  146. }
  147. size_t CComponent::getIndex() const
  148. {
  149. switch(data.type)
  150. {
  151. case ComponentType::NONE:
  152. return 0;
  153. case ComponentType::PRIM_SKILL:
  154. return data.subType.getNum();
  155. case ComponentType::EXPERIENCE:
  156. case ComponentType::LEVEL:
  157. return 4; // for whatever reason, in H3 experience icon is located in primary skills icons
  158. case ComponentType::MANA:
  159. return 5; // for whatever reason, in H3 mana points icon is located in primary skills icons
  160. case ComponentType::SEC_SKILL:
  161. return data.subType.getNum() * 3 + 3 + data.value.value_or(0) - 1;
  162. case ComponentType::RESOURCE:
  163. case ComponentType::RESOURCE_PER_DAY:
  164. return data.subType.getNum();
  165. case ComponentType::CREATURE:
  166. return LIBRARY->creatures()->getById(data.subType.as<CreatureID>())->getIconIndex();
  167. case ComponentType::ARTIFACT:
  168. return LIBRARY->artifacts()->getById(data.subType.as<ArtifactID>())->getIconIndex();
  169. case ComponentType::SPELL_SCROLL:
  170. case ComponentType::SPELL:
  171. return (size < large) ? data.subType.getNum() + 1 : data.subType.getNum();
  172. case ComponentType::MORALE:
  173. return data.value.value_or(0) + 3;
  174. case ComponentType::LUCK:
  175. return data.value.value_or(0) + 3;
  176. case ComponentType::BUILDING:
  177. return data.subType.as<BuildingTypeUniqueID>().getBuilding();
  178. case ComponentType::HERO_PORTRAIT:
  179. return LIBRARY->heroTypes()->getById(data.subType.as<HeroTypeID>())->getIconIndex();
  180. case ComponentType::FLAG:
  181. return data.subType.getNum();
  182. default:
  183. assert(0);
  184. return 0;
  185. }
  186. }
  187. std::string CComponent::getDescription() const
  188. {
  189. switch(data.type)
  190. {
  191. case ComponentType::PRIM_SKILL:
  192. return LIBRARY->generaltexth->arraytxt[2+data.subType.getNum()];
  193. case ComponentType::EXPERIENCE:
  194. case ComponentType::LEVEL:
  195. return LIBRARY->generaltexth->allTexts[241];
  196. case ComponentType::MANA:
  197. return LIBRARY->generaltexth->allTexts[149];
  198. case ComponentType::SEC_SKILL:
  199. return LIBRARY->skillh->getByIndex(data.subType.getNum())->getDescriptionTranslated(data.value.value_or(0));
  200. case ComponentType::RESOURCE:
  201. case ComponentType::RESOURCE_PER_DAY:
  202. return LIBRARY->generaltexth->allTexts[242];
  203. case ComponentType::NONE:
  204. case ComponentType::CREATURE:
  205. return "";
  206. case ComponentType::ARTIFACT:
  207. return LIBRARY->artifacts()->getById(data.subType.as<ArtifactID>())->getDescriptionTranslated();
  208. case ComponentType::SPELL_SCROLL:
  209. {
  210. auto description = ArtifactID(ArtifactID::SPELL_SCROLL).toEntity(LIBRARY)->getDescriptionTranslated();
  211. ArtifactUtils::insertScrrollSpellName(description, data.subType.as<SpellID>());
  212. return description;
  213. }
  214. case ComponentType::SPELL:
  215. return LIBRARY->spells()->getById(data.subType.as<SpellID>())->getDescriptionTranslated(std::max(0, data.value.value_or(0)));
  216. case ComponentType::MORALE:
  217. return LIBRARY->generaltexth->heroscrn[ 4 - (data.value.value_or(0)>0) + (data.value.value_or(0)<0)];
  218. case ComponentType::LUCK:
  219. return LIBRARY->generaltexth->heroscrn[ 7 - (data.value.value_or(0)>0) + (data.value.value_or(0)<0)];
  220. case ComponentType::BUILDING:
  221. {
  222. auto index = data.subType.as<BuildingTypeUniqueID>();
  223. return (*LIBRARY->townh)[index.getFaction()]->town->buildings[index.getBuilding()]->getDescriptionTranslated();
  224. }
  225. case ComponentType::HERO_PORTRAIT:
  226. return "";
  227. case ComponentType::FLAG:
  228. return "";
  229. default:
  230. assert(0);
  231. return "";
  232. }
  233. }
  234. std::string CComponent::getSubtitle() const
  235. {
  236. if (!customSubtitle.empty())
  237. return customSubtitle;
  238. switch(data.type)
  239. {
  240. case ComponentType::PRIM_SKILL:
  241. if (data.value)
  242. return boost::str(boost::format("%+d %s") % data.value.value_or(0) % LIBRARY->generaltexth->primarySkillNames[data.subType.getNum()]);
  243. else
  244. return LIBRARY->generaltexth->primarySkillNames[data.subType.getNum()];
  245. case ComponentType::EXPERIENCE:
  246. return std::to_string(data.value.value_or(0));
  247. case ComponentType::LEVEL:
  248. {
  249. std::string level = LIBRARY->generaltexth->allTexts[442];
  250. boost::replace_first(level, "1", std::to_string(data.value.value_or(0)));
  251. return level;
  252. }
  253. case ComponentType::MANA:
  254. return boost::str(boost::format("%+d %s") % data.value.value_or(0) % LIBRARY->generaltexth->allTexts[387]);
  255. case ComponentType::SEC_SKILL:
  256. return LIBRARY->generaltexth->levels[data.value.value_or(0)-1] + "\n" + LIBRARY->skillh->getById(data.subType.as<SecondarySkill>())->getNameTranslated();
  257. case ComponentType::RESOURCE:
  258. return std::to_string(data.value.value_or(0));
  259. case ComponentType::RESOURCE_PER_DAY:
  260. return boost::str(boost::format(LIBRARY->generaltexth->allTexts[3]) % data.value.value_or(0));
  261. case ComponentType::CREATURE:
  262. {
  263. auto creature = LIBRARY->creh->getById(data.subType.as<CreatureID>());
  264. if(data.value)
  265. return std::to_string(*data.value) + " " + (*data.value > 1 ? creature->getNamePluralTranslated() : creature->getNameSingularTranslated());
  266. else
  267. return creature->getNamePluralTranslated();
  268. }
  269. case ComponentType::ARTIFACT:
  270. return LIBRARY->artifacts()->getById(data.subType.as<ArtifactID>())->getNameTranslated();
  271. case ComponentType::SPELL_SCROLL:
  272. case ComponentType::SPELL:
  273. if (data.value.value_or(0) < 0)
  274. return "{#A9A9A9|" + LIBRARY->spells()->getById(data.subType.as<SpellID>())->getNameTranslated() + "}";
  275. else
  276. return LIBRARY->spells()->getById(data.subType.as<SpellID>())->getNameTranslated();
  277. case ComponentType::NONE:
  278. case ComponentType::MORALE:
  279. case ComponentType::LUCK:
  280. case ComponentType::HERO_PORTRAIT:
  281. return "";
  282. case ComponentType::BUILDING:
  283. {
  284. auto index = data.subType.as<BuildingTypeUniqueID>();
  285. auto building = (*LIBRARY->townh)[index.getFaction()]->town->buildings[index.getBuilding()];
  286. if(!building)
  287. {
  288. logGlobal->error("Town of faction %s has no building #%d", (*LIBRARY->townh)[index.getFaction()]->town->faction->getNameTranslated(), index.getBuilding().getNum());
  289. return (boost::format("Missing building #%d") % index.getBuilding().getNum()).str();
  290. }
  291. return building->getNameTranslated();
  292. }
  293. case ComponentType::FLAG:
  294. return LIBRARY->generaltexth->capColors[data.subType.as<PlayerColor>().getNum()];
  295. default:
  296. assert(0);
  297. return "";
  298. }
  299. }
  300. void CComponent::setSurface(const AnimationPath & defName, int imgPos)
  301. {
  302. OBJECT_CONSTRUCTION;
  303. image = std::make_shared<CAnimImage>(defName, imgPos);
  304. }
  305. void CComponent::showPopupWindow(const Point & cursorPosition)
  306. {
  307. if(!getDescription().empty())
  308. CRClickPopup::createAndPush(getDescription());
  309. }
  310. void CSelectableComponent::clickPressed(const Point & cursorPosition)
  311. {
  312. if(onSelect)
  313. onSelect();
  314. }
  315. void CSelectableComponent::clickDouble(const Point & cursorPosition)
  316. {
  317. if (!selected)
  318. {
  319. clickPressed(cursorPosition);
  320. }
  321. else
  322. {
  323. if (onChoose)
  324. onChoose();
  325. }
  326. }
  327. void CSelectableComponent::init()
  328. {
  329. selected = false;
  330. }
  331. CSelectableComponent::CSelectableComponent(const Component &c, std::function<void()> OnSelect):
  332. CComponent(c),onSelect(OnSelect)
  333. {
  334. setRedrawParent(true);
  335. addUsedEvents(LCLICK | DOUBLECLICK | KEYBOARD);
  336. init();
  337. }
  338. CSelectableComponent::CSelectableComponent(ComponentType Type, ComponentSubType Sub, int Val, ESize imageSize, std::function<void()> OnSelect):
  339. CComponent(Type,Sub,Val, imageSize),onSelect(OnSelect)
  340. {
  341. setRedrawParent(true);
  342. addUsedEvents(LCLICK | DOUBLECLICK | KEYBOARD);
  343. init();
  344. }
  345. void CSelectableComponent::select(bool on)
  346. {
  347. if(on != selected)
  348. {
  349. selected = on;
  350. redraw();
  351. }
  352. }
  353. void CSelectableComponent::showAll(Canvas & to)
  354. {
  355. CComponent::showAll(to);
  356. if(selected)
  357. {
  358. to.drawBorder(Rect::createAround(image->pos, 1), Colors::BRIGHT_YELLOW);
  359. }
  360. }
  361. void CComponentBox::selectionChanged(std::shared_ptr<CSelectableComponent> newSelection)
  362. {
  363. if (newSelection == selected)
  364. return;
  365. if (selected)
  366. selected->select(false);
  367. selected = newSelection;
  368. if (onSelect)
  369. onSelect(selectedIndex());
  370. if (selected)
  371. selected->select(true);
  372. }
  373. int CComponentBox::selectedIndex()
  374. {
  375. if (selected)
  376. return static_cast<int>(std::find(components.begin(), components.end(), selected) - components.begin());
  377. return -1;
  378. }
  379. Point CComponentBox::getOrTextPos(CComponent *left, CComponent *right)
  380. {
  381. int leftSubtitle = ( left->pos.w - left->image->pos.w) / 2;
  382. int rightSubtitle = (right->pos.w - right->image->pos.w) / 2;
  383. int fullDistance = getDistance(left, right) + leftSubtitle + rightSubtitle;
  384. return Point(fullDistance/2 - leftSubtitle, (left->image->pos.h + right->image->pos.h) / 4);
  385. }
  386. int CComponentBox::getDistance(CComponent *left, CComponent *right)
  387. {
  388. int leftSubtitle = ( left->pos.w - left->image->pos.w) / 2;
  389. int rightSubtitle = (right->pos.w - right->image->pos.w) / 2;
  390. int subtitlesOffset = leftSubtitle + rightSubtitle;
  391. return std::max(betweenSubtitlesMin, betweenImagesMin - subtitlesOffset);
  392. }
  393. void CComponentBox::placeComponents(bool selectable)
  394. {
  395. OBJECT_CONSTRUCTION;
  396. if (components.empty())
  397. return;
  398. //prepare components
  399. for(auto & comp : components)
  400. {
  401. addChild(comp.get());
  402. comp->moveTo(Point(pos.x, pos.y));
  403. }
  404. struct RowData
  405. {
  406. size_t comps;
  407. int width;
  408. int height;
  409. RowData (size_t Comps, int Width, int Height):
  410. comps(Comps), width (Width), height (Height){};
  411. };
  412. std::vector<RowData> rows;
  413. rows.push_back (RowData (0,0,0));
  414. //split components in rows
  415. std::shared_ptr<CComponent> prevComp;
  416. for(std::shared_ptr<CComponent> comp : components)
  417. {
  418. //make sure that components are smaller than our width
  419. //assert(pos.w == 0 || pos.w < comp->pos.w);
  420. const int distance = prevComp ? getDistance(prevComp.get(), comp.get()) : 0;
  421. //start next row
  422. if ((pos.w != 0 && rows.back().width + comp->pos.w + distance > pos.w) // row is full
  423. || rows.back().comps >= componentsInRow
  424. || (prevComp && prevComp->newLine))
  425. {
  426. prevComp = nullptr;
  427. rows.push_back (RowData (0,0,0));
  428. }
  429. if (prevComp)
  430. rows.back().width += distance;
  431. rows.back().comps++;
  432. rows.back().width += comp->pos.w;
  433. vstd::amax(rows.back().height, comp->pos.h);
  434. prevComp = comp;
  435. }
  436. if (pos.w == 0)
  437. {
  438. for(auto & row : rows)
  439. vstd::amax(pos.w, row.width);
  440. }
  441. int height = ((int)rows.size() - 1) * betweenRows;
  442. for(auto & row : rows)
  443. height += row.height;
  444. //assert(pos.h == 0 || pos.h < height);
  445. if (pos.h == 0)
  446. pos.h = height;
  447. auto iter = components.begin();
  448. int currentY = (pos.h - height) / 2;
  449. //move components to their positions
  450. for (auto & rows_row : rows)
  451. {
  452. // amount of free space we may add on each side of every component
  453. int freeSpace = (pos.w - rows_row.width) / ((int)rows_row.comps * 2);
  454. prevComp = nullptr;
  455. int currentX = 0;
  456. for (size_t col = 0; col < rows_row.comps; col++)
  457. {
  458. currentX += freeSpace;
  459. if (prevComp)
  460. {
  461. if (selectable)
  462. {
  463. Point orPos = Point(currentX - freeSpace, currentY) + getOrTextPos(prevComp.get(), iter->get());
  464. orLabels.push_back(std::make_shared<CLabel>(orPos.x, orPos.y, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->allTexts[4]));
  465. }
  466. currentX += getDistance(prevComp.get(), iter->get());
  467. }
  468. (*iter)->moveBy(Point(currentX, currentY));
  469. currentX += (*iter)->pos.w;
  470. currentX += freeSpace;
  471. prevComp = *(iter++);
  472. }
  473. currentY += rows_row.height + betweenRows;
  474. }
  475. }
  476. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position):
  477. CComponentBox(_components, position, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
  478. {
  479. }
  480. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
  481. components(_components),
  482. betweenImagesMin(betweenImagesMin),
  483. betweenSubtitlesMin(betweenSubtitlesMin),
  484. betweenRows(betweenRows),
  485. componentsInRow(componentsInRow)
  486. {
  487. setRedrawParent(true);
  488. pos = position + pos.topLeft();
  489. placeComponents(false);
  490. }
  491. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect):
  492. CComponentBox(_components, position, _onSelect, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
  493. {
  494. }
  495. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
  496. components(_components.begin(), _components.end()),
  497. onSelect(_onSelect),
  498. betweenImagesMin(betweenImagesMin),
  499. betweenSubtitlesMin(betweenSubtitlesMin),
  500. betweenRows(betweenRows),
  501. componentsInRow(componentsInRow)
  502. {
  503. setRedrawParent(true);
  504. pos = position + pos.topLeft();
  505. placeComponents(true);
  506. assert(!components.empty());
  507. auto key = EShortcut::SELECT_INDEX_1;
  508. for(auto & comp : _components)
  509. {
  510. comp->onSelect = std::bind(&CComponentBox::selectionChanged, this, comp);
  511. comp->assignedKey = key;
  512. key = vstd::next(key, 1);
  513. }
  514. selectionChanged(_components.front());
  515. }