Skip to content

Commit

Permalink
Refactor|Widgets|libappfw: Collecting pending assets
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 7, 2017
1 parent efb0910 commit 485427c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
2 changes: 2 additions & 0 deletions doomsday/sdk/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -501,6 +501,8 @@ public slots:
*/
static void recycleTrashedWidgets();

static void collectNotReadyAssets(AssetGroup &collected, Widget &widget);

protected:
/**
* Called by GuiWidget::update() the first time an update is being carried
Expand Down
22 changes: 22 additions & 0 deletions doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -28,6 +28,7 @@
#include <de/Drawable>
#include <de/GLTexture>
#include <de/GLTextureFramebuffer>
#include <de/LogBuffer>
#include <de/FocusWidget>
#include <de/PopupWidget>

Expand Down Expand Up @@ -1260,4 +1261,25 @@ void GuiWidget::postDrawChildren()
}
}

void GuiWidget::collectNotReadyAssets(AssetGroup &collected, Widget &widget)
{
if (auto *assetGroup = widget.maybeAs<IAssetGroup>())
{
if (!assetGroup->assets().isReady())
{
collected += *assetGroup;

LOGDEV_XVERBOSE("Found " _E(m) "NotReady" _E(.) " asset %s (%p)",
widget.path() << &widget);
}
}
else
{
foreach (Widget *child, widget.children())
{
collectNotReadyAssets(collected, *child);
}
}
}

} // namespace de
28 changes: 3 additions & 25 deletions doomsday/sdk/libappfw/src/widgets/panelwidget.cpp
Expand Up @@ -46,7 +46,7 @@ DENG_GUI_PIMPL(PanelWidget)
AnimationRule *openingRule;
QTimer dismissTimer;

QScopedPointer<AssetGroup> pendingShow;
std::unique_ptr<AssetGroup> pendingShow;

// GL objects.
Drawable drawable;
Expand Down Expand Up @@ -157,29 +157,6 @@ DENG_GUI_PIMPL(PanelWidget)
dismissTimer.setInterval((CLOSING_ANIM_SPAN + delay).asMilliSeconds());
}

void findAssets(Widget *widget)
{
//qDebug() << "checking if" << widget << "is an asset to wait for...";

if (auto *assetGroup = widget->maybeAs<IAssetGroup>())
{
if (!assetGroup->assets().isReady())
{
*pendingShow += *assetGroup;

LOGDEV_XVERBOSE("Found " _E(m) "NotReady" _E(.) " asset %s (%p)",
widget->path() << widget);
}
}
else
{
foreach (Widget *child, widget->children())
{
findAssets(child);
}
}
}

void waitForAssetsInContent()
{
if (!waitForContentReady) return;
Expand All @@ -189,7 +166,8 @@ DENG_GUI_PIMPL(PanelWidget)
pendingShow.reset(new AssetGroup);

LOGDEV_XVERBOSE("Checking for assets that need waiting for...", "");
findAssets(content);
DENG2_ASSERT(content);
GuiWidget::collectNotReadyAssets(*pendingShow, *content);

if (pendingShow->isEmpty())
{
Expand Down

0 comments on commit 485427c

Please sign in to comment.