split Dialog drawing and rendering and skip drawing render when possible

This commit is contained in:
thrust26 2020-11-11 23:32:00 +01:00
parent a6922fb989
commit d77612f572
6 changed files with 24 additions and 23 deletions

View File

@ -128,7 +128,6 @@ void Dialog::close()
_visible = false; _visible = false;
parent().removeDialog(); parent().removeDialog();
setDirty();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -219,26 +218,30 @@ void Dialog::positionAt(uInt32 pos)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Dialog::render() void Dialog::redraw()
{ {
if(!isVisible() || !needsRedraw()) if(!isVisible() || !needsRedraw())
return false; return;// false;
// Draw this dialog // Draw this dialog
center(); center();
drawDialog(); drawDialog();
render();
// return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::render()
{
// Update dialog surface; also render any extra surfaces // Update dialog surface; also render any extra surfaces
// Extra surfaces must be rendered afterwards, so they are drawn on top // Extra surfaces must be rendered afterwards, so they are drawn on top
if(_surface->render()) if(_surface->render())
{ {
mySurfaceStack.applyAll([](shared_ptr<FBSurface>& surface){ mySurfaceStack.applyAll([](shared_ptr<FBSurface>& surface) {
surface->render(); surface->render();
}); });
} }
//_dirty = false;
return true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -67,7 +67,8 @@ class Dialog : public GuiObject
void setDirty() override; void setDirty() override;
bool isDirty() override; // TODO: remove bool isDirty() override; // TODO: remove
bool isChainDirty() const override; bool isChainDirty() const override;
bool render(); void redraw();
void render();
void addFocusWidget(Widget* w) override; void addFocusWidget(Widget* w) override;
void addToFocusList(WidgetArray& list) override; void addToFocusList(WidgetArray& list) override;

View File

@ -89,11 +89,11 @@ void DialogContainer::updateTime(uInt64 time)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DialogContainer::draw(bool full) void DialogContainer::draw(bool full)
{ {
cerr << "draw " << full << " " << typeid(*this).name() << endl; cerr << "draw " << full << " " << typeid(*this).name() << endl;
if(myDialogStack.empty()) if(myDialogStack.empty())
return false; return;
// Make the top dialog dirty if a full redraw is requested // Make the top dialog dirty if a full redraw is requested
if(full) if(full)
@ -102,10 +102,8 @@ bool DialogContainer::draw(bool full)
// Render all dirty dialogs // Render all dirty dialogs
myDialogStack.applyAll([&](Dialog*& d) { myDialogStack.applyAll([&](Dialog*& d) {
if(d->needsRedraw()) if(d->needsRedraw())
full |= d->render(); d->redraw();
}); });
return full;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -133,7 +131,7 @@ int DialogContainer::addDialog(Dialog* d)
"Unable to show dialog box; FIX THE CODE"); "Unable to show dialog box; FIX THE CODE");
else else
{ {
// fade out current top dialog // "darken" current top dialog
if(!myDialogStack.empty()) if(!myDialogStack.empty())
myDialogStack.top()->setDirty(); myDialogStack.top()->setDirty();
d->setDirty(); d->setDirty();
@ -148,14 +146,16 @@ void DialogContainer::removeDialog()
if(!myDialogStack.empty()) if(!myDialogStack.empty())
{ {
myDialogStack.pop(); myDialogStack.pop();
// necessary as long as all dialogs share the same surface
if(!myDialogStack.empty()) if(!myDialogStack.empty())
{ {
//myDialogStack.top()->setDirty(); // this "undarkens" the top dialog
myDialogStack.top()->setDirty();
// Mark all dialogs for redraw // Rerender all dialogs (TODO: top dialog is rendered twice)
myDialogStack.applyAll([&](Dialog*& d){ myDialogStack.applyAll([&](Dialog*& d){
d->setDirty(); //d->setDirty();
d->render();
}); });
} }
} }

View File

@ -121,10 +121,8 @@ class DialogContainer
/** /**
Draw the stack of menus (full indicates to redraw all items). Draw the stack of menus (full indicates to redraw all items).
@return Answers whether any drawing actually occurred.
*/ */
bool draw(bool full = false); void draw(bool full = false);
/** /**
Answers whether a full redraw is required. Answers whether a full redraw is required.

View File

@ -74,7 +74,6 @@ bool EditableWidget::isDirty()
_caretEnabled = !_caretEnabled; _caretEnabled = !_caretEnabled;
_dirty = true; _dirty = true;
} }
cerr << ".";
} }
return _dirty; return _dirty;

View File

@ -277,7 +277,7 @@ void PopUpWidget::drawWidget(bool hilite)
// Fill the background // Fill the background
ColorId bgCol = isEditable() ? kWidColor : kDlgColor; ColorId bgCol = isEditable() ? kWidColor : kDlgColor;
s.fillRect(x + 1, _y + 1, w - (_arrowWidth * 2 - 0), _h - 2, s.fillRect(x + 1, _y + 1, w - (_arrowWidth * 2 - 1), _h - 2,
onTop ? _changed ? kDbgChangedColor : bgCol : kDlgColor); onTop ? _changed ? kDbgChangedColor : bgCol : kDlgColor);
s.fillRect(x + w - (_arrowWidth * 2 - 2), _y + 1, (_arrowWidth * 2 - 3), _h - 2, s.fillRect(x + w - (_arrowWidth * 2 - 2), _y + 1, (_arrowWidth * 2 - 3), _h - 2,
onTop ? isEnabled() && hilite ? kBtnColorHi : bgCol : kBGColorLo); onTop ? isEnabled() && hilite ? kBtnColorHi : bgCol : kBGColorLo);