Skip to content

Commit

Permalink
Refactor|Client: Common GuiWidget opacity
Browse files Browse the repository at this point in the history
The console command line is made more transparent when it is out of
focus.
  • Loading branch information
skyjake committed Jun 3, 2013
1 parent f6faeb7 commit 66f6c67
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 19 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/consolecommandwidget.h
Expand Up @@ -37,10 +37,12 @@ class ConsoleCommandWidget : public QObject, public LineEditWidget

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

signals:
void gotFocus();
void lostFocus();

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/consolewidget.h
Expand Up @@ -57,6 +57,8 @@ public slots:
void closeLog();
void clearLog();
void showFullLog();
void setFullyOpaque();
void setTranslucent();

protected slots:
void logContentHeightIncreased(int delta);
Expand Down
18 changes: 18 additions & 0 deletions doomsday/client/include/ui/widgets/guiwidget.h
Expand Up @@ -80,6 +80,24 @@ class GuiWidget : public de::Widget

Background const &background() const;

/**
* Sets the opacity of the widget. Child widgets' opacity is also affected.
*
* @param opacity Opacity.
* @param span Animation transition span.
*/
void setOpacity(float opacity, de::TimeDelta span = 0);

/**
* Determines the widget's current opacity.
*/
float opacity() const;

/**
* Determines the widget's opacity factored into the ancestor's opacities.
*/
float visibleOpacity() const;

// Events.
void initialize();
void deinitialize();
Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/include/ui/widgets/labelwidget.h
Expand Up @@ -110,8 +110,6 @@ class LabelWidget : public GuiWidget
void setWidthPolicy(SizePolicy policy);
void setHeightPolicy(SizePolicy policy);

void setOpacity(float opacity, de::TimeDelta span = 0);

// Events.
void viewResized();
void update();
Expand Down
4 changes: 3 additions & 1 deletion doomsday/client/src/ui/ui_panel.cpp
Expand Up @@ -31,6 +31,7 @@
#include "de_graphics.h"
#include "de_ui.h"

#include "ui/widgets/taskbarwidget.h"
#include "render/rend_font.h"

#include <de/DisplayMode>
Expand Down Expand Up @@ -1231,7 +1232,8 @@ D_CMD(OpenPanel)
cvarbutton_t* cvb;
int i;

Con_Execute(CMDS_DDAY, "conclose", true, false);
//Con_Execute(CMDS_DDAY, "conclose", true, false);
ClientWindow::main().taskBar().close();

populateDisplayResolutions();

Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/src/ui/widgets/consolecommandwidget.cpp
Expand Up @@ -71,6 +71,11 @@ void ConsoleCommandWidget::focusGained()
emit gotFocus();
}

void ConsoleCommandWidget::focusLost()
{
emit lostFocus();
}

bool ConsoleCommandWidget::handleEvent(Event const &event)
{
if(hasFocus() && event.isKeyDown())
Expand Down
18 changes: 18 additions & 0 deletions doomsday/client/src/ui/widgets/consolewidget.cpp
Expand Up @@ -126,6 +126,9 @@ ConsoleWidget::ConsoleWidget() : GuiWidget("Console"), d(new Instance(this))
// Keep the button at the bottom of the expanding command line.
//consoleButton->rule().setInput(Rule::Bottom, d->cmdLine->rule().bottom());

d->button->setOpacity(.5f);
d->cmdLine->setOpacity(.5f);

// The Log is attached to the top of the command line.
d->log = new LogWidget("log");
d->log->rule()
Expand All @@ -145,6 +148,9 @@ ConsoleWidget::ConsoleWidget() : GuiWidget("Console"), d(new Instance(this))
.setInput(Rule::Bottom, d->cmdLine->rule().top() - unit);

closeLog();

connect(d->cmdLine, SIGNAL(gotFocus()), this, SLOT(setFullyOpaque()));
connect(d->cmdLine, SIGNAL(lostFocus()), this, SLOT(setTranslucent()));
}

ButtonWidget &ConsoleWidget::button()
Expand Down Expand Up @@ -341,3 +347,15 @@ void ConsoleWidget::logContentHeightIncreased(int delta)
{
d->expandLog(delta, true);
}

void ConsoleWidget::setFullyOpaque()
{
d->button->setOpacity(1, .25f);
d->cmdLine->setOpacity(1, .25f);
}

void ConsoleWidget::setTranslucent()
{
d->button->setOpacity(.5f, .25f);
d->cmdLine->setOpacity(.5f, .25f);
}
29 changes: 28 additions & 1 deletion doomsday/client/src/ui/widgets/guiwidget.cpp
Expand Up @@ -31,8 +31,11 @@ DENG2_PIMPL(GuiWidget)
bool inited;
bool needGeometry;
Background background;
Animation opacity;

