2
0

CMessage.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. #include "stdafx.h"
  2. #include "CMessage.h"
  3. #include "SDL_ttf.h"
  4. #include "hch/CDefHandler.h"
  5. #include "CGameInfo.h"
  6. #include "SDL_Extensions.h"
  7. #include "hch/CLodHandler.h"
  8. #include <boost/algorithm/string.hpp>
  9. #include <boost/algorithm/string/replace.hpp>
  10. #include "CPlayerInterface.h"
  11. #include "hch/CDefHandler.h"
  12. #include "CGameInfo.h"
  13. #include "SDL_Extensions.h"
  14. #include <sstream>
  15. #include "hch/CGeneralTextHandler.h"
  16. #include "client/Graphics.h"
  17. #include "CAdvmapInterface.h"
  18. /*
  19. * CMessage.cpp, part of VCMI engine
  20. *
  21. * Authors: listed in file AUTHORS in main folder
  22. *
  23. * License: GNU General Public License v2.0 or later
  24. * Full text of license available in license.txt file, in main folder
  25. *
  26. */
  27. SDL_Color tytulowy, tlo, zwykly ;
  28. extern SDL_Surface * screen;
  29. extern TTF_Font * TNRB16, *TNR, *GEOR13;
  30. using namespace NMessage;
  31. const int COMPONENT_TO_SUBTITLE = 5;
  32. const int BETWEEN_COMPS_ROWS = 10;
  33. const int BEFORE_COMPONENTS = 30;
  34. template <typename T, typename U> std::pair<T,U> max(const std::pair<T,U> &x, const std::pair<T,U> &y)
  35. {
  36. std::pair<T,U> ret;
  37. ret.first = std::max(x.first,y.first);
  38. ret.second = std::max(x.second,y.second);
  39. return ret;
  40. }
  41. namespace NMessage
  42. {
  43. CDefHandler * ok, *cancel;
  44. std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  45. SDL_Surface * background = NULL;
  46. }
  47. void CMessage::init()
  48. {
  49. {
  50. for (int i=0;i<PLAYER_LIMIT;i++)
  51. {
  52. CDefHandler * bluePieces = CDefHandler::giveDef("DIALGBOX.DEF");
  53. std::vector<SDL_Surface *> n;
  54. piecesOfBox.push_back(n);
  55. if (i==1)
  56. {
  57. for (size_t j=0;j<bluePieces->ourImages.size();++j)
  58. {
  59. piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
  60. }
  61. }
  62. for (size_t j=0;j<bluePieces->ourImages.size();++j)
  63. {
  64. graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
  65. piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
  66. }
  67. }
  68. NMessage::background = BitmapHandler::loadBitmap("DIBOXBCK.BMP");
  69. SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255));
  70. }
  71. ok = CDefHandler::giveDef("IOKAY.DEF");
  72. cancel = CDefHandler::giveDef("ICANCEL.DEF");
  73. }
  74. void CMessage::dispose()
  75. {
  76. for (int i=0;i<PLAYER_LIMIT;i++)
  77. {
  78. for (size_t j=0; j<piecesOfBox[i].size(); ++j)
  79. {
  80. SDL_FreeSurface(piecesOfBox[i][j]);
  81. }
  82. }
  83. SDL_FreeSurface(background);
  84. delete ok;
  85. delete cancel;
  86. }
  87. SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for window
  88. {
  89. //prepare surface
  90. SDL_Surface * ret = SDL_CreateRGBSurface(screen->flags, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
  91. for (int i=0; i<h; i+=background->h)//background
  92. {
  93. for (int j=0; j<w; j+=background->w-1)
  94. {
  95. SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); //FIXME taking address of temporary
  96. }
  97. }
  98. drawBorder(playerColor, ret, w, h);
  99. return ret;
  100. }
  101. /* The map file contains long texts, with or without line breaks. This
  102. * method takes such a text and breaks it into into several lines. */
  103. std::vector<std::string> * CMessage::breakText(std::string text, size_t maxLineSize,
  104. bool userBreak, bool ifor)
  105. {
  106. std::vector<std::string> * ret = new std::vector<std::string>();
  107. boost::algorithm::trim_if(text,boost::algorithm::is_any_of(" "));
  108. while (text.length())
  109. {
  110. unsigned int z = 0;
  111. unsigned int braces = 0;
  112. bool opened = false;
  113. while((text[z] != 0) && (text[z] != 0x0a) && (z < maxLineSize+braces))
  114. {
  115. /* We don't count braces in string length. */
  116. if (text[z] == '{')
  117. {
  118. opened=true;
  119. braces++;
  120. }
  121. else if (text[z]=='}')
  122. {
  123. opened=false;
  124. braces++;
  125. }
  126. z++;
  127. }
  128. if ((text[z] != 0) && (text[z] != 0x0a))
  129. {
  130. /* We have a long line. Try to do a nice line break, if
  131. * possible. We backtrack on the line until we find a
  132. * suitable character. */
  133. int pos = z-1;
  134. /* TODO: boost should have a nice method to do that. */
  135. while(pos > 0 &&
  136. text[pos] != ' ' &&
  137. text[pos] != ',' &&
  138. text[pos] != '.' &&
  139. text[pos] != ';' &&
  140. text[pos] != '!' &&
  141. text[pos] != '?')
  142. pos --;
  143. if (pos > 0)
  144. z = pos+1;
  145. }
  146. if(z) //non-blank line
  147. {
  148. ret->push_back(text.substr(0, z));
  149. if (opened)
  150. /* Close the brace for the current line. */
  151. ret->back() += '}';
  152. text.erase(0, z);
  153. }
  154. else if(text[z] == 0x0a) //blank line
  155. {
  156. ret->push_back(""); //add empty string, no extra actions needed
  157. }
  158. if (text[0] == 0x0a)
  159. {
  160. /* Braces do not carry over lines. The map author forgot
  161. * to close it. */
  162. opened = false;
  163. /* Remove LF */
  164. text.erase(0, 1);
  165. }
  166. boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(" "));
  167. if (opened)
  168. {
  169. /* Add an opening brace for the next line. */
  170. if (text.length())
  171. text.insert(0, "{");
  172. }
  173. }
  174. /* Trim whitespaces of every line. */
  175. for (size_t i=0; i<ret->size(); i++)
  176. boost::algorithm::trim((*ret)[i]);
  177. return ret;
  178. }
  179. std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg)
  180. {
  181. std::pair<int,int> ret;
  182. ret.first = -1;
  183. ret.second=0;
  184. for (size_t i=0; i<txtg->size();i++) //we are searching widest line and total height
  185. {
  186. int lw=0;
  187. for (size_t j=0;j<(*txtg)[i].size();j++)
  188. {
  189. lw+=(*txtg)[i][j]->w;
  190. ret.second+=(*txtg)[i][j]->h;
  191. }
  192. if(!(*txtg)[i].size())
  193. ret.second+=19;
  194. if (ret.first<lw)
  195. ret.first=lw;
  196. }
  197. return ret;
  198. }
  199. SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret, int xCenterPos)
  200. {
  201. for (size_t i=0; i<txtg->size();i++)
  202. {
  203. int lw=0; //line width
  204. for (size_t j=0;j<(*txtg)[i].size();j++)
  205. lw+=(*txtg)[i][j]->w;
  206. int pw = (xCenterPos < 0) ? ret->w/2 : xCenterPos;
  207. pw -= lw/2; //x coord for the start of the text
  208. int tw = pw;
  209. for (size_t j=0;j<(*txtg)[i].size();j++) //blit text
  210. {
  211. blitAt((*txtg)[i][j],tw,curh+i*19,ret);
  212. tw+=(*txtg)[i][j]->w;
  213. SDL_FreeSurface((*txtg)[i][j]);
  214. (*txtg)[i][j] = NULL;
  215. }
  216. }
  217. curh+=txtg->size()*19;
  218. return ret;
  219. }
  220. std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext, TTF_Font *font)
  221. {
  222. if(!font) font = TNRB16;
  223. std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
  224. txtg->resize(brtext->size());
  225. for (size_t i=0; i<brtext->size();i++) //foreach line
  226. {
  227. while((*brtext)[i].length()) //if something left
  228. {
  229. size_t z;
  230. /* Handle normal text. */
  231. z = 0;
  232. while((*brtext)[i][z]!= 0 && (*brtext)[i][z] != ('{'))
  233. z++;
  234. if (z)
  235. (*txtg)[i].push_back(TTF_RenderText_Blended(font, (*brtext)[i].substr(0,z).c_str(), zwykly));
  236. (*brtext)[i].erase(0,z);
  237. if ((*brtext)[i][0] == '{')
  238. /* Remove '{' */
  239. (*brtext)[i].erase(0,1);
  240. if ((*brtext)[i].length()==0)
  241. /* End of line */
  242. continue;
  243. /* This text will be highlighted. */
  244. z = 0;
  245. while((*brtext)[i][z]!= 0 && (*brtext)[i][z] != ('}'))
  246. z++;
  247. if (z)
  248. (*txtg)[i].push_back(TTF_RenderText_Blended(font, (*brtext)[i].substr(0,z).c_str(), tytulowy));
  249. (*brtext)[i].erase(0,z);
  250. if ((*brtext)[i][0] == '}')
  251. /* Remove '}' */
  252. (*brtext)[i].erase(0,1);
  253. } //ends while((*brtext)[i].length())
  254. } //ends for(int i=0; i<brtext->size();i++)
  255. return txtg;
  256. }
  257. CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
  258. {
  259. CSimpleWindow * ret = new CSimpleWindow();
  260. std::vector<std::string> * brtext = breakText(text,32,true,true);
  261. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  262. std::pair<int,int> txts = getMaxSizes(txtg);
  263. ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0);
  264. ret->pos.h=ret->bitmap->h;
  265. ret->pos.w=ret->bitmap->w;
  266. int curh = ret->bitmap->h/2 - (19*txtg->size())/2;
  267. blitTextOnSur(txtg,curh,ret->bitmap);
  268. delete brtext;
  269. delete txtg;
  270. return ret;
  271. }
  272. SDL_Surface * CMessage::drawBoxTextBitmapSub( int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline/*=30*/, int imgToBmp/*=55*/ )
  273. {
  274. int curh;
  275. std::vector<std::string> * tekst = breakText(text,charperline);
  276. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
  277. std::pair<int,int> txts = getMaxSizes(txtg), boxs;
  278. boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width
  279. + 50; //side margins
  280. boxs.second =
  281. (curh=45) //top margin
  282. + txts.second //text total height
  283. + imgToBmp //text <=> img
  284. + bitmap->h
  285. + 5 // to sibtitle
  286. + (*txtg)[0][0]->h
  287. + 30;
  288. SDL_Surface *ret = drawBox1(boxs.first,boxs.second,player);
  289. blitTextOnSur(txtg,curh,ret);
  290. curh += imgToBmp;
  291. blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
  292. curh += bitmap->h + 5;
  293. CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+10,GEOR13,zwykly,ret);
  294. delete tekst;
  295. delete txtg;
  296. return ret;
  297. }
  298. void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline)
  299. {
  300. SDL_Surface * _or = NULL;
  301. if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
  302. _or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
  303. std::vector<std::string> * brtext = breakText(text,charperline,true,true); //text
  304. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  305. std::pair<int,int> txts = getMaxSizes(txtg);
  306. ComponentsToBlit comps(ret->components,500,_or);
  307. if(ret->buttons.size())
  308. txts.second += 20 + //before button
  309. ok->ourImages[0].bitmap->h; //button
  310. if (ret->components.size())
  311. {
  312. txts.second += 30 + comps.h; //space to first component
  313. }
  314. amax(txts.first,comps.w);
  315. ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
  316. ret->pos.h=ret->bitmap->h;
  317. ret->pos.w=ret->bitmap->w;
  318. ret->pos.x=screen->w/2-(ret->pos.w/2);
  319. ret->pos.y=screen->h/2-(ret->pos.h/2);
  320. int curh = 30; //gorny margines
  321. blitTextOnSur(txtg,curh,ret->bitmap);
  322. if (ret->components.size())
  323. {
  324. curh += BEFORE_COMPONENTS;
  325. comps.blitCompsOnSur(_or, 10, curh, ret->bitmap);
  326. }
  327. if(ret->buttons.size())
  328. {
  329. curh += 20; //to buttton
  330. int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them
  331. for(size_t i=0; i<ret->buttons.size(); i++) //and add buttons width
  332. bw+=ret->buttons[i]->imgs[0][0]->w;
  333. bw = (ret->bitmap->w/2) - (bw/2);
  334. for(size_t i=0; i<ret->buttons.size(); i++)
  335. {
  336. ret->buttons[i]->pos.x = bw + ret->pos.x;
  337. ret->buttons[i]->pos.y = curh + ret->pos.y;
  338. bw += ret->buttons[i]->imgs[0][0]->w + 20;
  339. }
  340. }
  341. for(size_t i=0; i<ret->components.size(); i++)
  342. {
  343. ret->components[i]->pos.x += ret->pos.x;
  344. ret->components[i]->pos.y += ret->pos.y;
  345. }
  346. delete brtext;
  347. delete txtg;
  348. if(_or)
  349. SDL_FreeSurface(_or);
  350. }
  351. SDL_Surface * CMessage::genMessage
  352. (std::string title, std::string text, EWindowType type, std::vector<CDefHandler*> *addPics, void * cb)
  353. {
  354. //max x 320 okolo 30 znakow
  355. std::vector<std::string> * tekst;
  356. if (text.length() < 30) //does not need breaking
  357. {
  358. tekst = new std::vector<std::string>();
  359. tekst->push_back(text);
  360. }
  361. else tekst = breakText(text);
  362. int ww, hh; //dimensions of box
  363. if (319>30+13*text.length())
  364. ww = 30+13*text.length();
  365. else ww = 319;
  366. if (title.length())
  367. hh=110+(21*tekst->size());
  368. else hh=60+(21*tekst->size());
  369. if (type==yesOrNO) //make place for buttons
  370. {
  371. if (ww<200) ww=200;
  372. hh+=70;
  373. }
  374. SDL_Surface * ret = drawBox1(ww,hh,0);
  375. //prepare title text
  376. if (title.length())
  377. {
  378. SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy);
  379. //draw title
  380. SDL_Rect tytul = genRect(titleText->h,titleText->w,((ret->w/2)-(titleText->w/2)),37);
  381. SDL_BlitSurface(titleText,NULL,ret,&tytul);
  382. SDL_FreeSurface(titleText);
  383. }
  384. //draw text
  385. for (size_t i=0; i<tekst->size(); i++)
  386. {
  387. int by = 37+i*21;
  388. if (title.length()) by+=40;
  389. SDL_Surface * tresc = TTF_RenderText_Blended(TNRB16,(*tekst)[i].c_str(),zwykly);
  390. SDL_Rect trescRect = genRect(tresc->h,tresc->w,((ret->w/2)-(tresc->w/2)),by);
  391. SDL_BlitSurface(tresc,NULL,ret,&trescRect);
  392. SDL_FreeSurface(tresc);
  393. }
  394. if (type==yesOrNO) // add buttons
  395. {
  396. int by = 77+tekst->size()*21;
  397. if (title.length()) by+=40;
  398. int hwo = (*addPics)[0]->ourImages[0].bitmap->w, hwc=(*addPics)[0]->ourImages[0].bitmap->w;
  399. //ok
  400. SDL_Rect trescRect = genRect((*addPics)[0]->ourImages[0].bitmap->h,hwo,((ret->w/2)-hwo-10),by);
  401. SDL_BlitSurface((*addPics)[0]->ourImages[0].bitmap,NULL,ret,&trescRect);
  402. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  403. //cancel
  404. trescRect = genRect((*addPics)[1]->ourImages[0].bitmap->h,hwc,((ret->w/2)+10),by);
  405. SDL_BlitSurface((*addPics)[1]->ourImages[0].bitmap,NULL,ret,&trescRect);
  406. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  407. }
  408. delete tekst;
  409. return ret;
  410. }
  411. void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x, int y)
  412. {
  413. //obwodka I-szego rzedu pozioma //border of 1st series, horizontal
  414. for (int i=0; i<w-piecesOfBox[playerColor][6]->w; i+=piecesOfBox[playerColor][6]->w)
  415. {
  416. SDL_BlitSurface
  417. (piecesOfBox[playerColor][6],NULL,ret,&genRect(piecesOfBox[playerColor][6]->h,piecesOfBox[playerColor][6]->w,x+i,y+0));
  418. SDL_BlitSurface
  419. (piecesOfBox[playerColor][7],NULL,ret,&genRect(piecesOfBox[playerColor][7]->h,piecesOfBox[playerColor][7]->w,x+i,y+h-piecesOfBox[playerColor][7]->h));
  420. }
  421. //obwodka I-szego rzedu pionowa //border of 1st series, vertical
  422. for (int i=0; i<h-piecesOfBox[playerColor][4]->h; i+=piecesOfBox[playerColor][4]->h)
  423. {
  424. SDL_BlitSurface
  425. (piecesOfBox[playerColor][4],NULL,ret,&genRect(piecesOfBox[playerColor][4]->h,piecesOfBox[playerColor][4]->w,x+0,y+i));
  426. SDL_BlitSurface
  427. (piecesOfBox[playerColor][5],NULL,ret,&genRect(piecesOfBox[playerColor][5]->h,piecesOfBox[playerColor][5]->w,x+w-piecesOfBox[playerColor][5]->w,y+i));
  428. }
  429. //corners
  430. SDL_BlitSurface
  431. (piecesOfBox[playerColor][0],NULL,ret,&genRect(piecesOfBox[playerColor][0]->h,piecesOfBox[playerColor][0]->w,x+0,y+0));
  432. SDL_BlitSurface
  433. (piecesOfBox[playerColor][1],NULL,ret,&genRect(piecesOfBox[playerColor][1]->h,piecesOfBox[playerColor][1]->w,x+w-piecesOfBox[playerColor][1]->w,y+0));
  434. SDL_BlitSurface
  435. (piecesOfBox[playerColor][2],NULL,ret,&genRect(piecesOfBox[playerColor][2]->h,piecesOfBox[playerColor][2]->w,x+0,y+h-piecesOfBox[playerColor][2]->h));
  436. SDL_BlitSurface
  437. (piecesOfBox[playerColor][3],NULL,ret,&genRect(piecesOfBox[playerColor][3]->h,piecesOfBox[playerColor][3]->w,x+w-piecesOfBox[playerColor][3]->w,y+h-piecesOfBox[playerColor][3]->h));
  438. }
  439. ComponentResolved::ComponentResolved()
  440. {
  441. comp = NULL;
  442. img = NULL;
  443. txt = NULL;
  444. }
  445. ComponentResolved::ComponentResolved( SComponent *Comp )
  446. {
  447. comp = Comp;
  448. img = comp->getImg();
  449. std::vector<std::string> * brtext = CMessage::breakText(comp->subtitle,11,true,true); //text
  450. txt = CMessage::drawText(brtext,GEOR13);
  451. delete brtext;
  452. //calculate dimensions
  453. std::pair<int,int> textSize = CMessage::getMaxSizes(txt);
  454. comp->pos.w = std::max(textSize.first, img->w); //bigger of: subtitle width and image width
  455. comp->pos.h = img->h + COMPONENT_TO_SUBTITLE + textSize.second;
  456. }
  457. ComponentResolved::~ComponentResolved()
  458. {
  459. for(size_t i = 0; i < txt->size(); i++)
  460. for(size_t j = 0; j < (*txt)[i].size(); j++)
  461. if((*txt)[i][j])
  462. SDL_FreeSurface((*txt)[i][j]);
  463. delete txt;
  464. }
  465. ComponentsToBlit::~ComponentsToBlit()
  466. {
  467. for(size_t i=0; i<comps.size(); i++)
  468. for(size_t j = 0; j < comps[i].size(); j++)
  469. delete comps[i][j];
  470. }
  471. ComponentsToBlit::ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or)
  472. {
  473. w = h = 0;
  474. if(!SComps.size())
  475. return;
  476. comps.resize(1);
  477. int curw = 0;
  478. int curr = 0; //current row
  479. for(size_t i=0;i<SComps.size();i++)
  480. {
  481. ComponentResolved *cur = new ComponentResolved(SComps[i]);
  482. int toadd = (cur->comp->pos.w + 12 + (_or ? _or->w : 0));
  483. if (curw + toadd > maxw)
  484. {
  485. curr++;
  486. amax(w,curw);
  487. curw = cur->comp->pos.w;
  488. comps.resize(curr+1);
  489. }
  490. else
  491. {
  492. curw += toadd;
  493. }
  494. comps[curr].push_back(cur);
  495. }
  496. for(size_t i=0;i<comps.size();i++)
  497. {
  498. int maxh = 0;
  499. for(size_t j=0;j<comps[i].size();j++)
  500. amax(maxh,comps[i][j]->comp->pos.h);
  501. h += maxh + BETWEEN_COMPS_ROWS;
  502. }
  503. }
  504. void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret )
  505. {
  506. for (size_t i=0;i<comps.size();i++)
  507. {
  508. int totalw=0, maxh=0;
  509. for(size_t j=0;j<(comps)[i].size();j++)
  510. {
  511. ComponentResolved *cur = (comps)[i][j];
  512. totalw += cur->comp->pos.w;
  513. amax(maxh,cur->comp->pos.h+BETWEEN_COMPS_ROWS);
  514. }
  515. if(_or)
  516. {
  517. totalw += (inter*2+_or->w) * ((comps)[i].size() - 1);
  518. }
  519. else
  520. {
  521. totalw += (inter) * ((comps)[i].size() - 1);
  522. }
  523. curh+=maxh/2;
  524. int curw = (ret->w/2)-(totalw/2);
  525. for(size_t j=0;j<(comps)[i].size();j++)
  526. {
  527. ComponentResolved *cur = (comps)[i][j];
  528. //blit img
  529. int hlp = curh-(cur->comp->pos.h)/2;
  530. blitAt(cur->img, curw + (cur->comp->pos.w - cur->comp->getImg()->w)/2, hlp, ret);
  531. cur->comp->pos.x = curw;
  532. cur->comp->pos.y = hlp;
  533. //blit subtitle
  534. hlp += cur->img->h + COMPONENT_TO_SUBTITLE;
  535. CMessage::blitTextOnSur(cur->txt, hlp, ret, cur->comp->pos.x + cur->comp->pos.w/2 );
  536. //if there is subsequent component blit "or"
  537. curw += cur->comp->pos.w;
  538. if(j<((comps)[i].size()-1))
  539. {
  540. if(_or)
  541. {
  542. curw+=inter;
  543. blitAt(_or,curw,curh-(_or->h/2),ret);
  544. curw+=_or->w;
  545. }
  546. curw+=inter;
  547. }
  548. }
  549. curh+=maxh/2;
  550. }
  551. }