Skip to content

Commit

Permalink
UI|Client|DialogWidget: Modal dialog flashes borders to indicate bloc…
Browse files Browse the repository at this point in the history
…king

If an event gets eaten because a modal dialog is open, the dialog's
borders now briefly flash to let the user know that the dialog is
preventing the event from going further.
  • Loading branch information
skyjake committed Aug 20, 2013
1 parent 768043b commit 3d49311
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/dialogwidget.h
Expand Up @@ -117,6 +117,7 @@ class DialogWidget : public PopupWidget
int exec(GuiRootWidget &root);

// Events.
void update();
bool handleEvent(de::Event const &event);

public slots:
Expand Down
47 changes: 46 additions & 1 deletion doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -23,10 +23,13 @@
#include "dd_main.h"

#include <de/KeyEvent>
#include <de/MouseEvent>
#include <QEventLoop>

using namespace de;

static TimeDelta const FLASH_ANIM_SPAN = 0.75;

static bool dialogButtonOrder(ui::Item const &a, ui::Item const &b)
{
DialogButtonItem const &left = a.as<DialogButtonItem>();
Expand Down Expand Up @@ -71,9 +74,18 @@ DENG2_OBSERVES(Widget, ChildAddition) // for styling the contents
ScrollAreaWidget *area;
MenuWidget *buttons;
QEventLoop subloop;
Animation glow;
float normalGlow;
bool animatingGlow;

Instance(Public *i) : Base(i), modality(Modal)
Instance(Public *i) : Base(i), modality(Modal), animatingGlow(false)
{
// Initialize the border glow.
normalGlow = self.style().colors().colorf("glow").w;
glow.setValue(normalGlow);
glow.setStyle(Animation::EaseIn);

// Set up widget structure.
GuiWidget *container = new GuiWidget("container");

area = new ScrollAreaWidget("area");
Expand Down Expand Up @@ -220,6 +232,24 @@ DENG2_OBSERVES(Widget, ChildAddition) // for styling the contents
{
return buttons->organizer().itemWidget(item)->as<ButtonWidget>();
}

void startBorderFlash()
{
animatingGlow = true;
glow.setValueFrom(1, normalGlow, FLASH_ANIM_SPAN);
Background bg = self.background();
bg.color.w = glow;
self.set(bg);
}

void updateBorderFlash()
{
Background bg = self.background();
bg.color.w = glow;
self.set(bg);

if(glow.done()) animatingGlow = false;
}
};

DialogWidget::DialogWidget(String const &name)
Expand Down Expand Up @@ -271,6 +301,16 @@ int DialogWidget::exec(GuiRootWidget &root)
return result;
}

void DialogWidget::update()
{
PopupWidget::update();

if(d->animatingGlow)
{
d->updateBorderFlash();
}
}

bool DialogWidget::handleEvent(Event const &event)
{
if(event.isKeyDown())
Expand Down Expand Up @@ -301,6 +341,11 @@ bool DialogWidget::handleEvent(Event const &event)
if(d->modality == Modal)
{
// The event should already have been handled by the children.
if(event.isKeyDown() ||
(event.type() == Event::MouseButton && !hitTest(event.as<MouseEvent>().pos())))
{
d->startBorderFlash();
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/ui/widgets/guiwidget.cpp
Expand Up @@ -363,6 +363,7 @@ void GuiWidget::deleteLater()
void GuiWidget::set(Background const &bg)
{
d->background = bg;
requestGeometry();
}

bool GuiWidget::clipped() const
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/popupwidget.cpp
Expand Up @@ -203,7 +203,7 @@ PopupWidget::PopupWidget(String const &name) : d(new Instance(this))
// Initially the popup is hidden.
hide();

// Move these to an updateStyle:
/// @todo Move these to an updateStyle.
Style const &st = style();
set(Background(st.colors().colorf("background"),
Background::BorderGlow,
Expand Down

0 comments on commit 3d49311

Please sign in to comment.