2
0

CMessage.cpp 17 KB

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