Skip to content

Commit

Permalink
Refactor|Client|Widgets: GuiWidget stores/updates common style proper…
Browse files Browse the repository at this point in the history
…ties

Also cleaned up colors.dei in the Default Style pack a little with
new gui module color operations.
  • Loading branch information
skyjake committed Jun 4, 2013
1 parent a7a4b13 commit 8550792
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 57 deletions.
13 changes: 8 additions & 5 deletions doomsday/client/data/defaultstyle.pack/colors.dei
@@ -1,17 +1,20 @@
# Colors for the default UI style

color text { rgb <1.0, 1.0, 1.0> }
color background { rgba <0.0, 0.0, 0.0, 0.666> }
script { import gui }

color text { rgb <1.0, 1.0, 1.0> }
color background { rgb <0.0, 0.0, 0.0, 0.666> }
color accent { rgb <1.0, 0.8, 0.4> }

group editor {
color cursor { rgb <1.0, 0.8, 0.4, 0.7> }
color cursor { rgb $= gui.colorAlpha(accent.rgb, 0.7) }
color hint { rgb $= gui.colorMix(text.rgb, accent.rgb, 0.5) }
}

group log {
color normal { rgb <0.85, 0.85, 0.8> }
color highlight { rgb <1.0, 1.0, 1.0> }
color dimmed { rgb <0.72, 0.72, 0.68> }
color accent { rgb <1.0, 0.8, 0.4> }
color accent { rgb $= accent.rgb }
color dimaccent { rgb <0.85, 0.68, 0.34> }
}
}
21 changes: 20 additions & 1 deletion doomsday/client/include/ui/widgets/guiwidget.h
Expand Up @@ -60,7 +60,7 @@ class GuiWidget : public de::Widget
GuiWidget(de::String const &name = "");

GuiRootWidget &root();
Style const &style();
Style const &style() const;

/**
* Returns the rule rectangle that defines the placement of the widget on
Expand All @@ -76,8 +76,20 @@ class GuiWidget : public de::Widget

void deleteLater();

void setFont(de::DotPath const &id);
void setTextColor(de::DotPath const &id);
void set(Background const &bg);

de::Font const &font() const;
de::ColorBank::Color textColor() const;
de::ColorBank::Colorf textColorf() const;

/**
* Determines whether the contents of the widget are scissor-clipped to its
* boundaries.
*/
bool clipped() const;

Background const &background() const;

/**
Expand All @@ -102,6 +114,7 @@ class GuiWidget : public de::Widget
void initialize();
void deinitialize();
void update();
void drawIfVisible();

/**
* Determines if the widget occupies on-screen position @a pos.
Expand Down Expand Up @@ -159,6 +172,12 @@ class GuiWidget : public de::Widget
*/
bool hasChangedPlace(de::Rectanglei &currentPlace);

/**
* Called during GuiWidget::update() whenever the style of the widget has
* been marked as changed.
*/
virtual void updateStyle();

private:
DENG2_PRIVATE(d)
};
Expand Down
4 changes: 3 additions & 1 deletion doomsday/client/include/ui/widgets/labelwidget.h
Expand Up @@ -66,6 +66,8 @@ class LabelWidget : public GuiWidget
void setText(de::String const &text);
void setImage(de::Image const &image);

de::String text() const;

