/* * WindowHandler.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #pragma once class IShowActivatable; class WindowHandler { /// list of windows. front = bottom-most (background), back = top-most (foreground) /// (includes adventure map, window windows, all kind of active dialogs, and so on) std::vector> windowsStack; /// Temporary list of recently popped windows std::vector> disposed; bool totalRedrawRequested = false; /// returns top windows std::shared_ptr topWindowImpl() const; /// forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering void totalRedrawImpl(); /// update only top windows and draw background from buffer, sets a flag, method gets called at the end of the rendering void simpleRedrawImpl(); public: /// forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering void totalRedraw(); /// update only top windows and draw background from buffer, sets a flag, method gets called at the end of the rendering void simpleRedraw(); /// called whenever user selects different resolution, requiring to center/resize all windows void onScreenResize(); /// deactivate old top windows, activates this one and pushes to the top void pushWindow(std::shared_ptr newInt); /// creates window of class T and pushes it to the top template void createAndPushWindow(Args && ... args); /// pops one or more windows - deactivates top, deletes and removes given number of windows, activates new front void popWindows(int howMany); /// returns true if current top window is a right-click popup bool isTopWindowPopup() const; /// removes given windows from the top and activates next void popWindow(std::shared_ptr top); /// returns true if selected interface is on top bool isTopWindow(std::shared_ptr window) const; bool isTopWindow(IShowActivatable * window) const; /// returns top window if it matches requested class template std::shared_ptr topWindow() const; /// should be called after frame has been rendered to screen void onFrameRendered(); /// returns current number of windows in the stack size_t count() const; /// erases all currently existing windows from the stack void clear(); /// returns all existing windows of selected type template std::vector> findWindows() const; }; template void WindowHandler::createAndPushWindow(Args && ... args) { auto newWindow = std::make_shared(std::forward(args)...); pushWindow(newWindow); } template std::vector> WindowHandler::findWindows() const { std::vector> result; for(const auto & window : windowsStack) { std::shared_ptr casted = std::dynamic_pointer_cast(window); if (casted) result.push_back(casted); } return result; } template std::shared_ptr WindowHandler::topWindow() const { return std::dynamic_pointer_cast(topWindowImpl()); }