CMessage.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. #include "StdInc.h"
  2. #include "CMessage.h"
  3. #include "SDL_ttf.h"
  4. #include "CDefHandler.h"
  5. #include "CAnimation.h"
  6. #include "CGameInfo.h"
  7. #include "UIFramework/SDL_Extensions.h"
  8. #include "../lib/CGeneralTextHandler.h"
  9. #include "Graphics.h"
  10. #include "GUIClasses.h"
  11. #include "../lib/CConfigHandler.h"
  12. #include "CBitmapHandler.h"
  13. #include "UIFramework/CIntObjectClasses.h"
  14. /*
  15. * CMessage.cpp, part of VCMI engine
  16. *
  17. * Authors: listed in file AUTHORS in main folder
  18. *
  19. * License: GNU General Public License v2.0 or later
  20. * Full text of license available in license.txt file, in main folder
  21. *
  22. */
  23. //extern SDL_Surface * screen;
  24. const int COMPONENT_TO_SUBTITLE = 17;
  25. const int BETWEEN_COMPS_ROWS = 10;
  26. const int BEFORE_COMPONENTS = 30;
  27. const int BETWEEN_COMPS = 30;
  28. const int SIDE_MARGIN = 30;
  29. template <typename T, typename U> std::pair<T,U> max(const std::pair<T,U> &x, const std::pair<T,U> &y)
  30. {
  31. std::pair<T,U> ret;
  32. ret.first = std::max(x.first,y.first);
  33. ret.second = std::max(x.second,y.second);
  34. return ret;
  35. }
  36. //One image component + subtitles below it
  37. class ComponentResolved : public CIntObject
  38. {
  39. public:
  40. CComponent *comp;
  41. //blit component with image centered at this position
  42. void showAll(SDL_Surface * to);
  43. //ComponentResolved(); //c-tor
  44. ComponentResolved(CComponent *Comp); //c-tor
  45. ~ComponentResolved(); //d-tor
  46. };
  47. // Full set of components for blitting on dialog box
  48. struct ComponentsToBlit
  49. {
  50. std::vector< std::vector<ComponentResolved*> > comps;
  51. int w, h;
  52. void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
  53. ComponentsToBlit(std::vector<CComponent*> & SComps, int maxw, SDL_Surface* _or); //c-tor
  54. ~ComponentsToBlit(); //d-tor
  55. };
  56. namespace
  57. {
  58. CDefHandler * ok, *cancel;
  59. std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  60. SDL_Surface * background = NULL;
  61. }
  62. void CMessage::init()
  63. {
  64. {
  65. piecesOfBox.resize(GameConstants::PLAYER_LIMIT);
  66. for (int i=0;i<GameConstants::PLAYER_LIMIT;i++)
  67. {
  68. CDefHandler * bluePieces = CDefHandler::giveDef("DIALGBOX.DEF");
  69. if (i==1)
  70. {
  71. for (size_t j=0;j<bluePieces->ourImages.size();++j)
  72. {
  73. piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
  74. bluePieces->ourImages[j].bitmap->refcount++;
  75. }
  76. }
  77. for (size_t j=0;j<bluePieces->ourImages.size();++j)
  78. {
  79. graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
  80. piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
  81. bluePieces->ourImages[j].bitmap->refcount++;
  82. }
  83. delete bluePieces;
  84. }
  85. background = BitmapHandler::loadBitmap("DIBOXBCK.BMP");
  86. SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255));
  87. }
  88. ok = CDefHandler::giveDef("IOKAY.DEF");
  89. cancel = CDefHandler::giveDef("ICANCEL.DEF");
  90. }
  91. void CMessage::dispose()
  92. {
  93. for (int i=0;i<GameConstants::PLAYER_LIMIT;i++)
  94. {
  95. for (size_t j=0; j<piecesOfBox[i].size(); ++j)
  96. {
  97. SDL_FreeSurface(piecesOfBox[i][j]);
  98. }
  99. }
  100. SDL_FreeSurface(background);
  101. delete ok;
  102. delete cancel;
  103. }
  104. SDL_Surface * CMessage::drawDialogBox(int w, int h, int playerColor)
  105. {
  106. //prepare surface
  107. SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
  108. for (int i=0; i<w; i+=background->w)//background
  109. {
  110. for (int j=0; j<h; j+=background->h)
  111. {
  112. Rect srcR(0,0,background->w, background->h);
  113. Rect dstR(i,j,w,h);
  114. CSDL_Ext::blitSurface(background, &srcR, ret, &dstR);
  115. }
  116. }
  117. drawBorder(playerColor, ret, w, h);
  118. return ret;
  119. }
  120. /* The map file contains long texts, with or without line breaks. This
  121. * method takes such a text and breaks it into into several lines. */
  122. std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineSize/*=30*/, const boost::function<int(char)> &charMetric /*= 0*/, bool allowLeadingWhitespace /*= false*/ )
  123. {
  124. std::vector<std::string> ret;
  125. boost::algorithm::trim_right_if(text,boost::algorithm::is_any_of(std::string(" ")));
  126. while (text.length())
  127. {
  128. ui32 lineLength = 0; //in characters or given char metric
  129. ui32 z = 0; //our position in text
  130. bool opened = false;//if we have an unclosed brace in current line
  131. bool lineManuallyBroken = false;
  132. while(z < text.length() && text[z] != 0x0a && lineLength < maxLineSize)
  133. {
  134. /* We don't count braces in string length. */
  135. if (text[z] == '{')
  136. opened=true;
  137. else if (text[z]=='}')
  138. opened=false;
  139. else if(charMetric)
  140. lineLength += charMetric(text[z]);
  141. else
  142. lineLength++;
  143. z++;
  144. }
  145. if (z < text.length() && (text[z] != 0x0a))
  146. {
  147. /* We have a long line. Try to do a nice line break, if
  148. * possible. We backtrack on the line until we find a
  149. * suitable character.
  150. * Note: Cyrillic symbols have indexes 220-255 so we need
  151. * to use ui8 for comparison
  152. */
  153. int pos = z-1;
  154. while(pos > 0 && ((ui8)text[pos]) > ' ' )
  155. pos --;
  156. if (pos > 0)
  157. z = pos+1;
  158. }
  159. if(z) //non-blank line
  160. {
  161. ret.push_back(text.substr(0, z));
  162. if (opened)
  163. /* Close the brace for the current line. */
  164. ret.back() += '}';
  165. text.erase(0, z);
  166. }
  167. else if(text[z] == 0x0a) //blank line
  168. {
  169. ret.push_back(""); //add empty string, no extra actions needed
  170. }
  171. if (text.length() && text[0] == 0x0a)
  172. {
  173. /* Braces do not carry over lines. The map author forgot
  174. * to close it. */
  175. opened = false;
  176. /* Remove LF */
  177. text.erase(0, 1);
  178. lineManuallyBroken = true;
  179. }
  180. if(!allowLeadingWhitespace || !lineManuallyBroken)
  181. boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(std::string(" ")));
  182. if (opened)
  183. {
  184. /* Add an opening brace for the next line. */
  185. if (text.length())
  186. text.insert(0, "{");
  187. }
  188. }
  189. /* Trim whitespaces of every line. */
  190. if(!allowLeadingWhitespace)
  191. for (size_t i=0; i<ret.size(); i++)
  192. boost::algorithm::trim(ret[i]);
  193. return ret;
  194. }
  195. std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWidth, EFonts font )
  196. {
  197. return breakText(text, maxLineWidth, boost::bind(&Font::getCharWidth, graphics->fonts[font], _1), true);
  198. }
  199. std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight)
  200. {
  201. std::pair<int,int> ret;
  202. ret.first = -1;
  203. ret.second=0;
  204. for (size_t i=0; i<txtg->size();i++) //we are searching widest line and total height
  205. {
  206. int lw=0;
  207. for (size_t j=0;j<(*txtg)[i].size();j++)
  208. {
  209. lw+=(*txtg)[i][j]->w;
  210. ret.second+=(*txtg)[i][j]->h;
  211. }
  212. if(!(*txtg)[i].size())
  213. ret.second+=fontHeight;
  214. if (ret.first<lw)
  215. ret.first=lw;
  216. }
  217. return ret;
  218. }
  219. // Blit the text in txtg onto one surface. txtg contains lines of
  220. // text. Each line can be split into pieces. Currently only lines with
  221. // the same height are supported (ie. fontHeight).
  222. SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight, int & curh, SDL_Surface * ret, int xCenterPos)
  223. {
  224. for (size_t i=0; i<txtg->size(); i++, curh += fontHeight)
  225. {
  226. int lw=0; //line width
  227. for (size_t j=0;j<(*txtg)[i].size();j++)
  228. lw+=(*txtg)[i][j]->w;
  229. int pw = (xCenterPos < 0) ? ret->w/2 : xCenterPos;
  230. pw -= lw/2; //x coord for the start of the text
  231. int tw = pw;
  232. for (size_t j=0;j<(*txtg)[i].size();j++) //blit text
  233. {
  234. SDL_Surface *surf = (*txtg)[i][j];
  235. blitAt(surf, tw, curh, ret);
  236. tw+=surf->w;
  237. SDL_FreeSurface(surf);
  238. (*txtg)[i][j] = NULL;
  239. }
  240. }
  241. return ret;
  242. }
  243. SDL_Surface * FNT_RenderText (EFonts font, std::string text, SDL_Color kolor= Colors::WHITE)
  244. {
  245. if (graphics->fontsTrueType[font])
  246. return TTF_RenderText_Blended(graphics->fontsTrueType[font], text.c_str(), kolor);
  247. const Font *f = graphics->fonts[font];
  248. int w = f->getWidth(text.c_str()),
  249. h = f->height;
  250. SDL_Surface * ret = CSDL_Ext::newSurface(w, h, screen);
  251. CSDL_Ext::fillRect (ret, NULL, SDL_MapRGB(ret->format,128,128,128));//if use default black - no shadowing
  252. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,128,128,128));
  253. CSDL_Ext::printAt(text.c_str(), 0, 0, font, kolor, ret);
  254. return ret;
  255. }
  256. std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext, int &fontHeigh, EFonts font)
  257. {
  258. std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
  259. txtg->resize(brtext->size());
  260. if (graphics->fontsTrueType[font])
  261. fontHeigh = TTF_FontHeight(graphics->fontsTrueType[font]);
  262. else
  263. fontHeigh = graphics->fonts[font]->height;
  264. for (size_t i=0; i<brtext->size();i++) //foreach line
  265. {
  266. while((*brtext)[i].length()) //if something left
  267. {
  268. size_t z;
  269. /* Handle normal text. */
  270. z = 0;
  271. while(z < (*brtext)[i].length() && (*brtext)[i][z] != ('{'))
  272. z++;
  273. if (z)
  274. (*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), Colors::WHITE));
  275. (*brtext)[i].erase(0,z);
  276. if ((*brtext)[i].length() && (*brtext)[i][0] == '{')
  277. /* Remove '{' */
  278. (*brtext)[i].erase(0,1);
  279. if ((*brtext)[i].length()==0)
  280. /* End of line */
  281. continue;
  282. /* This text will be highlighted. */
  283. z = 0;
  284. while(z < (*brtext)[i].length() && (*brtext)[i][z] != ('}'))
  285. z++;
  286. if (z)
  287. (*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), Colors::YELLOW));
  288. (*brtext)[i].erase(0,z);
  289. if ((*brtext)[i].length() && (*brtext)[i][0] == '}')
  290. /* Remove '}' */
  291. (*brtext)[i].erase(0,1);
  292. } //ends while((*brtext)[i].length())
  293. } //ends for(int i=0; i<brtext->size();i++)
  294. return txtg;
  295. }
  296. SDL_Surface * CMessage::drawBoxTextBitmapSub( int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline/*=30*/, int imgToBmp/*=55*/ )
  297. {
  298. int curh;
  299. int fontHeight;
  300. std::vector<std::string> tekst = breakText(text,charperline);
  301. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(&tekst, fontHeight);
  302. std::pair<int,int> txts = getMaxSizes(txtg, fontHeight), boxs;
  303. boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width
  304. + 50; //side margins
  305. boxs.second =
  306. (curh=45) //top margin
  307. + txts.second //text total height
  308. + imgToBmp //text <=> img
  309. + bitmap->h
  310. + 5 // to sibtitle
  311. + (*txtg)[0][0]->h
  312. + 30;
  313. SDL_Surface *ret = drawDialogBox(boxs.first,boxs.second,player);
  314. blitTextOnSur(txtg,fontHeight,curh,ret);
  315. curh += imgToBmp;
  316. blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
  317. curh += bitmap->h + 5;
  318. CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+10,FONT_SMALL,Colors::WHITE,ret);
  319. delete txtg;
  320. return ret;
  321. }
  322. void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player)
  323. {
  324. SDL_Surface * _or = NULL;
  325. if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
  326. _or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],Colors::WHITE);
  327. const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}};
  328. for(int i = 0;
  329. i < ARRAY_COUNT(sizes)
  330. && sizes[i][0] < screen->w - 150
  331. && sizes[i][1] < screen->h - 150
  332. && ret->text->slider;
  333. i++)
  334. {
  335. ret->text->setBounds(sizes[i][0], sizes[i][1]);
  336. }
  337. if(ret->text->slider)
  338. ret->text->slider->addUsedEvents(CIntObject::WHEEL | CIntObject::KEYBOARD);
  339. std::pair<int,int> winSize(ret->text->pos.w, ret->text->pos.h); //start with text size
  340. ComponentsToBlit comps(ret->components,500,_or);
  341. if (ret->components.size())
  342. winSize.second += 10 + comps.h; //space to first component
  343. int bw = 0;
  344. if (ret->buttons.size())
  345. {
  346. // Compute total width of buttons
  347. bw = 20*(ret->buttons.size()-1); // space between all buttons
  348. for(size_t i=0; i<ret->buttons.size(); i++) //and add buttons width
  349. bw+=ret->buttons[i]->pos.w;
  350. winSize.second += 20 + //before button
  351. ok->ourImages[0].bitmap->h; //button
  352. }
  353. // Clip window size
  354. vstd::amax(winSize.second, 50);
  355. vstd::amax(winSize.first, 80);
  356. vstd::amax(winSize.first, comps.w);
  357. vstd::amax(winSize.first, bw);
  358. vstd::amin(winSize.first, screen->w - 150);
  359. ret->bitmap = drawDialogBox (winSize.first + 2*SIDE_MARGIN, winSize.second + 2*SIDE_MARGIN, player);
  360. ret->pos.h=ret->bitmap->h;
  361. ret->pos.w=ret->bitmap->w;
  362. ret->center();
  363. int curh = SIDE_MARGIN;
  364. int xOffset = (ret->pos.w - ret->text->pos.w)/2;
  365. if(!ret->buttons.size() && !ret->components.size()) //improvement for very small text only popups -> center text vertically
  366. {
  367. if(ret->bitmap->h > ret->text->pos.h + 2*SIDE_MARGIN)
  368. curh = (ret->bitmap->h - ret->text->pos.h)/2;
  369. }
  370. ret->text->moveBy(Point(xOffset, curh));
  371. curh += ret->text->pos.h;
  372. if (ret->components.size())
  373. {
  374. curh += BEFORE_COMPONENTS;
  375. comps.blitCompsOnSur (_or, BETWEEN_COMPS, curh, ret->bitmap);
  376. }
  377. if(ret->buttons.size())
  378. {
  379. // Position the buttons at the bottom of the window
  380. bw = (ret->bitmap->w/2) - (bw/2);
  381. curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->pos.h;
  382. for(size_t i=0; i<ret->buttons.size(); i++)
  383. {
  384. ret->buttons[i]->moveBy(Point(bw, curh));
  385. bw += ret->buttons[i]->pos.w + 20;
  386. }
  387. }
  388. for(size_t i=0; i<ret->components.size(); i++)
  389. ret->components[i]->moveBy(Point(ret->pos.x, ret->pos.y));
  390. if(_or)
  391. SDL_FreeSurface(_or);
  392. }
  393. void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x, int y)
  394. {
  395. std::vector<SDL_Surface *> &box = piecesOfBox[playerColor];
  396. // Note: this code assumes that the corner dimensions are all the same.
  397. // Horizontal borders
  398. int start_x = x + box[0]->w;
  399. const int stop_x = x + w - box[1]->w;
  400. const int bottom_y = y+h-box[7]->h+1;
  401. while (start_x < stop_x) {
  402. int cur_w = stop_x - start_x;
  403. if (cur_w > box[6]->w)
  404. cur_w = box[6]->w;
  405. // Top border
  406. Rect srcR(0, 0, cur_w, box[6]->h);
  407. Rect dstR(start_x, y, 0, 0);
  408. CSDL_Ext::blitSurface(box[6], &srcR, ret, &dstR);
  409. // Bottom border
  410. dstR.y = bottom_y;
  411. CSDL_Ext::blitSurface(box[7], &srcR, ret, &dstR);
  412. start_x += cur_w;
  413. }
  414. // Vertical borders
  415. int start_y = y + box[0]->h;
  416. const int stop_y = y + h - box[2]->h+1;
  417. const int right_x = x+w-box[5]->w;
  418. while (start_y < stop_y) {
  419. int cur_h = stop_y - start_y;
  420. if (cur_h > box[4]->h)
  421. cur_h = box[4]->h;
  422. // Left border
  423. Rect srcR(0, 0, box[4]->w, cur_h);
  424. Rect dstR(x, start_y, 0, 0);
  425. CSDL_Ext::blitSurface(box[4], &srcR, ret, &dstR);
  426. // Right border
  427. dstR.x = right_x;
  428. CSDL_Ext::blitSurface(box[5], &srcR, ret, &dstR);
  429. start_y += cur_h;
  430. }
  431. //corners
  432. Rect dstR(x, y, box[0]->w, box[0]->h);
  433. CSDL_Ext::blitSurface(box[0], NULL, ret, &dstR);
  434. dstR=Rect(x+w-box[1]->w, y, box[1]->w, box[1]->h);
  435. CSDL_Ext::blitSurface(box[1], NULL, ret, &dstR);
  436. dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h);
  437. CSDL_Ext::blitSurface(box[2], NULL, ret, &dstR);
  438. dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h);
  439. CSDL_Ext::blitSurface(box[3], NULL, ret, &dstR);
  440. }
  441. ComponentResolved::ComponentResolved( CComponent *Comp ):
  442. comp(Comp)
  443. {
  444. //Temporary assign ownership on comp
  445. if (parent)
  446. parent->removeChild(this);
  447. if (comp->parent)
  448. {
  449. comp->parent->addChild(this);
  450. comp->parent->removeChild(comp);
  451. }
  452. addChild(comp);
  453. defActions = 255 - DISPOSE;
  454. pos.x = pos.y = 0;
  455. pos.w = comp->pos.w;
  456. pos.h = comp->pos.h;
  457. }
  458. ComponentResolved::~ComponentResolved()
  459. {
  460. if (parent)
  461. {
  462. removeChild(comp);
  463. parent->addChild(comp);
  464. }
  465. }
  466. void ComponentResolved::showAll(SDL_Surface *to)
  467. {
  468. CIntObject::showAll(to);
  469. comp->showAll(to);
  470. }
  471. ComponentsToBlit::~ComponentsToBlit()
  472. {
  473. for(size_t i=0; i<comps.size(); i++)
  474. for(size_t j = 0; j < comps[i].size(); j++)
  475. delete comps[i][j];
  476. }
  477. ComponentsToBlit::ComponentsToBlit(std::vector<CComponent*> & SComps, int maxw, SDL_Surface* _or)
  478. {
  479. w = h = 0;
  480. if(SComps.empty())
  481. return;
  482. comps.resize(1);
  483. int curw = 0;
  484. int curr = 0; //current row
  485. for(size_t i=0;i<SComps.size();i++)
  486. {
  487. ComponentResolved *cur = new ComponentResolved(SComps[i]);
  488. int toadd = (cur->pos.w + BETWEEN_COMPS + (_or ? _or->w : 0));
  489. if (curw + toadd > maxw)
  490. {
  491. curr++;
  492. vstd::amax(w,curw);
  493. curw = cur->pos.w;
  494. comps.resize(curr+1);
  495. }
  496. else
  497. {
  498. curw += toadd;
  499. vstd::amax(w,curw);
  500. }
  501. comps[curr].push_back(cur);
  502. }
  503. for(size_t i=0;i<comps.size();i++)
  504. {
  505. int maxHeight = 0;
  506. for(size_t j=0;j<comps[i].size();j++)
  507. vstd::amax(maxHeight, comps[i][j]->pos.h);
  508. h += maxHeight + BETWEEN_COMPS_ROWS;
  509. }
  510. }
  511. void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret )
  512. {
  513. for (size_t i=0;i<comps.size();i++)//for each row
  514. {
  515. int totalw=0, maxHeight=0;
  516. for(size_t j=0;j<(comps)[i].size();j++)//find max height & total width in this row
  517. {
  518. ComponentResolved *cur = (comps)[i][j];
  519. totalw += cur->pos.w;
  520. vstd::amax(maxHeight, cur->pos.h);
  521. }
  522. //add space between comps in this row
  523. if(_or)
  524. totalw += (inter*2+_or->w) * ((comps)[i].size() - 1);
  525. else
  526. totalw += (inter) * ((comps)[i].size() - 1);
  527. int middleh = curh + maxHeight/2;//axis for image aligment
  528. int curw = ret->w/2 - totalw/2;
  529. for(size_t j=0;j<(comps)[i].size();j++)
  530. {
  531. ComponentResolved *cur = (comps)[i][j];
  532. cur->moveTo(Point(curw, curh));
  533. //blit component
  534. cur->showAll(ret);
  535. curw += cur->pos.w;
  536. //if there is subsequent component blit "or"
  537. if(j<((comps)[i].size()-1))
  538. {
  539. if(_or)
  540. {
  541. curw+=inter;
  542. blitAt(_or,curw,middleh-(_or->h/2),ret);
  543. curw+=_or->w;
  544. }
  545. curw+=inter;
  546. }
  547. }
  548. curh += maxHeight + BETWEEN_COMPS_ROWS;
  549. }
  550. }