1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 22:19:54 +00:00
openmw-tes3mp/apps/openmw/mwgui/windowbase.cpp
scrawl 1714271a76 Improve KeyboardNavigation to better handle modal windows
It's no longer possible to cycle to widgets that aren't part of the current modal window.

The window manager will remember the focused widget of a modal window on a limited basis (it'll be discarded when a different modal window opens).
2017-09-27 12:55:58 +00:00

124 lines
3.1 KiB
C++

#include "windowbase.hpp"
#include <MyGUI_InputManager.h>
#include <MyGUI_RenderManager.h>
#include <components/settings/settings.hpp>
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/environment.hpp"
#include "draganddrop.hpp"
using namespace MWGui;
WindowBase::WindowBase(const std::string& parLayout)
: Layout(parLayout)
{
mMainWidget->setVisible(false);
}
void WindowBase::setVisible(bool visible)
{
bool wasVisible = mMainWidget->getVisible();
mMainWidget->setVisible(visible);
if (visible)
onOpen();
else if (wasVisible && !visible)
onClose();
// This is needed as invisible widgets can retain key focus.
// Remove for MyGUI 3.2.2
if (!visible)
{
MyGUI::Widget* keyFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
while (keyFocus != mMainWidget && keyFocus != NULL)
keyFocus = keyFocus->getParent();
if (keyFocus == mMainWidget)
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(NULL);
}
}
bool WindowBase::isVisible()
{
return mMainWidget->getVisible();
}
void WindowBase::center()
{
// Centre dialog
MyGUI::IntSize layerSize = MyGUI::RenderManager::getInstance().getViewSize();
if (mMainWidget->getLayer())
layerSize = mMainWidget->getLayer()->getSize();
MyGUI::IntCoord coord = mMainWidget->getCoord();
coord.left = (layerSize.width - coord.width)/2;
coord.top = (layerSize.height - coord.height)/2;
mMainWidget->setCoord(coord);
}
WindowModal::WindowModal(const std::string& parLayout)
: WindowBase(parLayout)
{
}
void WindowModal::onOpen()
{
MWBase::Environment::get().getWindowManager()->addCurrentModal(this); //Set so we can escape it if needed
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
MyGUI::InputManager::getInstance ().addWidgetModal (mMainWidget);
MyGUI::InputManager::getInstance().setKeyFocusWidget(focus);
}
void WindowModal::onClose()
{
MWBase::Environment::get().getWindowManager()->removeCurrentModal(this);
MyGUI::InputManager::getInstance ().removeWidgetModal (mMainWidget);
}
NoDrop::NoDrop(DragAndDrop *drag, MyGUI::Widget *widget)
: mWidget(widget), mDrag(drag), mTransparent(false)
{
}
void NoDrop::onFrame(float dt)
{
if (!mWidget)
return;
MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance().getMousePosition();
if (mDrag->mIsOnDragAndDrop)
{
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getMouseFocusWidget();
while (focus && focus != mWidget)
focus = focus->getParent();
if (focus == mWidget)
mTransparent = true;
}
if (!mWidget->getAbsoluteCoord().inside(mousePos))
mTransparent = false;
if (mTransparent)
{
mWidget->setNeedMouseFocus(false); // Allow click-through
setAlpha(std::max(0.13f, mWidget->getAlpha() - dt*5));
}
else
{
mWidget->setNeedMouseFocus(true);
setAlpha(std::min(1.0f, mWidget->getAlpha() + dt*5));
}
}
void NoDrop::setAlpha(float alpha)
{
if (mWidget)
mWidget->setAlpha(alpha);
}