Skip to content

Commit

Permalink
libappfw|GuiWidget: Added blurred background with a solid fill
Browse files Browse the repository at this point in the history
Also added a new attribute that makes the opacity of a widget
independent of its ancestors.
  • Loading branch information
skyjake committed Nov 30, 2014
1 parent 40da832 commit 442812d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
7 changes: 7 additions & 0 deletions doomsday/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -103,6 +103,7 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
BorderGlow, ///< Border glow with specified color/thickness.
Blurred, ///< Blurs whatever is showing behind the widget.
BlurredWithBorderGlow,
BlurredWithSolidFill,
SharedBlur, ///< Use the blur background from a BlurWidget.
SharedBlurWithBorderGlow,
Rounded
Expand Down Expand Up @@ -182,6 +183,12 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
*/
DontDrawContent = 0x4,

/**
* Visible opacity determined solely by the widget itself, not affected by
* ancestors.
*/
IndependentOpacity = 0x8,

DefaultAttributes = RetainStatePersistently | AnimateOpacityWhenEnabledOrDisabled
};
Q_DECLARE_FLAGS(Attributes, Attribute)
Expand Down
23 changes: 17 additions & 6 deletions doomsday/libappfw/src/guiwidget.cpp
Expand Up @@ -265,7 +265,8 @@ DENG2_PIMPL(GuiWidget)
}

if(background.type != Background::Blurred &&
background.type != Background::BlurredWithBorderGlow)
background.type != Background::BlurredWithBorderGlow &&
background.type != Background::BlurredWithSolidFill)
{
deinitBlur();
return;
Expand Down Expand Up @@ -299,9 +300,15 @@ DENG2_PIMPL(GuiWidget)

// Pass 3: apply the vertical blur filter, drawing the final result
// into the original target.
if(!attribs.testFlag(DontDrawContent) && background.solidFill.w > 0)
Vector4f blurColor = background.solidFill;
float blurOpacity = self.visibleOpacity();
if(background.type == Background::BlurredWithSolidFill)
{
self.drawBlurredRect(self.rule().recti(), background.solidFill, self.visibleOpacity());
blurColor.w = 1;
}
if(!attribs.testFlag(DontDrawContent) && blurColor.w > 0 && blurOpacity > 0)
{
self.drawBlurredRect(self.rule().recti(), blurColor, blurOpacity);
}
}

Expand Down Expand Up @@ -553,11 +560,14 @@ Animation GuiWidget::opacity() const
float GuiWidget::visibleOpacity() const
{
float opacity = d->currentOpacity();
for(Widget *i = Widget::parent(); i != 0; i = i->parent())
if(!d->attribs.testFlag(IndependentOpacity))
{
if(GuiWidget *w = i->maybeAs<GuiWidget>())
for(Widget *i = Widget::parent(); i != 0; i = i->parent())
{
opacity *= w->d->currentOpacity();
if(GuiWidget *w = i->maybeAs<GuiWidget>())
{
opacity *= w->d->currentOpacity();
}
}
}
return opacity;
Expand Down Expand Up @@ -908,6 +918,7 @@ void GuiWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)

case Background::Blurred: // blurs drawn separately in GuiWidget::draw()
case Background::SharedBlur:
case Background::BlurredWithSolidFill:
break;

case Background::None:
Expand Down

0 comments on commit 442812d

Please sign in to comment.