/**
* Sets the alignment of the entire contents of the widget inside its
* rectangle.
Expand Down Expand Up @@ -125,8 +127,8 @@ class LabelWidget : public GuiWidget
protected:
void glInit();
void glDeinit();

void glMakeGeometry(DefaultVertexBuf::Builder &verts);
void updateStyle();

/**
* Called before drawing to update the model-view-projection matrix.
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/lineeditwidget.h
Expand Up @@ -52,6 +52,7 @@ class LineEditWidget : public GuiWidget, public de::shell::AbstractLineEditor
void glInit();
void glDeinit();
void glMakeGeometry(DefaultVertexBuf::Builder &verts);
void updateStyle();

int maximumWidth() const;
void numberOfLinesChanged(int lineCount);
Expand Down
4 changes: 0 additions & 4 deletions doomsday/client/src/ui/widgets/consolewidget.cpp
Expand Up @@ -313,8 +313,6 @@ bool ConsoleWidget::handleEvent(Event const &event)

void ConsoleWidget::openLog()
{
qDebug() << "ConsoleWidget: openLog, opened" << d->opened;

if(d->opened) return;

d->opened = true;
Expand All @@ -323,8 +321,6 @@ void ConsoleWidget::openLog()

void ConsoleWidget::closeLog()
{
qDebug() << "ConsoleWidget: closeLog, opened" << d->opened;

if(!d->opened) return;

d->opened = false;
Expand Down
75 changes: 72 additions & 3 deletions doomsday/client/src/ui/widgets/guiwidget.cpp
Expand Up @@ -21,6 +21,7 @@
#include "clientapp.h"
#include <de/garbage.h>
#include <de/MouseEvent>
#include <de/GLState>

using namespace de;

Expand All @@ -30,12 +31,22 @@ DENG2_PIMPL(GuiWidget)
Rectanglei savedPos;
bool inited;
bool needGeometry;
bool styleChanged;
Background background;
Animation opacity;

// Style.
DotPath fontId;
DotPath textColorId;

Instance(Public *i)
: Base(i), inited(false), needGeometry(true),
opacity(1.f, Animation::Linear)
: Base(i),
inited(false),
needGeometry(true),
styleChanged(false),
opacity(1.f, Animation::Linear),
fontId("default"),
textColorId("text")
{}

~Instance()
Expand All @@ -53,11 +64,38 @@ GuiRootWidget &GuiWidget::root()
return static_cast<GuiRootWidget &>(Widget::root());
}

Style const &GuiWidget::style()
Style const &GuiWidget::style() const
{
return ClientApp::windowSystem().style();
}

Font const &GuiWidget::font() const
{
return style().fonts().font(d->fontId);
}

void GuiWidget::setFont(DotPath const &id)
{
d->fontId = id;
d->styleChanged = true;
}

ColorBank::Color GuiWidget::textColor() const
{
return style().colors().color(d->textColorId);
}

ColorBank::Colorf GuiWidget::textColorf() const
{
return style().colors().colorf(d->textColorId);
}

void GuiWidget::setTextColor(DotPath const &id)
{
d->textColorId = id;
d->styleChanged = true;
}

RuleRectangle &GuiWidget::rule()
{
return d->rule;
Expand All @@ -83,6 +121,11 @@ void GuiWidget::set(Background const &bg)
d->background = bg;
}

bool GuiWidget::clipped() const
{
return behavior().testFlag(ContentClipping);
}

GuiWidget::Background const &GuiWidget::background() const
{
return d->background;
Expand Down Expand Up @@ -150,6 +193,29 @@ void GuiWidget::update()
{
initialize();
}
if(d->styleChanged)
{
d->styleChanged = false;
updateStyle();
}
}

void GuiWidget::drawIfVisible()
{
if(!isHidden())
{
if(clipped())
{
GLState::push().setScissor(rule().recti());
}

draw();

if(clipped())
{
GLState::pop();
}
}
}

bool GuiWidget::hitTest(Vector2i const &pos) const
Expand Down Expand Up @@ -243,3 +309,6 @@ bool GuiWidget::hasChangedPlace(Rectanglei &currentPlace)
d->savedPos = currentPlace;
return changed;
}

void GuiWidget::updateStyle()
{}
45 changes: 31 additions & 14 deletions doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -46,7 +46,6 @@ public Font::RichFormat::IStyle
ConstantRule *height;

// Style.
Font const *font;
int margin;
int gap;

Expand All @@ -71,7 +70,6 @@ public Font::RichFormat::IStyle
imageAlign(AlignCenter),
imageFit(OriginalAspectRatio | FitToSize),
imageScale(1),
font(0),
wrapWidth(0),
needImageUpdate(false),
imageTex(Id::None),
Expand All @@ -81,7 +79,7 @@ public Font::RichFormat::IStyle
width = new ConstantRule(0);
height = new ConstantRule(0);

uColor = Vector4f(1, 1, 1, 1);
uColor = Vector4f(1, 1, 1, 1);
updateStyle();
}

Expand All @@ -95,18 +93,18 @@ public Font::RichFormat::IStyle
{
Style const &st = self.style();

font = &st.fonts().font("default");
margin = st.rules().rule("gap").valuei();
gap = margin / 2;

wraps.setFont(*font);
wraps.setFont(self.font());
wrapWidth = 0;

self.requestGeometry();
}

Color richStyleColor(int index) const
Color richStyleColor(int /*index*/) const
{
return Vector4ub(255, 255, 255, 255);
return self.textColor();
}

void richStyleFormat(int contentStyle, float &sizeFactor, Font::RichFormat::Weight &fontWeight,
Expand All @@ -116,9 +114,9 @@ public Font::RichFormat::IStyle
{
default:
sizeFactor = 1.f;
fontWeight = Font::RichFormat::Normal;
fontStyle = Font::RichFormat::Regular;
colorIndex = Font::RichFormat::NormalColor;
fontWeight = Font::RichFormat::OriginalWeight;
fontStyle = Font::RichFormat::OriginalStyle;
colorIndex = Font::RichFormat::OriginalColor;
break;
}
}
Expand Down Expand Up @@ -336,7 +334,7 @@ public Font::RichFormat::IStyle
wrapWidth = availableTextWidth();
self.requestGeometry();

Font::RichFormat format;
Font::RichFormat format(*this);
String plain = format.initFromStyledText(styledText);
wraps.wrapTextToWidth(plain, format, wrapWidth);

Expand Down Expand Up @@ -393,7 +391,17 @@ void LabelWidget::setImage(Image const &image)
d->needImageUpdate = true;
}

void LabelWidget::setTextAlignment(const Alignment &textAlign)
String LabelWidget::text() const
{
return d->styledText;
}

void LabelWidget::setAlignment(Alignment const &align)
{
d->align = align;
}

void LabelWidget::setTextAlignment(Alignment const &textAlign)
{
d->textAlign = textAlign;
}
Expand Down Expand Up @@ -421,8 +429,12 @@ void LabelWidget::update()

void LabelWidget::draw()
{
d->uColor = Vector4f(1, 1, 1, visibleOpacity());
d->draw();
float const opac = visibleOpacity();
if(opac > 0)
{
d->uColor = Vector4f(1, 1, 1, opac);
d->draw();
}
}

void LabelWidget::contentLayout(LabelWidget::ContentLayout &layout)
Expand Down Expand Up @@ -461,6 +473,11 @@ void LabelWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)
}
}

void LabelWidget::updateStyle()
{
d->updateStyle();
}

void LabelWidget::updateModelViewProjection(GLUniform &uMvp)
{
uMvp = root().projMatrix2D();
Expand Down

0 comments on commit 8550792

Please sign in to comment.