CMessage.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. SDL_Color tytulowy, tlo, zwykly ;
  19. SDL_Rect genRect(int hh, int ww, int xx, int yy);
  20. extern SDL_Surface * screen;
  21. extern TTF_Font * TNRB16, *TNR, *GEOR13;
  22. SDL_Color genRGB(int r, int g, int b, int a=0);
  23. //void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);
  24. bool isItIn(const SDL_Rect * rect, int x, int y);
  25. using namespace NMessage;
  26. template <typename T, typename U> std::pair<T,U> max(const std::pair<T,U> &x, const std::pair<T,U> &y)
  27. {
  28. std::pair<T,U> ret;
  29. ret.first = std::max(x.first,y.first);
  30. ret.second = std::max(x.second,y.second);
  31. return ret;
  32. }
  33. namespace NMessage
  34. {
  35. CDefHandler * ok, *cancel;
  36. std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
  37. SDL_Surface * background = NULL;
  38. }
  39. CMessage::CMessage()
  40. {
  41. //if (!NMessage::background)
  42. // init();
  43. }
  44. void CMessage::init()
  45. {
  46. {
  47. for (int i=0;i<PLAYER_LIMIT;i++)
  48. {
  49. CDefHandler * bluePieces = CDefHandler::giveDef("DIALGBOX.DEF");
  50. std::vector<SDL_Surface *> n;
  51. piecesOfBox.push_back(n);
  52. if (i==1)
  53. {
  54. for (int j=0;j<bluePieces->ourImages.size();j++)
  55. {
  56. piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
  57. }
  58. }
  59. for (int j=0;j<bluePieces->ourImages.size();j++)
  60. {
  61. graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
  62. piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
  63. }
  64. }
  65. NMessage::background = BitmapHandler::loadBitmap("DIBOXBCK.BMP");
  66. SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255));
  67. }
  68. ok = CDefHandler::giveDef("IOKAY.DEF");
  69. cancel = CDefHandler::giveDef("ICANCEL.DEF");
  70. }
  71. void CMessage::dispose()
  72. {
  73. for (int i=0;i<PLAYER_LIMIT;i++)
  74. {
  75. for (int j=0;j<piecesOfBox[i].size();j++)
  76. {
  77. SDL_FreeSurface(piecesOfBox[i][j]);
  78. }
  79. }
  80. SDL_FreeSurface(background);
  81. delete ok;
  82. delete cancel;
  83. }
  84. SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for window
  85. {
  86. //prepare surface
  87. SDL_Surface * ret = SDL_CreateRGBSurface(screen->flags, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
  88. for (int i=0; i<h; i+=background->h)//background
  89. {
  90. for (int j=0; j<w; j+=background->w-1)
  91. SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i));
  92. }
  93. //obwodka I-szego rzedu pozioma
  94. for (int i=0; i<w; i+=piecesOfBox[playerColor][6]->w)
  95. {
  96. SDL_BlitSurface
  97. (piecesOfBox[playerColor][6],NULL,ret,&genRect(piecesOfBox[playerColor][6]->h,piecesOfBox[playerColor][6]->w,i,0));
  98. SDL_BlitSurface
  99. (piecesOfBox[playerColor][7],NULL,ret,&genRect(piecesOfBox[playerColor][7]->h,piecesOfBox[playerColor][7]->w,i,h-piecesOfBox[playerColor][7]->h));
  100. }
  101. //obwodka I-szego rzedu pionowa
  102. for (int i=0; i<h; i+=piecesOfBox[playerColor][4]->h)
  103. {
  104. SDL_BlitSurface
  105. (piecesOfBox[playerColor][4],NULL,ret,&genRect(piecesOfBox[playerColor][4]->h,piecesOfBox[playerColor][4]->w,0,i));
  106. SDL_BlitSurface
  107. (piecesOfBox[playerColor][5],NULL,ret,&genRect(piecesOfBox[playerColor][5]->h,piecesOfBox[playerColor][5]->w,w-piecesOfBox[playerColor][5]->w,i));
  108. }
  109. //corners
  110. SDL_BlitSurface
  111. (piecesOfBox[playerColor][0],NULL,ret,&genRect(piecesOfBox[playerColor][0]->h,piecesOfBox[playerColor][0]->w,0,0));
  112. SDL_BlitSurface
  113. (piecesOfBox[playerColor][1],NULL,ret,&genRect(piecesOfBox[playerColor][1]->h,piecesOfBox[playerColor][1]->w,w-piecesOfBox[playerColor][1]->w,0));
  114. SDL_BlitSurface
  115. (piecesOfBox[playerColor][2],NULL,ret,&genRect(piecesOfBox[playerColor][2]->h,piecesOfBox[playerColor][2]->w,0,h-piecesOfBox[playerColor][2]->h));
  116. SDL_BlitSurface
  117. (piecesOfBox[playerColor][3],NULL,ret,&genRect(piecesOfBox[playerColor][3]->h,piecesOfBox[playerColor][3]->w,w-piecesOfBox[playerColor][3]->w,h-piecesOfBox[playerColor][3]->h));
  118. //box gotowy!
  119. return ret;
  120. }
  121. std::vector<std::string> * CMessage::breakText(std::string text, int line, bool userBreak, bool ifor)
  122. {
  123. std::vector<std::string> * ret = new std::vector<std::string>();
  124. while (text.length()>line)
  125. {
  126. int whereCut = -1, braces=0;
  127. bool pom = true, opened=false;
  128. for (int i=0; i<line+braces; i++)
  129. {
  130. if (text[i]==10) //end of line sign
  131. {
  132. whereCut=i+1;
  133. pom=false;
  134. break;
  135. }
  136. else if (ifor && (text[i]=='{') || (text[i]=='}')) // ignore braces
  137. {
  138. if (text[i]=='{')
  139. opened=true;
  140. else
  141. opened=false;
  142. braces++;
  143. }
  144. }
  145. for (int i=line+braces; i>0&&pom; i--)
  146. {
  147. if (text[i]==' ')
  148. {
  149. whereCut = i;
  150. break;
  151. }
  152. else if (opened && text[i]=='{')
  153. opened = false;
  154. else if (text[i]=='}')
  155. opened = true;
  156. }
  157. ret->push_back(text.substr(0,whereCut));
  158. text.erase(0,whereCut);
  159. boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(" "));
  160. if (opened)
  161. {
  162. (*(ret->end()-1))+='}';
  163. text.insert(0,"{");
  164. }
  165. }
  166. for (int i=0;i<text.length();i++)
  167. {
  168. if (text[i]==10) //end of line sign
  169. {
  170. ret->push_back(text.substr(0,i));
  171. text.erase(0,i);
  172. i=0;
  173. }
  174. }
  175. if (text.length() > 0)
  176. ret->push_back(text);
  177. for (int i=0; i<ret->size(); i++)
  178. {
  179. boost::algorithm::trim((*ret)[i]);
  180. }
  181. return ret;
  182. }
  183. std::pair<int, int> CMessage::getMaxSizes(std::vector< std::vector<SComponent*> > * komp)
  184. {
  185. std::pair<int,int> ret;
  186. for (int i=0;i<komp->size();i++)
  187. {
  188. int sumaw=0;
  189. int maxh=0;
  190. for(int j=0;j<(*komp)[i].size();j++)
  191. {
  192. sumaw += (*komp)[i][j]->getImg()->w;
  193. if (maxh < (*komp)[i][j]->getImg()->h)
  194. maxh = (*komp)[i][j]->getImg()->h;
  195. }
  196. if(sumaw>ret.first)
  197. ret.first = sumaw;
  198. ret.second+=maxh;
  199. }
  200. return ret;
  201. }
  202. std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg)
  203. {
  204. std::pair<int,int> ret;
  205. ret.first = -1;
  206. ret.second=0;
  207. for (int i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
  208. {
  209. int lw=0;
  210. for (int j=0;j<(*txtg)[i].size();j++)
  211. {
  212. lw+=(*txtg)[i][j]->w;
  213. ret.second+=(*txtg)[i][j]->h;
  214. }
  215. if (ret.first<lw)
  216. ret.first=lw;
  217. }
  218. return ret;
  219. }
  220. SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret)
  221. {
  222. for (int i=0; i<txtg->size();i++)
  223. {
  224. int lw=0;
  225. for (int j=0;j<(*txtg)[i].size();j++)
  226. lw+=(*txtg)[i][j]->w; //lw - laczna szerokosc linii
  227. int pw = ret->w/2;
  228. pw -= lw/2; //poczatek tekstu (x)
  229. int tw = pw;
  230. for (int j=0;j<(*txtg)[i].size();j++) //blit text
  231. {
  232. blitAt((*txtg)[i][j],tw,curh+i*19,ret);
  233. tw+=(*txtg)[i][j]->w;
  234. SDL_FreeSurface((*txtg)[i][j]);
  235. }
  236. }
  237. curh+=txtg->size()*19;
  238. return ret;
  239. }
  240. SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret)
  241. {
  242. std::vector<std::string> * brdtext;
  243. if (comps.size())
  244. brdtext = breakText(comps[0]->subtitle,12,true,true);
  245. else
  246. brdtext = NULL;
  247. comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2);
  248. comps[0]->pos.y = curh;
  249. blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret);
  250. curh += comps[0]->getImg()->h + 5; //obrazek + przerwa
  251. for (int i=0; i<brdtext->size();i++) //descr.
  252. {
  253. SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly);
  254. blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret);
  255. curh+=tesu->h;
  256. SDL_FreeSurface(tesu);
  257. }
  258. return ret;
  259. }
  260. SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * _or, std::vector< std::vector<SComponent*> > * komp, int inter, int &curh, SDL_Surface *ret)
  261. {
  262. for (int i=0;i<komp->size();i++)
  263. {
  264. int totalw=0, maxh=0;
  265. for(int j=0;j<(*komp)[i].size();j++)
  266. {
  267. totalw+=(*komp)[i][j]->getImg()->w;
  268. if(maxh<(*komp)[i][j]->getImg()->h)
  269. maxh=(*komp)[i][j]->getImg()->h;
  270. }
  271. if(_or)
  272. totalw += (inter*2+_or->w) * ((*komp)[i].size() - 1);
  273. else
  274. totalw += (inter) * ((*komp)[i].size() - 1);
  275. curh+=maxh/2;
  276. int curw = (ret->w/2)-(totalw/2);
  277. for(int j=0;j<(*komp)[i].size();j++)
  278. {
  279. blitAt((*komp)[i][j]->getImg(),curw,curh-((*komp)[i][j]->getImg()->h/2),ret);
  280. (*komp)[i][j]->pos.x = curw;
  281. (*komp)[i][j]->pos.y = curh-((*komp)[i][j]->getImg()->h/2);
  282. CSDL_Ext::printAtMiddle((*komp)[i][j]->subtitle,curw+(*komp)[i][j]->getImg()->w/2,curh+((*komp)[i][j]->getImg()->h/2)+10,GEOR13,zwykly,ret);
  283. curw += (*komp)[i][j]->getImg()->w;
  284. if(j<((*komp)[i].size()-1))
  285. {
  286. if(_or)
  287. {
  288. curw+=inter;
  289. blitAt(_or,curw,curh-(_or->h/2),ret);
  290. curw+=_or->w;
  291. }
  292. curw+=inter;
  293. }
  294. }
  295. curh+=maxh/2;
  296. curh += 20; //todo: check subtitle length
  297. }
  298. return ret;
  299. }
  300. std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext)
  301. {
  302. std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
  303. txtg->resize(brtext->size());
  304. for (int i=0; i<brtext->size();i++) //foreach line
  305. {
  306. while((*brtext)[i].length()) //jesli zostalo cos
  307. {
  308. int z=0; bool br=true;
  309. while( ((*brtext)[i][z]) != ('{') )
  310. {
  311. if (z >= (((*brtext)[i].length())-1))
  312. {
  313. br=false;
  314. break;
  315. }
  316. z++;
  317. }
  318. if (!br)
  319. z++;
  320. if (z)
  321. (*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(0,z).c_str(),zwykly));
  322. (*brtext)[i].erase(0,z);
  323. z=0;
  324. if ( ((*brtext)[i].length()==0) || ((*brtext)[i][z]!='{') )
  325. {
  326. continue;
  327. }
  328. while( ((*brtext)[i][++z]) != ('}') )
  329. {}
  330. //tyemp = (*brtext)[i].substr(1,z-1); //od 1 bo pomijamy otwierajaca klamre
  331. (*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(1,z-1).c_str(),tytulowy));
  332. (*brtext)[i].erase(0,z+1); //z+1 bo dajemy zamykajaca klamre
  333. } //ends while((*brtext)[i].length())
  334. } //ends for(int i=0; i<brtext->size();i++)
  335. return txtg;
  336. }
  337. CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
  338. {
  339. CSimpleWindow * ret = new CSimpleWindow();
  340. std::vector<std::string> * brtext = breakText(text,32,true,true);
  341. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  342. std::pair<int,int> txts = getMaxSizes(txtg);
  343. ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0);
  344. ret->pos.h=ret->bitmap->h;
  345. ret->pos.w=ret->bitmap->w;
  346. int curh = ret->bitmap->h/2 - (19*txtg->size())/2;
  347. blitTextOnSur(txtg,curh,ret->bitmap);
  348. delete brtext;
  349. delete txtg;
  350. return ret;
  351. }
  352. std::vector< std::vector<SComponent*> > * CMessage::breakComps(std::vector<SComponent*> & comps,int maxw, SDL_Surface* _or)
  353. {
  354. std::vector< std::vector<SComponent*> > * ret = new std::vector< std::vector<SComponent*> >();
  355. ret->resize(1);
  356. int rvi = 0;
  357. int curw = 0;
  358. for(int i=0;i<comps.size();i++)
  359. {
  360. curw += (comps[i]->getImg()->w + 12 + (_or ? _or->w : 0));
  361. if (curw > maxw)
  362. {
  363. curw = 0;
  364. rvi++;
  365. ret->resize(rvi+1);
  366. }
  367. (*ret)[rvi].push_back(comps[i]);
  368. }
  369. return ret;
  370. }
  371. SDL_Surface * CMessage::drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline)
  372. {
  373. int curh;
  374. std::vector<std::string> * tekst = breakText(text,charperline);
  375. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
  376. std::pair<int,int> txts = getMaxSizes(txtg), boxs;
  377. boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width
  378. + 50; //side margins
  379. boxs.second =
  380. (curh=45) //top margin
  381. + txts.second //text total height
  382. + 55 //text <=> img
  383. + bitmap->h
  384. + 5 // to sibtitle
  385. + (*txtg)[0][0]->h
  386. + 30;
  387. SDL_Surface *ret = drawBox1(boxs.first,boxs.second,player);
  388. blitTextOnSur(txtg,curh,ret);
  389. curh += 55;
  390. blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
  391. curh += bitmap->h + 5;
  392. CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+( ((*txtg)[0][0]->h) / 2 ),GEOR13,zwykly,ret);
  393. return ret;
  394. }
  395. void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline)
  396. {
  397. std::vector<std::string> * brtext = breakText(text,charperline,true,true);
  398. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  399. std::pair<int,int> txts = getMaxSizes(txtg);
  400. if(ret->buttons.size())
  401. txts.second += 20 + //before button
  402. ok->ourImages[0].bitmap->h; //button
  403. if (ret->components.size())
  404. txts.second += 30 //space to first component
  405. + ret->components[0]->getImg()->h
  406. + 5 //img <-> subtitle
  407. + 20; //subtitle //TODO: check how much place will be needed for subtitle
  408. ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
  409. ret->pos.h=ret->bitmap->h;
  410. ret->pos.w=ret->bitmap->w;
  411. ret->pos.x=300-(ret->pos.w/2);
  412. ret->pos.y=300-(ret->pos.h/2);
  413. int curh = 30; //gorny margines
  414. blitTextOnSur(txtg,curh,ret->bitmap);
  415. if (ret->components.size())
  416. {
  417. curh += 30;
  418. if(ret->components.size()==1)
  419. {
  420. blitCompsOnSur(ret->components,200,0,curh,ret->bitmap);
  421. }
  422. else
  423. {
  424. SDL_Surface * _or = 0;
  425. if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
  426. _or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
  427. std::vector< std::vector<SComponent*> > * komp = breakComps(reinterpret_cast<std::vector<SComponent*>&>(ret->components),500,_or);
  428. blitCompsOnSur(_or,komp,10,curh,ret->bitmap);
  429. delete komp;
  430. }
  431. }
  432. if(ret->buttons.size())
  433. {
  434. curh += 20; //to buttton
  435. int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them
  436. for(int i=0; i<ret->buttons.size(); i++) //and add buttons width
  437. bw+=ret->buttons[i]->imgs[0][0]->w;
  438. bw = (ret->bitmap->w/2) - (bw/2);
  439. for(int i=0; i<ret->buttons.size(); i++)
  440. {
  441. ret->buttons[i]->pos.x = bw + ret->pos.x;
  442. ret->buttons[i]->pos.y = curh + ret->pos.y;
  443. bw += ret->buttons[i]->imgs[0][0]->w + 20;
  444. }
  445. }
  446. for(int i=0; i<ret->components.size(); i++)
  447. {
  448. ret->components[i]->pos.x += ret->pos.x;
  449. ret->components[i]->pos.y += ret->pos.y;
  450. }
  451. delete brtext;
  452. delete txtg;
  453. }
  454. CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> & comps, int owner)
  455. {
  456. //CSelWindow * ret = new CSelWindow();
  457. //std::vector<std::string> * tekst = breakText(text,charperline);
  458. //std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
  459. //std::pair<int,int> txts = getMaxSizes(txtg);
  460. //txts.first+=45; //side margins
  461. //int curh = 50; //top margin
  462. ////std::pair<int,int> txts2 = getMaxSizes(komp);
  463. //ret->pos.h = txts.second //wys. tekstu
  464. // //+ txts2.second //wys komponentow
  465. // + 20 //podpis pod komponentami
  466. // + 55 //gorny margines
  467. // + 60 //text <=> comps
  468. // + 20 //comps <=> button
  469. // + ok->ourImages[0].bitmap->h //button
  470. // + 30; //bottom margin
  471. //ret->pos.w = std::max(txts.first,txts.second);
  472. //ret->bitmap = drawBox1(ret->pos.w,ret->pos.h,player);
  473. //blitTextOnSur(txtg,curh,ret->bitmap);
  474. //curh += 50;
  475. //blitCompsOnSur(_or,komp,10,curh,ret->bitmap);
  476. //curh += 30; //to buttton
  477. //ret->buttons[0]->pos.x = (ret->bitmap->w/2) - (ret->buttons[0]->imgs[0][0]->w/2);
  478. //ret->buttons[0]->pos.y = curh;
  479. //ret->buttons[0]->show();
  480. //curh += ret->buttons[0]->imgs[0][0]->h;
  481. //SDL_FreeSurface(_or);
  482. //delete komp;
  483. //delete tekst;
  484. return NULL;
  485. }
  486. SDL_Surface * CMessage::genMessage
  487. (std::string title, std::string text, EWindowType type, std::vector<CDefHandler*> *addPics, void * cb)
  488. {
  489. //max x 320 okolo 30 znakow
  490. std::vector<std::string> * tekst;
  491. if (text.length() < 30) //nie trzeba polamac
  492. {
  493. tekst = new std::vector<std::string>();
  494. tekst->push_back(text);
  495. }
  496. else tekst = breakText(text);
  497. int ww, hh; //wymiary boksa
  498. if (319>30+13*text.length())
  499. ww = 30+13*text.length();
  500. else ww = 319;
  501. if (title.length())
  502. hh=110+(21*tekst->size());
  503. else hh=60+(21*tekst->size());
  504. if (type==yesOrNO) //make place for buttons
  505. {
  506. if (ww<200) ww=200;
  507. hh+=70;
  508. }
  509. SDL_Surface * ret = drawBox1(ww,hh,0);
  510. //prepare title text
  511. if (title.length())
  512. {
  513. //SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB16,title.c_str(),tytulowy,tlo);
  514. SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy);
  515. //draw title
  516. SDL_Rect tytul = genRect(titleText->h,titleText->w,((ret->w/2)-(titleText->w/2)),37);
  517. SDL_BlitSurface(titleText,NULL,ret,&tytul);
  518. SDL_FreeSurface(titleText);
  519. }
  520. //draw text
  521. for (int i=0; i<tekst->size(); i++)
  522. {
  523. int by = 37+i*21;
  524. if (title.length()) by+=40;
  525. //SDL_Surface * tresc = TTF_RenderText_Shaded(TNRB16,(*tekst)[i].c_str(),zwykly,tlo);
  526. SDL_Surface * tresc = TTF_RenderText_Blended(TNRB16,(*tekst)[i].c_str(),zwykly);
  527. SDL_Rect trescRect = genRect(tresc->h,tresc->w,((ret->w/2)-(tresc->w/2)),by);
  528. SDL_BlitSurface(tresc,NULL,ret,&trescRect);
  529. SDL_FreeSurface(tresc);
  530. }
  531. if (type==yesOrNO) // add buttons
  532. {
  533. int by = 77+tekst->size()*21;
  534. if (title.length()) by+=40;
  535. int hwo = (*addPics)[0]->ourImages[0].bitmap->w, hwc=(*addPics)[0]->ourImages[0].bitmap->w;
  536. //ok
  537. SDL_Rect trescRect = genRect((*addPics)[0]->ourImages[0].bitmap->h,hwo,((ret->w/2)-hwo-10),by);
  538. SDL_BlitSurface((*addPics)[0]->ourImages[0].bitmap,NULL,ret,&trescRect);
  539. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  540. //cancel
  541. trescRect = genRect((*addPics)[1]->ourImages[0].bitmap->h,hwc,((ret->w/2)+10),by);
  542. SDL_BlitSurface((*addPics)[1]->ourImages[0].bitmap,NULL,ret,&trescRect);
  543. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  544. }
  545. delete tekst;
  546. return ret;
  547. }