GRAPHICS: MACGUI: Implement lockable widgets

Lockable widgets are those which takes in all input
and if set then no other widget can take any input
its same as them being inactive, no buttons, animations
etc will work.

This is implemented to support `modal` property of window,
which requires a window to take all input and prevent all
others from having any actions.
This commit is contained in:
Harishankar Kumar 2023-06-01 22:09:52 +05:30 committed by Eugene Sandulenko
parent dd72dd09ca
commit 797803d515
2 changed files with 21 additions and 1 deletions

View File

@ -164,6 +164,8 @@ MacWindowManager::MacWindowManager(uint32 mode, MacPatterns *patterns, Common::L
_needsRemoval = false;
_activeWidget = nullptr;
_lockedWidget = nullptr;
_mouseDown = false;
_hoveredWidget = nullptr;
@ -337,6 +339,13 @@ void MacWindowManager::setActiveWidget(MacWidget *widget) {
_activeWidget->setActive(true);
}
void MacWindowManager::setLockedWidget(MacWidget *widget) {
if (_lockedWidget == widget)
return;
_lockedWidget = widget;
}
void MacWindowManager::clearWidgetRefs(MacWidget *widget) {
if (widget == _hoveredWidget)
_hoveredWidget = nullptr;
@ -1024,7 +1033,8 @@ bool MacWindowManager::processEvent(Common::Event &event) {
for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.end(); it != _windowStack.begin();) {
it--;
BaseMacWindow *w = *it;
if (_lockedWidget != nullptr && w != _lockedWidget)
continue;
if (w->hasAllFocus() || (w->isEditable() && event.type == Common::EVENT_KEYDOWN) ||
w->getDimensions().contains(event.mouse.x, event.mouse.y)) {
if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)

View File

@ -292,9 +292,18 @@ public:
*/
void setActiveWidget(MacWidget *widget);
/**
* Similar to setActiveWidget but in this case no action including animation
* hover, etc can work until a window is locked.
* Anything outside this window will not respond to user.
* @param widget Pointer to the widget to lock, nullptr for no widget
*/
void setLockedWidget(MacWidget *widget);
MacPatterns &getBuiltinPatterns() { return _builtinPatterns; }
MacWidget *getActiveWidget() { return _activeWidget; }
MacWidget *getLockedWidget() { return _lockedWidget; }
Common::Rect getScreenBounds() { return _screen ? _screen->getBounds() : _screenDims; }
@ -446,6 +455,7 @@ private:
Cursor *_cursor;
MacWidget *_activeWidget;
MacWidget *_lockedWidget;
PauseToken *_screenCopyPauseToken;