2023-05-16 14:10:26 +02:00
|
|
|
/*
|
|
|
|
* WindowHandler.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "WindowHandler.h"
|
|
|
|
|
|
|
|
#include "CGuiHandler.h"
|
|
|
|
#include "CIntObject.h"
|
|
|
|
#include "CursorHandler.h"
|
|
|
|
|
|
|
|
#include "../CMT.h"
|
|
|
|
#include "../CGameInfo.h"
|
2023-06-02 15:42:18 +02:00
|
|
|
#include "../render/Canvas.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "../render/Colors.h"
|
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
void WindowHandler::popWindow(std::shared_ptr<IShowActivatable> top)
|
2023-05-16 14:10:26 +02:00
|
|
|
{
|
2024-04-07 13:19:57 +02:00
|
|
|
if (windowsStack.back() != top)
|
|
|
|
throw std::runtime_error("Attempt to pop non-top window from stack!");
|
|
|
|
|
2023-05-16 14:10:26 +02:00
|
|
|
top->deactivate();
|
|
|
|
disposed.push_back(top);
|
2023-05-16 15:07:03 +02:00
|
|
|
windowsStack.pop_back();
|
|
|
|
if(!windowsStack.empty())
|
|
|
|
windowsStack.back()->activate();
|
|
|
|
|
2023-05-16 14:10:26 +02:00
|
|
|
totalRedraw();
|
|
|
|
}
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
void WindowHandler::pushWindow(std::shared_ptr<IShowActivatable> newInt)
|
2023-05-16 14:10:26 +02:00
|
|
|
{
|
2024-04-07 13:19:57 +02:00
|
|
|
if (newInt == nullptr)
|
|
|
|
throw std::runtime_error("Attempt to push null window onto windows stack!");
|
|
|
|
|
|
|
|
if (vstd::contains(windowsStack, newInt))
|
|
|
|
throw std::runtime_error("Attempt to add already existing window to stack!");
|
2023-05-16 14:10:26 +02:00
|
|
|
|
|
|
|
//a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
|
|
|
|
screenBuf = screen2;
|
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
if(!windowsStack.empty())
|
|
|
|
windowsStack.back()->deactivate();
|
|
|
|
windowsStack.push_back(newInt);
|
2023-05-16 14:10:26 +02:00
|
|
|
CCS->curh->set(Cursor::Map::POINTER);
|
|
|
|
newInt->activate();
|
|
|
|
totalRedraw();
|
|
|
|
}
|
|
|
|
|
2023-06-11 19:38:42 +02:00
|
|
|
bool WindowHandler::isTopWindowPopup() const
|
|
|
|
{
|
|
|
|
if (windowsStack.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return windowsStack.back()->isPopupWindow();
|
|
|
|
}
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
void WindowHandler::popWindows(int howMany)
|
2023-05-16 14:10:26 +02:00
|
|
|
{
|
|
|
|
if(!howMany)
|
|
|
|
return; //senseless but who knows...
|
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
assert(windowsStack.size() >= howMany);
|
|
|
|
windowsStack.back()->deactivate();
|
2023-05-16 14:10:26 +02:00
|
|
|
for(int i = 0; i < howMany; i++)
|
|
|
|
{
|
2023-05-16 15:07:03 +02:00
|
|
|
disposed.push_back(windowsStack.back());
|
|
|
|
windowsStack.pop_back();
|
2023-05-16 14:10:26 +02:00
|
|
|
}
|
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
if(!windowsStack.empty())
|
2023-05-16 14:10:26 +02:00
|
|
|
{
|
2023-05-16 15:07:03 +02:00
|
|
|
windowsStack.back()->activate();
|
2023-05-16 14:10:26 +02:00
|
|
|
totalRedraw();
|
|
|
|
}
|
|
|
|
GH.fakeMouseMove();
|
|
|
|
}
|
|
|
|
|
2023-05-16 17:34:23 +02:00
|
|
|
std::shared_ptr<IShowActivatable> WindowHandler::topWindowImpl() const
|
2023-05-16 14:10:26 +02:00
|
|
|
{
|
2023-05-16 15:07:03 +02:00
|
|
|
if(windowsStack.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return windowsStack.back();
|
2023-05-16 14:10:26 +02:00
|
|
|
}
|
|
|
|
|
2023-05-16 17:34:23 +02:00
|
|
|
bool WindowHandler::isTopWindow(std::shared_ptr<IShowActivatable> window) const
|
|
|
|
{
|
|
|
|
assert(window != nullptr);
|
|
|
|
return !windowsStack.empty() && windowsStack.back() == window;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowHandler::isTopWindow(IShowActivatable * window) const
|
|
|
|
{
|
|
|
|
assert(window != nullptr);
|
|
|
|
return !windowsStack.empty() && windowsStack.back().get() == window;
|
|
|
|
}
|
|
|
|
|
2023-05-16 14:10:26 +02:00
|
|
|
void WindowHandler::totalRedraw()
|
|
|
|
{
|
2023-07-18 16:28:07 +02:00
|
|
|
totalRedrawRequested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowHandler::totalRedrawImpl()
|
|
|
|
{
|
|
|
|
logGlobal->debug("totalRedraw requested!");
|
2023-05-16 14:10:26 +02:00
|
|
|
|
2024-07-22 13:00:45 +02:00
|
|
|
Canvas target = Canvas::createFromSurface(screen2, CanvasScalingPolicy::AUTO);
|
2023-06-02 15:42:18 +02:00
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
for(auto & elem : windowsStack)
|
2023-06-02 15:42:18 +02:00
|
|
|
elem->showAll(target);
|
2023-05-16 14:10:26 +02:00
|
|
|
CSDL_Ext::blitAt(screen2, 0, 0, screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowHandler::simpleRedraw()
|
2023-07-18 16:28:07 +02:00
|
|
|
{
|
|
|
|
if (totalRedrawRequested)
|
|
|
|
totalRedrawImpl();
|
|
|
|
else
|
|
|
|
simpleRedrawImpl();
|
|
|
|
|
|
|
|
totalRedrawRequested = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowHandler::simpleRedrawImpl()
|
2023-05-16 14:10:26 +02:00
|
|
|
{
|
|
|
|
//update only top interface and draw background
|
2023-05-16 15:07:03 +02:00
|
|
|
if(windowsStack.size() > 1)
|
2023-05-16 14:10:26 +02:00
|
|
|
CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
|
2023-06-02 15:42:18 +02:00
|
|
|
|
2024-07-22 13:00:45 +02:00
|
|
|
Canvas target = Canvas::createFromSurface(screen, CanvasScalingPolicy::AUTO);
|
2023-06-02 15:42:18 +02:00
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
if(!windowsStack.empty())
|
2023-06-02 15:42:18 +02:00
|
|
|
windowsStack.back()->show(target); //blit active interface/window
|
2023-05-16 14:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowHandler::onScreenResize()
|
|
|
|
{
|
2023-05-16 15:07:03 +02:00
|
|
|
for(const auto & entry : windowsStack)
|
2023-05-17 22:22:45 +02:00
|
|
|
entry->onScreenResize();
|
2023-05-16 14:10:26 +02:00
|
|
|
|
|
|
|
totalRedraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowHandler::onFrameRendered()
|
|
|
|
{
|
|
|
|
disposed.clear();
|
|
|
|
}
|
2023-05-16 15:07:03 +02:00
|
|
|
|
|
|
|
size_t WindowHandler::count() const
|
|
|
|
{
|
|
|
|
return windowsStack.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowHandler::clear()
|
|
|
|
{
|
2023-05-16 17:34:23 +02:00
|
|
|
if(!windowsStack.empty())
|
|
|
|
windowsStack.back()->deactivate();
|
|
|
|
|
2023-05-16 15:07:03 +02:00
|
|
|
windowsStack.clear();
|
|
|
|
disposed.clear();
|
|
|
|
}
|