WindowHandler.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * WindowHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "WindowHandler.h"
  12. #include "CGuiHandler.h"
  13. #include "CIntObject.h"
  14. #include "CursorHandler.h"
  15. #include "../CMT.h"
  16. #include "../CGameInfo.h"
  17. #include "../render/Colors.h"
  18. #include "../renderSDL/SDL_Extensions.h"
  19. void WindowHandler::popWindow(std::shared_ptr<IShowActivatable> top)
  20. {
  21. assert(windowsStack.back() == top);
  22. top->deactivate();
  23. disposed.push_back(top);
  24. windowsStack.pop_back();
  25. if(!windowsStack.empty())
  26. windowsStack.back()->activate();
  27. totalRedraw();
  28. }
  29. void WindowHandler::pushWindow(std::shared_ptr<IShowActivatable> newInt)
  30. {
  31. assert(newInt);
  32. assert(!vstd::contains(windowsStack, newInt)); // do not add same object twice
  33. //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
  34. screenBuf = screen2;
  35. if(!windowsStack.empty())
  36. windowsStack.back()->deactivate();
  37. windowsStack.push_back(newInt);
  38. CCS->curh->set(Cursor::Map::POINTER);
  39. newInt->activate();
  40. totalRedraw();
  41. }
  42. void WindowHandler::popWindows(int howMany)
  43. {
  44. if(!howMany)
  45. return; //senseless but who knows...
  46. assert(windowsStack.size() >= howMany);
  47. windowsStack.back()->deactivate();
  48. for(int i = 0; i < howMany; i++)
  49. {
  50. disposed.push_back(windowsStack.back());
  51. windowsStack.pop_back();
  52. }
  53. if(!windowsStack.empty())
  54. {
  55. windowsStack.back()->activate();
  56. totalRedraw();
  57. }
  58. GH.fakeMouseMove();
  59. }
  60. std::shared_ptr<IShowActivatable> WindowHandler::topWindow() const
  61. {
  62. if(windowsStack.empty())
  63. return nullptr;
  64. return windowsStack.back();
  65. }
  66. void WindowHandler::totalRedraw()
  67. {
  68. CSDL_Ext::fillSurface(screen2, Colors::BLACK);
  69. for(auto & elem : windowsStack)
  70. elem->showAll(screen2);
  71. CSDL_Ext::blitAt(screen2, 0, 0, screen);
  72. }
  73. void WindowHandler::simpleRedraw()
  74. {
  75. //update only top interface and draw background
  76. if(windowsStack.size() > 1)
  77. CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
  78. if(!windowsStack.empty())
  79. windowsStack.back()->show(screen); //blit active interface/window
  80. }
  81. void WindowHandler::onScreenResize()
  82. {
  83. for(const auto & entry : windowsStack)
  84. {
  85. auto intObject = std::dynamic_pointer_cast<CIntObject>(entry);
  86. if(intObject)
  87. intObject->onScreenResize();
  88. }
  89. totalRedraw();
  90. }
  91. void WindowHandler::onFrameRendered()
  92. {
  93. disposed.clear();
  94. }
  95. size_t WindowHandler::count() const
  96. {
  97. return windowsStack.size();
  98. }
  99. void WindowHandler::clear()
  100. {
  101. windowsStack.clear();
  102. disposed.clear();
  103. }