2023-05-16 14:10:26 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
/// 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 14:10:26 +02:00
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
/// Temporary list of recently popped windows
|
2023-05-16 14:10:26 +02:00
|
|
|
std::vector<std::shared_ptr<IShowActivatable>> disposed;
|
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
public:
|
2023-05-16 14:10:26 +02:00
|
|
|
/// forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
|
|
|
|
void totalRedraw();
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
/// update only top windows and draw background from buffer, sets a flag, method gets called at the end of the rendering
|
2023-05-16 14:10:26 +02:00
|
|
|
void simpleRedraw();
|
|
|
|
|
|
|
|
/// called whenever user selects different resolution, requiring to center/resize all windows
|
|
|
|
void onScreenResize();
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
/// 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
|
2023-05-16 14:10:26 +02:00
|
|
|
template <typename T, typename ... Args>
|
2023-05-16 15:20:35 +02:00
|
|
|
void createAndPushWindow(Args && ... args);
|
2023-05-16 14:10:26 +02:00
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
/// pops one or more windows - deactivates top, deletes and removes given number of windows, activates new front
|
|
|
|
void popWindows(int howMany);
|
2023-05-16 14:10:26 +02:00
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
/// removes given windows from the top and activates next
|
|
|
|
void popWindow(std::shared_ptr<IShowActivatable> top);
|
2023-05-16 14:10:26 +02:00
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
/// returns top windows
|
|
|
|
std::shared_ptr<IShowActivatable> topWindow() const;
|
2023-05-16 14:10:26 +02:00
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
/// should be called after frame has been rendered to screen
|
2023-05-16 14:10:26 +02:00
|
|
|
void onFrameRendered();
|
2023-05-16 15:07:03 +02:00
|
|
|
|
|
|
|
/// returns current number of windows in the stack
|
|
|
|
size_t count() const;
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
/// 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>
|
2023-05-16 15:20:35 +02:00
|
|
|
std::vector<std::shared_ptr<T>> findWindows() const;
|
2023-05-16 14:10:26 +02:00
|
|
|
};
|
2023-05-16 15:07:03 +02:00
|
|
|
|
|
|
|
template <typename T, typename ... Args>
|
2023-05-16 15:20:35 +02:00
|
|
|
void WindowHandler::createAndPushWindow(Args && ... args)
|
2023-05-16 15:07:03 +02:00
|
|
|
{
|
2023-05-16 15:20:35 +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>
|
2023-05-16 15:20:35 +02:00
|
|
|
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;
|
|
|
|
}
|