WindowHandler.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/Canvas.h"
  18. #include "../render/Colors.h"
  19. #include "../renderSDL/SDL_Extensions.h"
  20. void WindowHandler::popWindow(std::shared_ptr<IShowActivatable> top)
  21. {
  22. assert(windowsStack.back() == top);
  23. top->deactivate();
  24. disposed.push_back(top);
  25. windowsStack.pop_back();
  26. if(!windowsStack.empty())
  27. windowsStack.back()->activate();
  28. totalRedraw();
  29. }
  30. void WindowHandler::pushWindow(std::shared_ptr<IShowActivatable> newInt)
  31. {
  32. assert(newInt);
  33. assert(!vstd::contains(windowsStack, newInt)); // do not add same object twice
  34. //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
  35. screenBuf = screen2;
  36. if(!windowsStack.empty())
  37. windowsStack.back()->deactivate();
  38. windowsStack.push_back(newInt);
  39. CCS->curh->set(Cursor::Map::POINTER);
  40. newInt->activate();
  41. totalRedraw();
  42. }
  43. bool WindowHandler::isTopWindowPopup() const
  44. {
  45. if (windowsStack.empty())
  46. return false;
  47. return windowsStack.back()->isPopupWindow();
  48. }
  49. void WindowHandler::popWindows(int howMany)
  50. {
  51. if(!howMany)
  52. return; //senseless but who knows...
  53. assert(windowsStack.size() >= howMany);
  54. windowsStack.back()->deactivate();
  55. for(int i = 0; i < howMany; i++)
  56. {
  57. disposed.push_back(windowsStack.back());
  58. windowsStack.pop_back();
  59. }
  60. if(!windowsStack.empty())
  61. {
  62. windowsStack.back()->activate();
  63. totalRedraw();
  64. }
  65. GH.fakeMouseMove();
  66. }
  67. std::shared_ptr<IShowActivatable> WindowHandler::topWindowImpl() const
  68. {
  69. if(windowsStack.empty())
  70. return nullptr;
  71. return windowsStack.back();
  72. }
  73. bool WindowHandler::isTopWindow(std::shared_ptr<IShowActivatable> window) const
  74. {
  75. assert(window != nullptr);
  76. return !windowsStack.empty() && windowsStack.back() == window;
  77. }
  78. bool WindowHandler::isTopWindow(IShowActivatable * window) const
  79. {
  80. assert(window != nullptr);
  81. return !windowsStack.empty() && windowsStack.back().get() == window;
  82. }
  83. void WindowHandler::totalRedraw()
  84. {
  85. CSDL_Ext::fillSurface(screen2, Colors::BLACK);
  86. Canvas target = Canvas::createFromSurface(screen2);
  87. for(auto & elem : windowsStack)
  88. elem->showAll(target);
  89. CSDL_Ext::blitAt(screen2, 0, 0, screen);
  90. }
  91. void WindowHandler::simpleRedraw()
  92. {
  93. //update only top interface and draw background
  94. if(windowsStack.size() > 1)
  95. CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
  96. Canvas target = Canvas::createFromSurface(screen);
  97. if(!windowsStack.empty())
  98. windowsStack.back()->show(target); //blit active interface/window
  99. }
  100. void WindowHandler::onScreenResize()
  101. {
  102. for(const auto & entry : windowsStack)
  103. entry->onScreenResize();
  104. totalRedraw();
  105. }
  106. void WindowHandler::onFrameRendered()
  107. {
  108. disposed.clear();
  109. }
  110. size_t WindowHandler::count() const
  111. {
  112. return windowsStack.size();
  113. }
  114. void WindowHandler::clear()
  115. {
  116. if(!windowsStack.empty())
  117. windowsStack.back()->deactivate();
  118. windowsStack.clear();
  119. disposed.clear();
  120. }