CMessage.cpp 18 KB

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