CMessage.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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(!(*txtg)[i].size())
  216. ret.second+=19;
  217. if (ret.first<lw)
  218. ret.first=lw;
  219. }
  220. return ret;
  221. }
  222. SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret)
  223. {
  224. for (int i=0; i<txtg->size();i++)
  225. {
  226. int lw=0;
  227. for (int j=0;j<(*txtg)[i].size();j++)
  228. lw+=(*txtg)[i][j]->w; //lw - laczna szerokosc linii
  229. int pw = ret->w/2;
  230. pw -= lw/2; //poczatek tekstu (x)
  231. int tw = pw;
  232. for (int j=0;j<(*txtg)[i].size();j++) //blit text
  233. {
  234. blitAt((*txtg)[i][j],tw,curh+i*19,ret);
  235. tw+=(*txtg)[i][j]->w;
  236. SDL_FreeSurface((*txtg)[i][j]);
  237. }
  238. }
  239. curh+=txtg->size()*19;
  240. return ret;
  241. }
  242. SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret)
  243. {
  244. std::vector<std::string> * brdtext;
  245. if (comps.size())
  246. brdtext = breakText(comps[0]->subtitle,12,true,true);
  247. else
  248. brdtext = NULL;
  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<SComponent*> > * 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. if(_or)
  274. totalw += (inter*2+_or->w) * ((*komp)[i].size() - 1);
  275. else
  276. totalw += (inter) * ((*komp)[i].size() - 1);
  277. curh+=maxh/2;
  278. int curw = (ret->w/2)-(totalw/2);
  279. for(int j=0;j<(*komp)[i].size();j++)
  280. {
  281. blitAt((*komp)[i][j]->getImg(),curw,curh-((*komp)[i][j]->getImg()->h/2),ret);
  282. (*komp)[i][j]->pos.x = curw;
  283. (*komp)[i][j]->pos.y = curh-((*komp)[i][j]->getImg()->h/2);
  284. 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);
  285. curw += (*komp)[i][j]->getImg()->w;
  286. if(j<((*komp)[i].size()-1))
  287. {
  288. if(_or)
  289. {
  290. curw+=inter;
  291. blitAt(_or,curw,curh-(_or->h/2),ret);
  292. curw+=_or->w;
  293. }
  294. curw+=inter;
  295. }
  296. }
  297. curh+=maxh/2;
  298. curh += 20; //todo: check subtitle length
  299. }
  300. return ret;
  301. }
  302. std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext)
  303. {
  304. std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
  305. txtg->resize(brtext->size());
  306. for (int i=0; i<brtext->size();i++) //foreach line
  307. {
  308. while((*brtext)[i].length()) //jesli zostalo cos
  309. {
  310. int z=0; bool br=true;
  311. while( ((*brtext)[i][z]) != ('{') )
  312. {
  313. if (z >= (((*brtext)[i].length())-1))
  314. {
  315. br=false;
  316. break;
  317. }
  318. z++;
  319. }
  320. if (!br)
  321. z++;
  322. if (z)
  323. (*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(0,z).c_str(),zwykly));
  324. (*brtext)[i].erase(0,z);
  325. z=0;
  326. if ( ((*brtext)[i].length()==0) || ((*brtext)[i][z]!='{') )
  327. {
  328. continue;
  329. }
  330. while( ((*brtext)[i][++z]) != ('}') )
  331. {}
  332. //tyemp = (*brtext)[i].substr(1,z-1); //od 1 bo pomijamy otwierajaca klamre
  333. (*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(1,z-1).c_str(),tytulowy));
  334. (*brtext)[i].erase(0,z+1); //z+1 bo dajemy zamykajaca klamre
  335. } //ends while((*brtext)[i].length())
  336. } //ends for(int i=0; i<brtext->size();i++)
  337. return txtg;
  338. }
  339. CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
  340. {
  341. CSimpleWindow * ret = new CSimpleWindow();
  342. std::vector<std::string> * brtext = breakText(text,32,true,true);
  343. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  344. std::pair<int,int> txts = getMaxSizes(txtg);
  345. ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0);
  346. ret->pos.h=ret->bitmap->h;
  347. ret->pos.w=ret->bitmap->w;
  348. int curh = ret->bitmap->h/2 - (19*txtg->size())/2;
  349. blitTextOnSur(txtg,curh,ret->bitmap);
  350. delete brtext;
  351. delete txtg;
  352. return ret;
  353. }
  354. std::vector< std::vector<SComponent*> > * CMessage::breakComps(std::vector<SComponent*> & comps,int maxw, SDL_Surface* _or)
  355. {
  356. std::vector< std::vector<SComponent*> > * ret = new std::vector< std::vector<SComponent*> >();
  357. ret->resize(1);
  358. int rvi = 0;
  359. int curw = 0;
  360. for(int i=0;i<comps.size();i++)
  361. {
  362. curw += (comps[i]->getImg()->w + 12 + (_or ? _or->w : 0));
  363. if (curw > maxw)
  364. {
  365. curw = 0;
  366. rvi++;
  367. ret->resize(rvi+1);
  368. }
  369. (*ret)[rvi].push_back(comps[i]);
  370. }
  371. return ret;
  372. }
  373. SDL_Surface * CMessage::drawBoxTextBitmapSub( int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline/*=30*/, int imgToBmp/*=55*/ )
  374. {
  375. int curh;
  376. std::vector<std::string> * tekst = breakText(text,charperline);
  377. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
  378. std::pair<int,int> txts = getMaxSizes(txtg), boxs;
  379. boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width
  380. + 50; //side margins
  381. boxs.second =
  382. (curh=45) //top margin
  383. + txts.second //text total height
  384. + imgToBmp //text <=> img
  385. + bitmap->h
  386. + 5 // to sibtitle
  387. + (*txtg)[0][0]->h
  388. + 30;
  389. SDL_Surface *ret = drawBox1(boxs.first,boxs.second,player);
  390. blitTextOnSur(txtg,curh,ret);
  391. curh += imgToBmp;
  392. blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
  393. curh += bitmap->h + 5;
  394. CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+( ((*txtg)[0][0]->h) / 2 ),GEOR13,zwykly,ret);
  395. delete tekst;
  396. delete txtg;
  397. return ret;
  398. }
  399. void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline)
  400. {
  401. std::vector<std::string> * brtext = breakText(text,charperline,true,true);
  402. std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
  403. std::pair<int,int> txts = getMaxSizes(txtg);
  404. if(ret->buttons.size())
  405. txts.second += 20 + //before button
  406. ok->ourImages[0].bitmap->h; //button
  407. if (ret->components.size())
  408. txts.second += 30 //space to first component
  409. + ret->components[0]->getImg()->h
  410. + 5 //img <-> subtitle
  411. + 20; //subtitle //TODO: check how much place will be needed for subtitle
  412. ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
  413. ret->pos.h=ret->bitmap->h;
  414. ret->pos.w=ret->bitmap->w;
  415. ret->pos.x=300-(ret->pos.w/2);
  416. ret->pos.y=300-(ret->pos.h/2);
  417. int curh = 30; //gorny margines
  418. blitTextOnSur(txtg,curh,ret->bitmap);
  419. if (ret->components.size())
  420. {
  421. curh += 30;
  422. if(ret->components.size()==1)
  423. {
  424. blitCompsOnSur(ret->components,200,0,curh,ret->bitmap);
  425. }
  426. else
  427. {
  428. SDL_Surface * _or = 0;
  429. if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
  430. _or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
  431. std::vector< std::vector<SComponent*> > * komp = breakComps(reinterpret_cast<std::vector<SComponent*>&>(ret->components),500,_or);
  432. blitCompsOnSur(_or,komp,10,curh,ret->bitmap);
  433. delete komp;
  434. }
  435. }
  436. if(ret->buttons.size())
  437. {
  438. curh += 20; //to buttton
  439. int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them
  440. for(int i=0; i<ret->buttons.size(); i++) //and add buttons width
  441. bw+=ret->buttons[i]->imgs[0][0]->w;
  442. bw = (ret->bitmap->w/2) - (bw/2);
  443. for(int i=0; i<ret->buttons.size(); i++)
  444. {
  445. ret->buttons[i]->pos.x = bw + ret->pos.x;
  446. ret->buttons[i]->pos.y = curh + ret->pos.y;
  447. bw += ret->buttons[i]->imgs[0][0]->w + 20;
  448. }
  449. }
  450. for(int i=0; i<ret->components.size(); i++)
  451. {
  452. ret->components[i]->pos.x += ret->pos.x;
  453. ret->components[i]->pos.y += ret->pos.y;
  454. }
  455. delete brtext;
  456. delete txtg;
  457. }
  458. CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> & comps, int owner)
  459. {
  460. //CSelWindow * ret = new CSelWindow();
  461. //std::vector<std::string> * tekst = breakText(text,charperline);
  462. //std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
  463. //std::pair<int,int> txts = getMaxSizes(txtg);
  464. //txts.first+=45; //side margins
  465. //int curh = 50; //top margin
  466. ////std::pair<int,int> txts2 = getMaxSizes(komp);
  467. //ret->pos.h = txts.second //wys. tekstu
  468. // //+ txts2.second //wys komponentow
  469. // + 20 //podpis pod komponentami
  470. // + 55 //gorny margines
  471. // + 60 //text <=> comps
  472. // + 20 //comps <=> button
  473. // + ok->ourImages[0].bitmap->h //button
  474. // + 30; //bottom margin
  475. //ret->pos.w = std::max(txts.first,txts.second);
  476. //ret->bitmap = drawBox1(ret->pos.w,ret->pos.h,player);
  477. //blitTextOnSur(txtg,curh,ret->bitmap);
  478. //curh += 50;
  479. //blitCompsOnSur(_or,komp,10,curh,ret->bitmap);
  480. //curh += 30; //to buttton
  481. //ret->buttons[0]->pos.x = (ret->bitmap->w/2) - (ret->buttons[0]->imgs[0][0]->w/2);
  482. //ret->buttons[0]->pos.y = curh;
  483. //ret->buttons[0]->show();
  484. //curh += ret->buttons[0]->imgs[0][0]->h;
  485. //SDL_FreeSurface(_or);
  486. //delete komp;
  487. //delete tekst;
  488. return NULL;
  489. }
  490. SDL_Surface * CMessage::genMessage
  491. (std::string title, std::string text, EWindowType type, std::vector<CDefHandler*> *addPics, void * cb)
  492. {
  493. //max x 320 okolo 30 znakow
  494. std::vector<std::string> * tekst;
  495. if (text.length() < 30) //nie trzeba polamac
  496. {
  497. tekst = new std::vector<std::string>();
  498. tekst->push_back(text);
  499. }
  500. else tekst = breakText(text);
  501. int ww, hh; //wymiary boksa
  502. if (319>30+13*text.length())
  503. ww = 30+13*text.length();
  504. else ww = 319;
  505. if (title.length())
  506. hh=110+(21*tekst->size());
  507. else hh=60+(21*tekst->size());
  508. if (type==yesOrNO) //make place for buttons
  509. {
  510. if (ww<200) ww=200;
  511. hh+=70;
  512. }
  513. SDL_Surface * ret = drawBox1(ww,hh,0);
  514. //prepare title text
  515. if (title.length())
  516. {
  517. //SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB16,title.c_str(),tytulowy,tlo);
  518. SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy);
  519. //draw title
  520. SDL_Rect tytul = genRect(titleText->h,titleText->w,((ret->w/2)-(titleText->w/2)),37);
  521. SDL_BlitSurface(titleText,NULL,ret,&tytul);
  522. SDL_FreeSurface(titleText);
  523. }
  524. //draw text
  525. for (int i=0; i<tekst->size(); i++)
  526. {
  527. int by = 37+i*21;
  528. if (title.length()) by+=40;
  529. //SDL_Surface * tresc = TTF_RenderText_Shaded(TNRB16,(*tekst)[i].c_str(),zwykly,tlo);
  530. SDL_Surface * tresc = TTF_RenderText_Blended(TNRB16,(*tekst)[i].c_str(),zwykly);
  531. SDL_Rect trescRect = genRect(tresc->h,tresc->w,((ret->w/2)-(tresc->w/2)),by);
  532. SDL_BlitSurface(tresc,NULL,ret,&trescRect);
  533. SDL_FreeSurface(tresc);
  534. }
  535. if (type==yesOrNO) // add buttons
  536. {
  537. int by = 77+tekst->size()*21;
  538. if (title.length()) by+=40;
  539. int hwo = (*addPics)[0]->ourImages[0].bitmap->w, hwc=(*addPics)[0]->ourImages[0].bitmap->w;
  540. //ok
  541. SDL_Rect trescRect = genRect((*addPics)[0]->ourImages[0].bitmap->h,hwo,((ret->w/2)-hwo-10),by);
  542. SDL_BlitSurface((*addPics)[0]->ourImages[0].bitmap,NULL,ret,&trescRect);
  543. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  544. //cancel
  545. trescRect = genRect((*addPics)[1]->ourImages[0].bitmap->h,hwc,((ret->w/2)+10),by);
  546. SDL_BlitSurface((*addPics)[1]->ourImages[0].bitmap,NULL,ret,&trescRect);
  547. ((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
  548. }
  549. delete tekst;
  550. return ret;
  551. }