1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-10 09:50:17 +02:00
vcmi/client/gui/WindowHandler.h

84 lines
2.5 KiB
C
Raw Normal View History

/*
* 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)
2023-05-16 15:07:03 +02:00
std::vector<std::shared_ptr<IShowActivatable>> windowsStack;
2023-05-16 15:07:03 +02:00
/// Temporary list of recently popped windows
std::vector<std::shared_ptr<IShowActivatable>> disposed;
2023-05-16 15:07:03 +02:00
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<IShowActivatable> newInt);
2023-05-16 15:07:03 +02:00
/// creates window of class T and pushes it to the top
template <typename T, typename ... Args>
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);
/// removes given windows from the top and activates next
void popWindow(std::shared_ptr<IShowActivatable> top);
/// returns top windows
std::shared_ptr<IShowActivatable> topWindow() const;
2023-05-16 15:07:03 +02:00
/// should be called after frame has been rendered to screen
void onFrameRendered();
2023-05-16 15:07:03 +02:00
/// returns current number of windows in the stack
size_t count() const;
/// erases all currently existing windows from the stack
2023-05-16 15:07:03 +02:00
void clear();
/// returns all existing windows of selected type
template <typename T>
std::vector<std::shared_ptr<T>> findWindows() const;
};
2023-05-16 15:07:03 +02:00
template <typename T, typename ... Args>
void WindowHandler::createAndPushWindow(Args && ... args)
2023-05-16 15:07:03 +02:00
{
auto newWindow = std::make_shared<T>(std::forward<Args>(args)...);
pushWindow(newWindow);
2023-05-16 15:07:03 +02:00
}
template <typename T>
std::vector<std::shared_ptr<T>> WindowHandler::findWindows() const
2023-05-16 15:07:03 +02:00
{
std::vector<std::shared_ptr<T>> result;
for (auto const & window : windowsStack)
{
std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(window);
if (casted)
result.push_back(casted);
}
return result;
}