replaced shaded UI redraws with shading surface

This commit is contained in:
thrust26 2020-11-12 14:04:29 +01:00
parent 3063752f60
commit 090c480e1a
3 changed files with 32 additions and 8 deletions

View File

@ -227,8 +227,6 @@ void Dialog::redraw()
center(); center();
drawDialog(); drawDialog();
render(); render();
// return true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -242,6 +240,28 @@ void Dialog::render()
surface->render(); surface->render();
}); });
} }
if(parent().myDialogStack.top() != this)
{
if(_shadeSurface == nullptr)
{
uInt32 data = 0xff000000;
_shadeSurface = instance().frameBuffer().allocateSurface(
1, 1, ScalingInterpolation::sharp, &data);
FBSurface::Attributes& attr = _shadeSurface->attributes();
attr.blending = true;
attr.blendalpha = 25; // darken background dialogs by 25%
_shadeSurface->applyAttributes();
}
const Common::Rect& rect = _surface->dstRect();
_shadeSurface->setDstPos(rect.x(), rect.y());
_shadeSurface->setDstSize(rect.w(), rect.h());
_shadeSurface->render();
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -408,7 +428,7 @@ void Dialog::drawDialog()
//cerr << "*** draw dialog " << typeid(*this).name() << " ***" << endl; //cerr << "*** draw dialog " << typeid(*this).name() << " ***" << endl;
// Dialog is still on top if e.g a ContextMenu is opened // Dialog is still on top if e.g a ContextMenu is opened
_onTop = parent().myDialogStack.top() == this _onTop = true/*parent().myDialogStack.top() == this*/
|| (parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this || (parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this
&& !parent().myDialogStack.top()->hasTitle()); && !parent().myDialogStack.top()->hasTitle());

View File

@ -230,6 +230,7 @@ class Dialog : public GuiObject
WidgetArray _buttonGroup; WidgetArray _buttonGroup;
shared_ptr<FBSurface> _surface; shared_ptr<FBSurface> _surface;
shared_ptr<FBSurface> _shadeSurface;
int _tabID{0}; int _tabID{0};
uInt32 _max_w{0}; // maximum wanted width uInt32 _max_w{0}; // maximum wanted width

View File

@ -146,9 +146,10 @@ int DialogContainer::addDialog(Dialog* d)
"Unable to show dialog box; FIX THE CODE", MessagePosition::BottomCenter, true); "Unable to show dialog box; FIX THE CODE", MessagePosition::BottomCenter, true);
else else
{ {
// "darken" current top dialog //// "shade" current top dialog
if(!myDialogStack.empty()) //if(!myDialogStack.empty())
myDialogStack.top()->setDirty(); // myDialogStack.top()->setDirty();
d->setDirty(); d->setDirty();
myDialogStack.push(d); myDialogStack.push(d);
} }
@ -164,14 +165,16 @@ void DialogContainer::removeDialog()
if(!myDialogStack.empty()) if(!myDialogStack.empty())
{ {
// this "undarkens" the top dialog //// this "unshades" the top dialog
myDialogStack.top()->setDirty(); //myDialogStack.top()->setDirty();
// Rerender all dialogs (TODO: top dialog is rendered twice) // Rerender all dialogs (TODO: top dialog is rendered twice)
myDialogStack.applyAll([&](Dialog*& d){ myDialogStack.applyAll([&](Dialog*& d){
//d->setDirty(); //d->setDirty();
d->render(); d->render();
}); });
// TODO: the screen is not updated until an event happens
// FrameBuffer::myBackend->renderToScreen() doesn't help
} }
} }
} }