CMessage.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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 "CLua.h"
  16. #include "hch/CGeneralTextHandler.h"
  17. #include "client/Graphics.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)
  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<CSelectableComponent*> > * 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. curh += 30;
  248. comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2);
  249. comps[0]->pos.y = curh;
  250. blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret);
  251. curh += comps[0]->getImg()->h + 5; //obrazek + przerwa
  252. for (int i=0; i<brdtext->size();i++) //descr.
  253. {
  254. SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly);
  255. blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret);
  256. curh+=tesu->h;
  257. SDL_FreeSurface(tesu);
  258. }
  259. return ret;
  260. }
  261. SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector<CSelectableComponent*> > * komp, int inter, int &curh, SDL_Surface *ret)
  262. {
  263. for (int i=0;i<komp->size();i++)
  264. {
  265. int totalw=0, maxh=0;
  266. for(int j=0;j<(*komp)[i].size();j++)
  267. {
  268. totalw+=(*komp)[i][j]->getImg()->w;
  269. if(maxh<(*komp)[i][j]->getImg()->h)
  270. maxh=(*komp)[i][j]->getImg()->h;
  271. }
  272. totalw += (inter*2+or->w) * ((*komp)[i].size() - 1);
  273. curh+=maxh/2;
  274. int curw = (ret->w/2)-(totalw/2);
  275. for(int j=0;j<(*komp)[i].size();j++)
  276. {
  277. blitAt((*komp)[i][j]->getImg(),curw,curh-((*komp)[i][j]->getImg()->h/2),ret);
  278. (*komp)[i][j]->pos.x = curw;
  279. (*komp)[i][j]->pos.y = curh-((*komp)[i][j]->getImg()->h/2);
  280. 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);
  281. curw += (*komp)[i][j]->getImg()->w;
  282. if(j<((*komp)[i].size()-1))
  283. {
  284. curw+=inter;
  285. blitAt(or,curw,curh-(or->h/2),ret);
  286. curw+=or->w;
  287. curw+=inter;
  288. }
  289. }
  290. curh+=maxh/2;
  291. }
  292. return ret;
  293. }
  294. std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext)
  295. {
  296. std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
  297. txtg->resize(brtext->size());
  298. for (int i=0; i<brtext->size();i++) //foreach line
  299. {
  300. while((*brtext)[i].length()) //jesli zostalo cos
  301. {
  302. int z=0; bool br=true;
  303. while( ((*brtext)[i][z]) != ('{') )
  304. {
  305. if (z >= (((*brtext)[i].length())-1))
  306. {
  307. br=false;
  308. break;
  309. }
  310. z++;
  311. }
  312. if (!br)
  313. z++;
  314. if (z)
  315. (*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(0,z).c_str(),zwykly));
  316. (*brtext)[i].erase(0,z);
  317. z=0;
  318. if ( ((*brtext)[i].length()==0) || ((*brtext)[i][z]!='{') )
  319. {
  320. continue;
  321. }
  322. while( ((*brtext)[i][++z]) != ('}') )
  323. {}
  324. //tyemp = (*brtext)[i].substr(1,z-1); //od 1 bo pomijamy otwierajaca klamre
  325. (*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(1,z-1).c_str(),tytulowy));
  326. (*brtext)[i].erase(0,z+1); //z+1 bo dajemy zamykajaca klamre
  327. } //ends while((*brtext)[i].length())
  328. } //ends for(int i=0; i<brtext->size();i++)
  329. return txtg;
  330. }
  331. CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
  332. {
  333. CSimpleWindow * ret = new CSimpleWindow();
  334. std::vector<std::string> * brtext = breakText(text,32,true,true);
  335. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  336. std::pair<int,int> txts = getMaxSizes(txtg);
  337. ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0);
  338. ret->pos.h=ret->bitmap->h;
  339. ret->pos.w=ret->bitmap->w;
  340. for (int i=0; i<txtg->size();i++)
  341. {
  342. int lw=0;
  343. for (int j=0;j<(*txtg)[i].size();j++)
  344. lw+=(*txtg)[i][j]->w;
  345. int pw = ret->bitmap->w/2, ph = ret->bitmap->h/2;
  346. //int pw = Tmar, ph = Lmar;
  347. pw -= lw/2;
  348. ph -= (19*txtg->size())/2;
  349. int tw = pw;
  350. for (int j=0;j<(*txtg)[i].size();j++)
  351. {
  352. //std::stringstream n;
  353. //n <<"temp_"<<i<<"__"<<j<<".bmp";
  354. blitAt((*txtg)[i][j],tw,ph+i*19,ret->bitmap);
  355. //SDL_SaveBMP(ret->bitmap,n.str().c_str());
  356. tw+=(*txtg)[i][j]->w;
  357. SDL_FreeSurface((*txtg)[i][j]);
  358. }
  359. }
  360. return ret;
  361. }
  362. CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline, std::vector<SComponent*> & comps)
  363. {
  364. //TODO: support for more than one component
  365. CInfoWindow * ret = new CInfoWindow();
  366. ret->components = comps;
  367. std::vector<std::string> * brtext = breakText(text,charperline,true,true);
  368. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  369. std::pair<int,int> txts = getMaxSizes(txtg);
  370. txts.second = txts.second
  371. + ok->ourImages[0].bitmap->h //button
  372. + 15 //after button
  373. + 20; // space between subtitle and button
  374. if (comps.size())
  375. txts.second = txts.second
  376. + 30 //space to first component
  377. + comps[0]->getImg()->h
  378. + 5 //img <-> subtitle
  379. + 20; //subtitle //!!!!!!!!!!!!!!!!!!!!
  380. ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
  381. ret->pos.h=ret->bitmap->h;
  382. ret->pos.w=ret->bitmap->w;
  383. int curh = 30; //gorny margines
  384. blitTextOnSur(txtg,curh,ret->bitmap);
  385. if (comps.size())
  386. {
  387. blitCompsOnSur(comps,200,0,curh,ret->bitmap);
  388. }
  389. curh += 20; //to buttton
  390. ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2);
  391. ret->okb.posr.y = curh;
  392. ret->okb.show();
  393. curh+=ret->okb.imgs[0][0]->h;
  394. return ret;
  395. }
  396. std::vector< std::vector<CSelectableComponent*> > * CMessage::breakComps(std::vector<CSelectableComponent*> & comps,int maxw, SDL_Surface* or)
  397. {
  398. std::vector< std::vector<CSelectableComponent*> > * ret = new std::vector< std::vector<CSelectableComponent*> >();
  399. ret->resize(1);
  400. bool wywalicOr=false;
  401. if (!or)
  402. {
  403. or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
  404. wywalicOr=true;
  405. }
  406. int rvi = 0;
  407. int curw = 0;
  408. for(int i=0;i<comps.size();i++)
  409. {
  410. curw += (comps[i]->getImg()->w + 12 + or->w);
  411. if (curw > maxw)
  412. {
  413. curw = 0;
  414. rvi++;
  415. ret->resize(rvi+1);
  416. }
  417. (*ret)[rvi].push_back(comps[i]);
  418. }
  419. if (wywalicOr)
  420. {
  421. SDL_FreeSurface(or);
  422. }
  423. return ret;
  424. }
  425. SDL_Surface * CMessage::drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline)
  426. {
  427. int curh;
  428. std::vector<std::string> * tekst = breakText(text,charperline);
  429. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
  430. std::pair<int,int> txts = getMaxSizes(txtg), boxs;
  431. boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width
  432. + 50; //side margins
  433. boxs.second =
  434. (curh=45) //top margin
  435. + txts.second //text total height
  436. + 55 //text <=> img
  437. + bitmap->h
  438. + 5 // to sibtitle
  439. + (*txtg)[0][0]->h
  440. + 30;
  441. SDL_Surface *ret = drawBox1(boxs.first,boxs.second,player);
  442. blitTextOnSur(txtg,curh,ret);
  443. curh += 55;
  444. blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
  445. curh += bitmap->h + 5;
  446. CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+( ((*txtg)[0][0]->h) / 2 ),GEOR13,zwykly,ret);
  447. return ret;
  448. }
  449. CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> & comps, int owner)
  450. {
  451. CSelWindow * ret = new CSelWindow();
  452. for(int i=0;i<comps.size();i++)
  453. {
  454. ret->components.push_back(comps[i]);
  455. comps[i]->owner = ret;
  456. }
  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. SDL_Surface * or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
  463. std::vector< std::vector<CSelectableComponent*> > * komp = breakComps(comps,500,or);
  464. std::pair<int,int> txts2 = getMaxSizes(komp);
  465. ret->pos.h = txts.second //wys. tekstu
  466. + txts2.second //wys komponentow
  467. + 20 //podpis pod komponentami
  468. + 55 //gorny margines
  469. + 60 //text <=> comps
  470. + 20 //comps <=> button
  471. + ok->ourImages[0].bitmap->h //button
  472. + 30; //bottom margin
  473. ret->pos.w = std::max(txts.first,txts.second);
  474. ret->bitmap = drawBox1(ret->pos.w,ret->pos.h,player);
  475. blitTextOnSur(txtg,curh,ret->bitmap);
  476. curh += 50;
  477. blitCompsOnSur(or,komp,10,curh,ret->bitmap);
  478. curh += 30; //to buttton
  479. ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2);
  480. ret->okb.posr.y = curh;
  481. ret->okb.show();
  482. curh+=ret->okb.imgs[0][0]->h;
  483. SDL_FreeSurface(or);
  484. delete komp;
  485. delete tekst;
  486. return ret;
  487. }
  488. SDL_Surface * CMessage::genMessage
  489. (std::string title, std::string text, EWindowType type, std::vector<CDefHandler*> *addPics, void * cb)
  490. {
  491. //max x 320 okolo 30 znakow
  492. std::vector<std::string> * tekst;
  493. if (text.length() < 30) //nie trzeba polamac
  494. {
  495. tekst = new std::vector<std::string>();
  496. tekst->push_back(text);
  497. }
  498. else tekst = breakText(text);
  499. int ww, hh; //wymiary boksa
  500. if (319>30+13*text.length())
  501. ww = 30+13*text.length();
  502. else ww = 319;
  503. if (title.length())
  504. hh=110+(21*tekst->size());
  505. else hh=60+(21*tekst->size());
  506. if (type==yesOrNO) //make place for buttons
  507. {
  508. if (ww<200) ww=200;
  509. hh+=70;
  510. }
  511. SDL_Surface * ret = drawBox1(ww,hh,0);
  512. //prepare title text
  513. if (title.length())
  514. {
  515. //SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB16,title.c_str(),tytulowy,tlo);
  516. SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy);
  517. //draw title
  518. SDL_Rect tytul = genRect(titleText->h,titleText->w,((ret->w/2)-(titleText->w/2)),37);
  519. SDL_BlitSurface(titleText,NULL,ret,&tytul);
  520. SDL_FreeSurface(titleText);
  521. }
  522. //draw text
  523. for (int i=0; i<tekst->size(); i++)
  524. {
  525. int by = 37+i*21;
  526. if (title.length()) by+=40;
  527. //SDL_Surface * tresc = TTF_RenderText_Shaded(TNRB16,(*tekst)[i].c_str(),zwykly,tlo);
  528. SDL_Surface * tresc = TTF_RenderText_Blended(TNRB16,(*tekst)[i].c_str(),zwykly);
  529. SDL_Rect trescRect = genRect(tresc->h,tresc->w,((ret->w/2)-(tresc->w/2)),by);
  530. SDL_BlitSurface(tresc,NULL,ret,&trescRect);
  531. SDL_FreeSurface(tresc);
  532. }
  533. if (type==yesOrNO) // add buttons
  534. {
  535. int by = 77+tekst->size()*21;
  536. if (title.length()) by+=40;
  537. int hwo = (*addPics)[0]->ourImages[0].bitmap->w, hwc=(*addPics)[0]->ourImages[0].bitmap->w;
  538. //ok
  539. SDL_Rect trescRect = genRect((*addPics)[0]->ourImages[0].bitmap->h,hwo,((ret->w/2)-hwo-10),by);
  540. SDL_BlitSurface((*addPics)[0]->ourImages[0].bitmap,NULL,ret,&trescRect);
  541. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  542. //cancel
  543. trescRect = genRect((*addPics)[1]->ourImages[0].bitmap->h,hwc,((ret->w/2)+10),by);
  544. SDL_BlitSurface((*addPics)[1]->ourImages[0].bitmap,NULL,ret,&trescRect);
  545. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  546. }
  547. delete tekst;
  548. return ret;
  549. }