CMessage.cpp 17 KB

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