2
0

CSpellWindow.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "CSpellWindow.h"
  2. #include "client/Graphics.h"
  3. #include "hch/CDefHandler.h"
  4. #include "hch/CObjectHandler.h"
  5. #include "SDL_Extensions.h"
  6. #include <boost/bind.hpp>
  7. #include <sstream>
  8. extern SDL_Surface * screen;
  9. extern SDL_Color tytulowy, zwykly ;
  10. extern TTF_Font *GEOR16;
  11. ClickableArea::ClickableArea(SDL_Rect &myRect, boost::function<void()> func)
  12. {
  13. pos = myRect;
  14. myFunc = func;
  15. }
  16. void ClickableArea::clickLeft(boost::logic::tribool down)
  17. {
  18. if(!down)
  19. {
  20. myFunc();
  21. }
  22. }
  23. void ClickableArea::activate()
  24. {
  25. ClickableL::activate();
  26. }
  27. void ClickableArea::deactivate()
  28. {
  29. ClickableL::deactivate();
  30. }
  31. CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4)
  32. {
  33. pos = myRect;
  34. background = BitmapHandler::loadBitmap("SpelBack.bmp");
  35. graphics->blueToPlayersAdv(background, myHero->tempOwner);
  36. std::stringstream mana;
  37. mana<<myHero->mana;
  38. CSDL_Ext::printAtMiddle(mana.str(), 434, 425, GEOR16, tytulowy, background);
  39. leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp");
  40. rightCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp");
  41. spells = CDefHandler::giveDef("Spells.def");
  42. spellTab = CDefHandler::giveDef("SpelTab.def");
  43. schools = CDefHandler::giveDef("Schools.def");
  44. schoolW = CDefHandler::giveDef("SplevW.def");
  45. schoolE = CDefHandler::giveDef("SplevE.def");
  46. schoolF = CDefHandler::giveDef("SplevF.def");
  47. schoolA = CDefHandler::giveDef("SplevA.def");
  48. SDL_Rect temp_rect = genRect(45, 35, 569, 407);
  49. exitBtn = new ClickableArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this));
  50. statusBar = new CStatusBar(97, 571, "Spelroll.bmp");
  51. }
  52. CSpellWindow::~CSpellWindow()
  53. {
  54. SDL_FreeSurface(background);
  55. SDL_FreeSurface(leftCorner);
  56. SDL_FreeSurface(rightCorner);
  57. delete spells;
  58. delete spellTab;
  59. delete schools;
  60. delete schoolW;
  61. delete schoolE;
  62. delete schoolF;
  63. delete schoolA;
  64. delete exitBtn;
  65. delete statusBar;
  66. }
  67. void CSpellWindow::fexitb()
  68. {
  69. deactivate();
  70. for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  71. {
  72. if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
  73. {
  74. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  75. break;
  76. }
  77. }
  78. delete this;
  79. LOCPLINT->curint->activate();
  80. }
  81. void CSpellWindow::show(SDL_Surface *to)
  82. {
  83. if(to == NULL) //evaluating to
  84. to = screen;
  85. SDL_BlitSurface(background, NULL, to, &pos);
  86. blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
  87. statusBar->show();
  88. }
  89. void CSpellWindow::activate()
  90. {
  91. exitBtn->activate();
  92. }
  93. void CSpellWindow::deactivate()
  94. {
  95. exitBtn->deactivate();
  96. }