mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Workaround keyfocus issues in current versions of MyGUI
This commit is contained in:
parent
b9341925f2
commit
475ac46f3e
@ -4,6 +4,7 @@
|
||||
#include <MyGUI_WidgetManager.h>
|
||||
#include <MyGUI_Button.h>
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_Window.h>
|
||||
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
@ -30,7 +31,13 @@ void getKeyFocusWidgets(MyGUI::Widget* parent, std::vector<MyGUI::Widget*>& resu
|
||||
}
|
||||
}
|
||||
|
||||
bool shouldAcceptKeyFocus(MyGUI::Widget* w)
|
||||
{
|
||||
return w && !w->castType<MyGUI::Window>(false) && w->getInheritedEnabled() && w->getInheritedVisible() && w->getVisible() && w->getEnabled();
|
||||
}
|
||||
|
||||
KeyboardNavigation::KeyboardNavigation()
|
||||
: mCurrentFocus(nullptr)
|
||||
{
|
||||
MyGUI::WidgetManager::getInstance().registerUnlinker(this);
|
||||
}
|
||||
@ -42,7 +49,11 @@ KeyboardNavigation::~KeyboardNavigation()
|
||||
|
||||
void KeyboardNavigation::saveFocus(int mode)
|
||||
{
|
||||
mKeyFocus[mode] = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
||||
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
||||
if (shouldAcceptKeyFocus(focus))
|
||||
mKeyFocus[mode] = focus;
|
||||
else
|
||||
mKeyFocus[mode] = mCurrentFocus;
|
||||
}
|
||||
|
||||
void KeyboardNavigation::restoreFocus(int mode)
|
||||
@ -61,6 +72,51 @@ void KeyboardNavigation::_unlinkWidget(MyGUI::Widget *widget)
|
||||
for (std::pair<const int, MyGUI::Widget*>& w : mKeyFocus)
|
||||
if (w.second == widget)
|
||||
w.second = nullptr;
|
||||
if (widget == mCurrentFocus)
|
||||
mCurrentFocus = nullptr;
|
||||
}
|
||||
|
||||
void styleFocusedButton(MyGUI::Widget* w)
|
||||
{
|
||||
if (w)
|
||||
{
|
||||
if (MyGUI::Button* b = w->castType<MyGUI::Button>(false))
|
||||
{
|
||||
b->_setWidgetState("highlighted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardNavigation::onFrame()
|
||||
{
|
||||
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
||||
|
||||
if (focus == mCurrentFocus)
|
||||
{
|
||||
styleFocusedButton(mCurrentFocus);
|
||||
return;
|
||||
}
|
||||
|
||||
// workaround incorrect key focus resets (fix in MyGUI TBD)
|
||||
if (!shouldAcceptKeyFocus(focus) && shouldAcceptKeyFocus(mCurrentFocus))
|
||||
{
|
||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(mCurrentFocus);
|
||||
focus = mCurrentFocus;
|
||||
}
|
||||
|
||||
// style highlighted button (won't be needed for MyGUI 3.2.3)
|
||||
if (focus != mCurrentFocus)
|
||||
{
|
||||
if (mCurrentFocus)
|
||||
{
|
||||
if (MyGUI::Button* b = mCurrentFocus->castType<MyGUI::Button>(false))
|
||||
b->_setWidgetState("normal");
|
||||
}
|
||||
|
||||
mCurrentFocus = focus;
|
||||
}
|
||||
|
||||
styleFocusedButton(mCurrentFocus);
|
||||
}
|
||||
|
||||
enum Direction
|
||||
|
@ -21,6 +21,8 @@ namespace MWGui
|
||||
|
||||
void _unlinkWidget(MyGUI::Widget* widget);
|
||||
|
||||
void onFrame();
|
||||
|
||||
private:
|
||||
bool switchFocus(int direction, bool wrap);
|
||||
|
||||
@ -28,6 +30,8 @@ namespace MWGui
|
||||
bool accept();
|
||||
|
||||
std::map<int, MyGUI::Widget*> mKeyFocus;
|
||||
|
||||
MyGUI::Widget* mCurrentFocus;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -866,6 +866,8 @@ namespace MWGui
|
||||
if (!mCurrentModals.empty())
|
||||
mCurrentModals.top()->onFrame(frameDuration);
|
||||
|
||||
mKeyboardNavigation->onFrame();
|
||||
|
||||
mMessageBoxManager->onFrame(frameDuration);
|
||||
|
||||
mToolTips->onFrame(frameDuration);
|
||||
|
Loading…
x
Reference in New Issue
Block a user