Skip to content

Commit

Permalink
Widgets|libappfw: Focus indicator is hidden when using the mouse
Browse files Browse the repository at this point in the history
The focus indicator is meant for keyboard input events.
  • Loading branch information
skyjake committed Oct 15, 2016
1 parent 43154d6 commit f688d40
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doomsday/sdk/libappfw/include/de/widgets/focuswidget.h
Expand Up @@ -39,6 +39,9 @@ class LIBAPPFW_PUBLIC FocusWidget : public LabelWidget
void startFlashing(GuiWidget const *reference = nullptr);
void stopFlashing();

void fadeIn();
void fadeOut();

// Events.
void update() override;

Expand Down
7 changes: 7 additions & 0 deletions doomsday/sdk/libappfw/src/guirootwidget.cpp
Expand Up @@ -326,6 +326,13 @@ void GuiRootWidget::dispatchLatestMousePosition()
bool GuiRootWidget::processEvent(Event const &event)
{
window().glActivate();

if (event.type() == Event::MouseButton &&
event.as<MouseEvent>().state() != MouseEvent::Released)
{
d->focusIndicator->fadeOut();
}

bool const wasProcessed = RootWidget::processEvent(event);
// {
// if (event.type() == Event::MouseButton)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -907,6 +907,7 @@ bool GuiWidget::handleEvent(Event const &event)
if (auto *focus = d->findNextWidgetToFocus(
key.modifiers().testFlag(KeyEvent::Shift)? Backward : Forward))
{
root().focusIndicator().fadeIn();
root().setFocus(focus);
return true;
}
Expand All @@ -917,6 +918,7 @@ bool GuiWidget::handleEvent(Event const &event)
key.ddKey() == DDKEY_UPARROW ||
key.ddKey() == DDKEY_DOWNARROW))
{
root().focusIndicator().fadeIn();
root().setFocus(d->findAdjacentWidgetToFocus(
key.ddKey() == DDKEY_LEFTARROW ? ui::Left :
key.ddKey() == DDKEY_RIGHTARROW? ui::Right :
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libappfw/src/widgets/buttonwidget.cpp
Expand Up @@ -20,6 +20,7 @@
#include "de/GuiRootWidget"
#include "de/CallbackAction"

#include <de/FocusWidget>
#include <de/MouseEvent>
#include <de/Animation>

Expand Down Expand Up @@ -320,6 +321,7 @@ bool ButtonWidget::handleEvent(Event const &event)
{
if (key.isKeyDown())
{
root().focusIndicator().fadeIn();
trigger();
}
return true;
Expand Down
13 changes: 12 additions & 1 deletion doomsday/sdk/libappfw/src/widgets/focuswidget.cpp
Expand Up @@ -30,6 +30,7 @@ DENG2_PIMPL(FocusWidget)
SafeWidgetPtr<GuiWidget const> reference;
Animation color { 0.f, Animation::Linear };
Vector4f flashColors[2];
float fadeOpacity = 0.f;

Impl(Public *i) : Base(i)
{
Expand Down Expand Up @@ -85,9 +86,19 @@ void FocusWidget::stopFlashing()
hide();
}

void FocusWidget::fadeIn()
{
d->fadeOpacity = 1.f;
}

void FocusWidget::fadeOut()
{
d->fadeOpacity = 0.f;
}

void FocusWidget::update()
{
setOpacity(d->reference? d->reference->visibleOpacity() : 0.f);
setOpacity(d->fadeOpacity * (d->reference? d->reference->visibleOpacity() : 0.f));
set(Background(Background::GradientFrameWithThinBorder, d->currentColor(), 6));

LabelWidget::update();
Expand Down
12 changes: 8 additions & 4 deletions doomsday/sdk/libappfw/src/widgets/menuwidget.cpp
Expand Up @@ -17,14 +17,16 @@
*/

#include "de/MenuWidget"
#include "de/PopupMenuWidget"
#include "de/PopupButtonWidget"
#include "de/VariableToggleWidget"

#include "de/ChildWidgetOrganizer"
#include "de/FocusWidget"
#include "de/GridLayout"
#include "de/PopupButtonWidget"
#include "de/PopupMenuWidget"
#include "de/StyleProceduralImage"
#include "de/ui/ListData"
#include "de/VariableToggleWidget"
#include "de/ui/ActionItem"
#include "de/ui/ListData"
#include "de/ui/SubwidgetItem"
#include "de/ui/VariantActionItem"

Expand Down Expand Up @@ -682,6 +684,8 @@ bool MenuWidget::handleEvent(Event const &event)
KeyEvent const &key = event.as<KeyEvent>();
if (key.ddKey() == DDKEY_UPARROW || key.ddKey() == DDKEY_DOWNARROW)
{
root().focusIndicator().fadeIn();

auto const children = childWidgets();

for (int ordinal = children.indexOf(root().focus());
Expand Down

0 comments on commit f688d40

Please sign in to comment.