WindowHandler.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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::topWindowImpl() const
  61. {
  62. if(windowsStack.empty())
  63. return nullptr;
  64. return windowsStack.back();
  65. }
  66. bool WindowHandler::isTopWindow(std::shared_ptr<IShowActivatable> window) const
  67. {
  68. assert(window != nullptr);
  69. return !windowsStack.empty() && windowsStack.back() == window;
  70. }
  71. bool WindowHandler::isTopWindow(IShowActivatable * window) const
  72. {
  73. assert(window != nullptr);
  74. return !windowsStack.empty() && windowsStack.back().get() == window;
  75. }
  76. void WindowHandler::totalRedraw()
  77. {
  78. CSDL_Ext::fillSurface(screen2, Colors::BLACK);
  79. for(auto & elem : windowsStack)
  80. elem->showAll(screen2);
  81. CSDL_Ext::blitAt(screen2, 0, 0, screen);
  82. }
  83. void WindowHandler::simpleRedraw()
  84. {
  85. //update only top interface and draw background
  86. if(windowsStack.size() > 1)
  87. CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
  88. if(!windowsStack.empty())
  89. windowsStack.back()->show(screen); //blit active interface/window
  90. }
  91. void WindowHandler::onScreenResize()
  92. {
  93. for(const auto & entry : windowsStack)
  94. entry->onScreenResize();
  95. totalRedraw();
  96. }
  97. void WindowHandler::onFrameRendered()
  98. {
  99. disposed.clear();
  100. }
  101. size_t WindowHandler::count() const
  102. {
  103. return windowsStack.size();
  104. }
  105. void WindowHandler::clear()
  106. {
  107. if(!windowsStack.empty())
  108. windowsStack.back()->deactivate();
  109. windowsStack.clear();
  110. disposed.clear();
  111. }