Skip to content

Commit

Permalink
Refactor|libappfw: Using color theme enums in popups
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 16, 2016
1 parent da0d05d commit 0a659c9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions doomsday/sdk/libappfw/include/de/widgets/popupmenuwidget.h
Expand Up @@ -39,6 +39,7 @@ class LIBAPPFW_PUBLIC PopupMenuWidget : public PopupWidget
ui::Data &items() { return menu().items(); }

void useInfoStyle(bool yes = true);
void setColorTheme(ColorTheme theme);

// Events.
void update();
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libappfw/include/de/widgets/popupwidget.h
Expand Up @@ -98,6 +98,8 @@ class LIBAPPFW_PUBLIC PopupWidget : public PanelWidget

Background infoStyleBackground() const;

void setColorTheme(ColorTheme theme);

// Events.
bool handleEvent(Event const &event);

Expand Down
1 change: 1 addition & 0 deletions doomsday/sdk/libappfw/src/widgets/focuswidget.cpp
Expand Up @@ -66,6 +66,7 @@ FocusWidget::FocusWidget(String const &name)
: LabelWidget(name)
, d(new Instance(this))
{
hide();
connect(&d->flashing, SIGNAL(timeout()), this, SLOT(updateFlash()));
}

Expand Down
22 changes: 14 additions & 8 deletions doomsday/sdk/libappfw/src/widgets/popupmenuwidget.cpp
Expand Up @@ -89,7 +89,7 @@ DENG_GUI_PIMPL(PopupMenuWidget)
Id _id;
};

bool infoStyle = false;
ColorTheme colorTheme = Normal;
ButtonWidget *hover;
int oldScrollY;
Rule const *widestItem;
Expand Down Expand Up @@ -206,8 +206,8 @@ DENG_GUI_PIMPL(PopupMenuWidget)
void setButtonColors(ButtonWidget &button)
{
bool const hovering = (hover == &button);
button.setTextColor(!hovering ^ infoStyle? "text" : "inverted.text");
button.setHoverTextColor(!hovering ^ infoStyle? "inverted.text" : "text",
button.setTextColor(!hovering ^ (colorTheme == Inverted)? "text" : "inverted.text");
button.setHoverTextColor(!hovering ^ (colorTheme == Inverted)? "inverted.text" : "text",
ButtonWidget::ReplaceColor);
}

Expand Down Expand Up @@ -310,7 +310,8 @@ DENG_GUI_PIMPL(PopupMenuWidget)

void updateImageColor(ButtonWidget &button, bool invert = false)
{
button.setImageColor(style().colors().colorf(invert ^ infoStyle? "inverted.text" : "text"));
button.setImageColor(style().colors().colorf(invert ^ (colorTheme == Inverted)? "inverted.text"
: "text"));
}

void buttonStateChanged(ButtonWidget &button, ButtonWidget::State state)
Expand Down Expand Up @@ -419,8 +420,13 @@ MenuWidget &PopupMenuWidget::menu() const

void PopupMenuWidget::useInfoStyle(bool yes)
{
PopupWidget::useInfoStyle(yes);
d->infoStyle = yes;
setColorTheme(yes? Inverted : Normal);
}

void PopupMenuWidget::setColorTheme(ColorTheme theme)
{
PopupWidget::setColorTheme(theme);
d->colorTheme = theme;
d->updateButtonColors();
}

Expand All @@ -438,8 +444,8 @@ void PopupMenuWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)
{
verts.makeQuad(d->highlightRect(),
d->hover->state() == ButtonWidget::Hover?
style().colors().colorf(!d->infoStyle? "inverted.background" : "background") :
style().colors().colorf(!d->infoStyle? "accent" : "inverted.accent"),
style().colors().colorf(d->colorTheme == Normal? "inverted.background" : "background") :
style().colors().colorf(d->colorTheme == Normal? "accent" : "inverted.accent"),
root().atlas().imageRectf(root().solidWhitePixel()).middle());
}
}
Expand Down
15 changes: 10 additions & 5 deletions doomsday/sdk/libappfw/src/widgets/popupwidget.cpp
Expand Up @@ -35,7 +35,7 @@ DENG_GUI_PIMPL(PopupWidget)
, DENG2_OBSERVES(Widget, Deletion)
{
bool flexibleDir = true;
bool useInfoStyle = false;
ColorTheme colorTheme = Normal;
bool deleteAfterDismiss = false;
bool clickToClose = true;
bool outsideClickOngoing = false;
Expand Down Expand Up @@ -204,7 +204,7 @@ DENG_GUI_PIMPL(PopupWidget)
Style const &st = style();
bool const opaqueBackground = (self.levelOfNesting() > 0);

if(useInfoStyle)
if(colorTheme == Inverted)
{
self.set(self.infoStyleBackground());
}
Expand Down Expand Up @@ -346,13 +346,18 @@ void PopupWidget::setClickToClose(bool clickCloses)

void PopupWidget::useInfoStyle(bool yes)
{
d->useInfoStyle = yes;
d->updateStyle();
setColorTheme(yes? Inverted : Normal);
}

bool PopupWidget::isUsingInfoStyle()
{
return d->useInfoStyle;
return d->colorTheme == Inverted;
}

void PopupWidget::setColorTheme(ColorTheme theme)
{
d->colorTheme = theme;
d->updateStyle();
}

GuiWidget::Background PopupWidget::infoStyleBackground() const
Expand Down

0 comments on commit 0a659c9

Please sign in to comment.