mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-12 04:14:05 +00:00
Do not allow to move resizable windows outside of game window
This commit is contained in:
parent
939760007e
commit
1b544b93d2
@ -417,6 +417,8 @@ namespace MWGui
|
||||
|
||||
void InventoryWindow::onWindowResize(MyGUI::Window* _sender)
|
||||
{
|
||||
WindowBase::clampWindowCoordinates(_sender);
|
||||
|
||||
adjustPanes();
|
||||
const WindowSettingValues settings = getModeSettings(mGuiMode);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include <components/settings/values.hpp>
|
||||
#include <components/widgets/imagebutton.hpp>
|
||||
|
||||
#include "draganddrop.hpp"
|
||||
@ -77,6 +78,34 @@ void WindowBase::center()
|
||||
mMainWidget->setCoord(coord);
|
||||
}
|
||||
|
||||
void WindowBase::clampWindowCoordinates(MyGUI::Window* window)
|
||||
{
|
||||
auto minSize = window->getMinSize();
|
||||
minSize.height = static_cast<int>(minSize.height * Settings::gui().mScalingFactor);
|
||||
minSize.width = static_cast<int>(minSize.width * Settings::gui().mScalingFactor);
|
||||
|
||||
// Window's minimum size is larger than the screen size, can not clamp coordinates
|
||||
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
if (minSize.width > viewSize.width || minSize.height > viewSize.height)
|
||||
return;
|
||||
|
||||
int left = std::max(0, window->getPosition().left);
|
||||
int top = std::max(0, window->getPosition().top);
|
||||
int width = std::clamp(window->getSize().width, 0, viewSize.width);
|
||||
int height = std::clamp(window->getSize().height, 0, viewSize.height);
|
||||
if (left + width > viewSize.width)
|
||||
left = viewSize.width - width;
|
||||
|
||||
if (top + height > viewSize.height)
|
||||
top = viewSize.height - height;
|
||||
|
||||
if (window->getSize().width != width || window->getSize().height != height)
|
||||
window->setSize(width, height);
|
||||
|
||||
if (window->getPosition().left != left || window->getPosition().top != top)
|
||||
window->setPosition(left, top);
|
||||
}
|
||||
|
||||
WindowModal::WindowModal(const std::string& parLayout)
|
||||
: WindowBase(parLayout)
|
||||
{
|
||||
|
@ -52,6 +52,8 @@ namespace MWGui
|
||||
virtual std::string_view getWindowIdForLua() const { return ""; }
|
||||
void setDisabledByLua(bool disabled) { mDisabledByLua = disabled; }
|
||||
|
||||
static void clampWindowCoordinates(MyGUI::Window* window);
|
||||
|
||||
protected:
|
||||
virtual void onTitleDoubleClicked();
|
||||
|
||||
|
@ -1200,6 +1200,8 @@ namespace MWGui
|
||||
const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mMaximized : settings.mRegular;
|
||||
window->setPosition(MyGUI::IntPoint(static_cast<int>(rect.mX * x), static_cast<int>(rect.mY * y)));
|
||||
window->setSize(MyGUI::IntSize(static_cast<int>(rect.mW * x), static_cast<int>(rect.mH * y)));
|
||||
|
||||
WindowBase::clampWindowCoordinates(window);
|
||||
}
|
||||
|
||||
for (const auto& window : mWindows)
|
||||
@ -1714,13 +1716,15 @@ namespace MWGui
|
||||
|
||||
const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mMaximized : settings.mRegular;
|
||||
|
||||
layout->mMainWidget->setPosition(
|
||||
MyGUI::Window* window = layout->mMainWidget->castType<MyGUI::Window>();
|
||||
window->setPosition(
|
||||
MyGUI::IntPoint(static_cast<int>(rect.mX * viewSize.width), static_cast<int>(rect.mY * viewSize.height)));
|
||||
layout->mMainWidget->setSize(
|
||||
window->setSize(
|
||||
MyGUI::IntSize(static_cast<int>(rect.mW * viewSize.width), static_cast<int>(rect.mH * viewSize.height)));
|
||||
|
||||
MyGUI::Window* window = layout->mMainWidget->castType<MyGUI::Window>();
|
||||
window->eventWindowChangeCoord += MyGUI::newDelegate(this, &WindowManager::onWindowChangeCoord);
|
||||
WindowBase::clampWindowCoordinates(window);
|
||||
|
||||
mTrackedWindows.emplace(window, settings);
|
||||
}
|
||||
|
||||
@ -1750,6 +1754,8 @@ namespace MWGui
|
||||
if (it == mTrackedWindows.end())
|
||||
return;
|
||||
|
||||
WindowBase::clampWindowCoordinates(window);
|
||||
|
||||
const WindowSettingValues& settings = it->second;
|
||||
|
||||
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
|
Loading…
x
Reference in New Issue
Block a user