Instance(Public *i) : Base(i), inited(false), needGeometry(true)
Instance(Public *i)
: Base(i), inited(false), needGeometry(true),
opacity(1.f, Animation::Linear)
{}

~Instance()
Expand Down Expand Up @@ -85,6 +88,30 @@ GuiWidget::Background const &GuiWidget::background() const
return d->background;
}

void GuiWidget::setOpacity(float opacity, TimeDelta span)
{
d->opacity.setValue(opacity, span);
}

float GuiWidget::opacity() const
{
return d->opacity;
}

float GuiWidget::visibleOpacity() const
{
float opacity = d->opacity;
for(Widget *i = parent(); i != 0; i = i->parent())
{
GuiWidget *w = dynamic_cast<GuiWidget *>(i);
if(w)
{
opacity *= w->d->opacity;
}
}
return opacity;
}

void GuiWidget::initialize()
{
if(d->inited) return;
Expand Down
9 changes: 1 addition & 8 deletions doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -49,7 +49,6 @@ public Font::RichFormat::IStyle
Font const *font;
int margin;
int gap;
Animation opacity;

String styledText;
FontLineWrapping wraps;
Expand Down Expand Up @@ -82,7 +81,6 @@ public Font::RichFormat::IStyle
width = new ConstantRule(0);
height = new ConstantRule(0);

opacity = 1;
uColor = Vector4f(1, 1, 1, 1);
updateStyle();
}
Expand Down Expand Up @@ -423,7 +421,7 @@ void LabelWidget::update()

void LabelWidget::draw()
{
d->uColor = Vector4f(1, 1, 1, d->opacity);
d->uColor = Vector4f(1, 1, 1, visibleOpacity());
d->draw();
}

Expand Down Expand Up @@ -498,8 +496,3 @@ void LabelWidget::setHeightPolicy(SizePolicy policy)
rule().clearInput(Rule::Height);
}
}

void LabelWidget::setOpacity(float opacity, TimeDelta span)
{
d->opacity.setValue(opacity, span);
}
22 changes: 15 additions & 7 deletions doomsday/client/src/ui/widgets/lineeditwidget.cpp
Expand Up @@ -52,21 +52,23 @@ DENG2_OBSERVES(Atlas, Reposition)
Drawable drawable;
GLUniform uMvpMatrix;
GLUniform uColor;
GLUniform uCursorColor;

Instance(Public *i)
: Base(i),
wraps(static_cast<FontLineWrapping &>(i->lineWraps())),
font(0),
margin(0),
hovering(0, Animation::Linear),
uMvpMatrix("uMvpMatrix", GLUniform::Mat4),
uColor ("uColor", GLUniform::Vec4)
uMvpMatrix ("uMvpMatrix", GLUniform::Mat4),
uColor ("uColor", GLUniform::Vec4),
uCursorColor("uColor", GLUniform::Vec4)
{
height = new ScalarRule(0);

updateStyle();

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

~Instance()
Expand Down Expand Up @@ -132,13 +134,14 @@ DENG2_OBSERVES(Atlas, Reposition)
drawable.addBuffer(ID_BUF_TEXT, new VertexBuf);
drawable.addBufferWithNewProgram(ID_BUF_CURSOR, new VertexBuf, "cursor");

self.root().shaders().build(drawable.program(), "generic.textured.color")
self.root().shaders().build(drawable.program(), "generic.textured.color_ucolor")
<< uMvpMatrix
<< uColor
<< self.root().uAtlas();

self.root().shaders().build(drawable.program("cursor"), "generic.color_ucolor")
<< uMvpMatrix
<< uColor;
<< uCursorColor;

updateProjection();
}
Expand Down Expand Up @@ -282,14 +285,19 @@ void LineEditWidget::update()

void LineEditWidget::draw()
{
float const opac = visibleOpacity();

// Blink the cursor.
Vector4f col = style().colors().colorf("editor.cursor");
col.w *= (int(d->blinkTime.since() * 2) & 1? .25f : 1.f);
col.w *= (int(d->blinkTime.since() * 2) & 1? .25f : 1.f) * opac;
if(!hasFocus())
{
col.w = 0;
}
d->uColor = col;
d->uCursorColor = col;

// Overall opacity.
d->uColor = Vector4f(1, 1, 1, opac);

d->updateGeometry();
d->drawable.draw();
Expand Down

0 comments on commit 66f6c67

Please sign in to comment.