Skip to content

Commit

Permalink
Fixed|Widgets|libappfw: Drawing the focus indicator
Browse files Browse the repository at this point in the history
The focus indicator should not be drawn after everything else,
because that would ignore clipping and blurring.
  • Loading branch information
skyjake committed Jul 21, 2016
1 parent c1bbf0e commit f555b90
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions doomsday/sdk/libappfw/include/de/framework/guirootwidget.h
Expand Up @@ -31,6 +31,7 @@
namespace de {

class GuiWidget;
class FocusWidget;

/**
* Graphical root widget.
Expand Down Expand Up @@ -96,6 +97,8 @@ class LIBAPPFW_PUBLIC GuiRootWidget : public RootWidget

GuiWidget const *guiFind(String const &name) const;

FocusWidget &focusIndicator();

// Events.
void update();
void draw();
Expand Down
23 changes: 14 additions & 9 deletions doomsday/sdk/libappfw/src/guirootwidget.cpp
Expand Up @@ -132,8 +132,9 @@ DENG2_PIMPL(GuiRootWidget)
self.audienceForChildAddition() += this;
self.audienceForFocusChange() += this;

// The focus indicator exists outside the widget tree.
focusIndicator = new FocusWidget;
self.add(focusIndicator);
focusIndicator->setRoot(thisPublic);
}

~Impl()
Expand All @@ -143,9 +144,11 @@ DENG2_PIMPL(GuiRootWidget)
// Tell all widgets to release their resource allocations. The base
// class destructor will destroy all widgets, but this class governs
// shared GL resources, so we'll ask the widgets to do this now.
focusIndicator->deinitialize();
self.notifyTree(&Widget::deinitialize);

// Destroy GUI widgets while the shared resources are still available.
GuiWidget::destroy(focusIndicator);
self.clearTree();
}

Expand Down Expand Up @@ -188,9 +191,6 @@ DENG2_PIMPL(GuiRootWidget)
// Make sure newly added children know the view size.
child.viewResized();
child.notifyTree(&Widget::viewResized);

// Keep the focus at the top.
self.moveChildToLast(*focusIndicator);
}

void focusedWidgetChanged(Widget *focused)
Expand Down Expand Up @@ -361,6 +361,11 @@ GuiWidget const *GuiRootWidget::guiFind(String const &name) const
return find(name)->maybeAs<GuiWidget>();
}

FocusWidget &GuiRootWidget::focusIndicator()
{
return *d->focusIndicator;
}

void GuiRootWidget::update()
{
if (window().canvas().isGLReady())
Expand All @@ -369,6 +374,7 @@ void GuiRootWidget::update()
window().canvas().makeCurrent();

RootWidget::update();
d->focusIndicator->update();

// Request a window draw so that the updated content becomes visible.
window().as<BaseWindow>().draw();
Expand All @@ -377,6 +383,8 @@ void GuiRootWidget::update()

void GuiRootWidget::draw()
{
d->focusIndicator->initialize();

if (d->noFramesDrawnYet)
{
// Widgets may not yet be ready on the first frame; make sure
Expand All @@ -398,11 +406,8 @@ void GuiRootWidget::draw()

void GuiRootWidget::drawUntil(Widget &until)
{
NotifyArgs args(&Widget::draw);
args.conditionFunc = &Widget::isVisible;
args.preNotifyFunc = &Widget::preDrawChildren;
args.postNotifyFunc = &Widget::postDrawChildren;
args.until = &until;
NotifyArgs args = notifyArgsForDraw();
args.until = &until;
notifyTree(args);
}

Expand Down
8 changes: 8 additions & 0 deletions doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -28,6 +28,7 @@
#include <de/Drawable>
#include <de/GLTexture>
#include <de/GLTarget>
#include <de/FocusWidget>

#include <QList>

Expand Down Expand Up @@ -1002,6 +1003,13 @@ void GuiWidget::postDrawChildren()
{
GLState::pop();
}

// Focus indicator is an overlay.
auto &rootWidget = root();
if (rootWidget.focus() && rootWidget.focus()->parent() == this)
{
rootWidget.focusIndicator().draw();
}
}

} // namespace de

0 comments on commit f555b90

Please sign in to comment.