CMessage.cpp 18 KB

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