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