Skip to content

Commit

Permalink
Fixed|UI|Client: Button text hover color with rich formatting
Browse files Browse the repository at this point in the history
Rich formatting would override the button hover color, which would
result in a potential clash with the hover background. Now the
hover text color is applied using a modulation color that is
applied in the vertex colors.
  • Loading branch information
skyjake committed Jan 8, 2014
1 parent a65722f commit 2b27c10
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
20 changes: 11 additions & 9 deletions doomsday/client/include/ui/widgets/labelwidget.h
Expand Up @@ -112,15 +112,7 @@ class LabelWidget : public GuiWidget

void setTextLineAlignment(ui::Alignment const &textLineAlign);

/**
* Sets the alignment of the image when there is both an image
* and a text in the label.
*
* @param imageAlign Alignment for the image.
*/
void setImageAlignment(ui::Alignment const &imageAlign);

void setImageFit(ui::ContentFit const &fit);
void setTextModulationColorf(de::Vector4f const &colorf);

/**
* Sets the maximum width used for text. By default, the maximum width is determined
Expand All @@ -138,6 +130,16 @@ class LabelWidget : public GuiWidget
*/
void setTextStyle(de::Font::RichFormat::IStyle const *richStyle);

/**
* Sets the alignment of the image when there is both an image
* and a text in the label.
*
* @param imageAlign Alignment for the image.
*/
void setImageAlignment(ui::Alignment const &imageAlign);

void setImageFit(ui::ContentFit const &fit);

/**
* The image's actual size will be overridden by this size.
* @param size Image size.
Expand Down
12 changes: 3 additions & 9 deletions doomsday/client/src/ui/widgets/buttonwidget.cpp
Expand Up @@ -29,7 +29,6 @@ DENG2_OBSERVES(Action, Triggered)
{
State state;
DotPath hoverTextColor;
DotPath textColor;
QScopedPointer<Action> action;
Animation scale;
Animation frameOpacity;
Expand Down Expand Up @@ -62,20 +61,15 @@ DENG2_OBSERVES(Action, Triggered)
if(!hoverTextColor.isEmpty())
{
// Restore old color.
self.setTextColor(textColor);
self.setTextModulationColorf(Vector4f(1, 1, 1, 1));
}
break;

case Hover:
//scale.setValue(1.1f, .15f);
//scale.setStyle(Animation::EaseOut);
frameOpacity.setValue(.4f, .15f);
if(!hoverTextColor.isEmpty())
{
// Remember the old color.
textColor = self.textColorId();

self.setTextColor(hoverTextColor);
self.setTextModulationColorf(style().colors().colorf(hoverTextColor));
}
break;

Expand Down Expand Up @@ -152,7 +146,7 @@ DENG2_OBSERVES(Action, Triggered)
ButtonWidget::ButtonWidget(String const &name) : LabelWidget(name), d(new Instance(this))
{}

void ButtonWidget::setHoverTextColor(const DotPath &hoverTextId)
void ButtonWidget::setHoverTextColor(DotPath const &hoverTextId)
{
d->hoverTextColor = hoverTextId;
}
Expand Down
10 changes: 9 additions & 1 deletion doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -43,6 +43,7 @@ public Font::RichFormat::IStyle
Vector2f overrideImageSize;
float imageScale;
Vector4f imageColor;
Vector4f textGLColor;
int maxTextWidth;

ConstantRule *width;
Expand Down Expand Up @@ -78,6 +79,7 @@ public Font::RichFormat::IStyle
, imageFit (OriginalAspectRatio | FitToSize)
, imageScale (1)
, imageColor (1, 1, 1, 1)
, textGLColor (1, 1, 1, 1)
, maxTextWidth(0)
, gapId ("label.gap")
, richStyle (0)
Expand Down Expand Up @@ -525,6 +527,12 @@ void LabelWidget::setTextLineAlignment(Alignment const &textLineAlign)
d->lineAlign = textLineAlign;
}

void LabelWidget::setTextModulationColorf(Vector4f const &colorf)
{
d->textGLColor = colorf;
requestGeometry();
}

void LabelWidget::setImageAlignment(Alignment const &imageAlign)
{
d->imageAlign = imageAlign;
Expand Down Expand Up @@ -618,7 +626,7 @@ void LabelWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)
// Shadow + text.
/*composer.makeVertices(verts, textPos.topLeft + Vector2i(0, 2),
lineAlign, Vector4f(0, 0, 0, 1));*/
d->glText.makeVertices(verts, layout.text, AlignCenter, d->lineAlign);
d->glText.makeVertices(verts, layout.text, AlignCenter, d->lineAlign, d->textGLColor);
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/popupmenuwidget.cpp
Expand Up @@ -240,7 +240,7 @@ void PopupMenuWidget::panelClosing()

if(d->hover)
{
d->hover->setTextColor("text");
d->hover->setTextModulationColorf(Vector4f(1, 1, 1, 1));
d->hover->setImageColor(style().colors().colorf("text"));
d->hover = 0;
requestGeometry();
Expand Down

0 comments on commit 2b27c10

Please sign in to comment.