CSpellWindow.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. exitBtn = new ClickableArea(genRect(45, 35, 569, 407), boost::bind(&CSpellWindow::fexitb, this));
  49. statusBar = new CStatusBar(97, 571, "Spelroll.bmp");
  50. }
  51. CSpellWindow::~CSpellWindow()
  52. {
  53. SDL_FreeSurface(background);
  54. SDL_FreeSurface(leftCorner);
  55. SDL_FreeSurface(rightCorner);
  56. delete spells;
  57. delete spellTab;
  58. delete schools;
  59. delete schoolW;
  60. delete schoolE;
  61. delete schoolF;
  62. delete schoolA;
  63. delete exitBtn;
  64. delete statusBar;
  65. }
  66. void CSpellWindow::fexitb()
  67. {
  68. deactivate();
  69. for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  70. {
  71. if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
  72. {
  73. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  74. break;
  75. }
  76. }
  77. delete this;
  78. LOCPLINT->curint->activate();
  79. }
  80. void CSpellWindow::show(SDL_Surface *to)
  81. {
  82. if(to == NULL) //evaluating to
  83. to = screen;
  84. SDL_BlitSurface(background, NULL, to, &pos);
  85. blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
  86. statusBar->show();
  87. }
  88. void CSpellWindow::activate()
  89. {
  90. exitBtn->activate();
  91. }
  92. void CSpellWindow::deactivate()
  93. {
  94. exitBtn->deactivate();
  95. }