Skip to content

Commit

Permalink
libappfw|FoldPanelWidget: Added a fold state indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 21, 2014
1 parent 9722a9f commit 50a0ba1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doomsday/client/data/defaultstyle.pack/images.dei
Expand Up @@ -20,6 +20,7 @@ group logo {
}

image alert { path = "graphics/alert.png" }
image fold { path = "graphics/fold.png" }
image gauge { path = "graphics/gauge.png" }
image gear { path = "graphics/gear.png" }
image display { path = "graphics/display.png" }
Expand Down
1 change: 1 addition & 0 deletions doomsday/libappfw/include/de/framework/guirootwidget.h
Expand Up @@ -62,6 +62,7 @@ class LIBAPPFW_PUBLIC GuiRootWidget : public RootWidget
Id borderGlow() const;
Id toggleOnOff() const;
Id tinyDot() const;
Id fold() const;

static GLShaderBank &shaders();

Expand Down
20 changes: 15 additions & 5 deletions doomsday/libappfw/src/guirootwidget.cpp
Expand Up @@ -45,14 +45,15 @@ DENG2_PIMPL(GuiRootWidget)
Id borderGlow;
Id toggleOnOff;
Id tinyDot;
Id fold;
bool noFramesDrawnYet;

Instance(Public *i, CanvasWindow *win)
: Base(i),
window(win),
atlas(0),
uTexAtlas("uTex", GLUniform::Sampler2D),
noFramesDrawnYet(true)
: Base(i)
, window(win)
, atlas(0)
, uTexAtlas("uTex", GLUniform::Sampler2D)
, noFramesDrawnYet(true)
{
self.audienceForChildAddition += this;
}
Expand Down Expand Up @@ -162,6 +163,9 @@ DENG2_PIMPL(GuiRootWidget)
// On/Off toggle.
toggleOnOff = atlas->alloc(st.images().image("toggle.onoff"));

// Fold indicator.
fold = atlas->alloc(st.images().image("fold"));

// Tiny dot.
{
QImage dot(QSize(5, 5), QImage::Format_ARGB32);
Expand Down Expand Up @@ -251,6 +255,12 @@ Id GuiRootWidget::tinyDot() const
return d->tinyDot;
}

Id de::GuiRootWidget::fold() const
{
d->initAtlas();
return d->fold;
}

GLShaderBank &GuiRootWidget::shaders()
{
return BaseGuiApp::shaders();
Expand Down
38 changes: 19 additions & 19 deletions doomsday/libappfw/src/widgets/foldpanelwidget.cpp
Expand Up @@ -27,7 +27,6 @@ using namespace ui;

DENG2_PIMPL_NOREF(FoldPanelWidget)
{
/*
struct FoldImage : public ProceduralImage
{
FoldPanelWidget &fold;
Expand All @@ -38,28 +37,28 @@ DENG2_PIMPL_NOREF(FoldPanelWidget)

void update()
{
setSize(fold.root().atlas().imageRect(fold.root().roundCorners()).size());
float h = fold.title().font().height().value();
setSize(Vector2f(h, h));
}

void glMakeGeometry(DefaultVertexBuf::Builder &verts, Rectanglef const &rect)
{
GuiRootWidget &root = fold.root();
Atlas &atlas = root.atlas();
ColorBank::Colorf const &textColor = fold.style().colors().colorf("text");
ColorBank::Colorf accentColor = fold.style().colors().colorf("accent")
* Vector4f(1, 1, 1, fold.isOpen()? .5f : 1);
verts.makeQuad(rect, accentColor,
atlas.imageRectf(root.roundCorners()));
Vector2ui dotSize = atlas.imageRect(root.tinyDot()).size();
verts.makeQuad(Rectanglef::fromSize(rect.middle() - dotSize/2,
dotSize),
fold.isOpen()? accentColor : textColor,
atlas.imageRectf(root.tinyDot()));
ColorBank::Colorf const &textColor = fold.title().textColorf();

verts.makeFlexibleFrame(rect.toRectanglei(), 5, textColor,
atlas.imageRectf(root.roundCorners()));

Rectanglef uv = atlas.imageRectf(root.fold());
if(!fold.isOpen())
{
// Flip it.
uv = Rectanglef(uv.bottomLeft(), uv.topRight());
}
verts.makeQuad(rect, textColor * Vector4f(1, 1, 1, .5f), uv);
}
};*/
};

ButtonWidget *title; // not owned
GuiWidget *container; ///< Held here while not part of the widget tree.
Expand All @@ -85,9 +84,10 @@ ButtonWidget *FoldPanelWidget::makeTitle(String const &text)
d->title->setAction(new SignalAction(this, SLOT(toggleFold())));
d->title->setOpacity(.8f);

// Icon is disabled for now, doesn't look quite right.
//d->title->setImage(new Instance::FoldImage(*this));
//d->title->setTextAlignment(ui::AlignRight); // Text is on the right from the image.
// Fold indicator.
d->title->setImage(new Instance::FoldImage(*this));
d->title->setTextAlignment(ui::AlignLeft);
d->title->setTextGap("gap");

return d->title;
}
Expand Down
7 changes: 5 additions & 2 deletions doomsday/libdeng2/include/de/core/rectangle.h
Expand Up @@ -115,9 +115,12 @@ class Rectangle
RectangleType adjusted(CornerVectorType const &tl, CornerVectorType const &br) const {
return RectangleType(topLeft + tl, bottomRight + br);
}
Rectangle<Vector2i, Vector2ui> toRectanglei() const {
return Rectangle<Vector2i, Vector2ui>(topLeft.toVector2i(), bottomRight.toVector2i());
}
Rectangle<Vector2ui, Vector2ui> toRectangleui() const {
Vector2ui tl(duint(de::max(0, topLeft.x)), duint(de::max(0, topLeft.y)));
Vector2ui br(duint(de::max(0, bottomRight.x)), duint(de::max(0, bottomRight.y)));
Vector2ui tl(duint(de::max(Type(0), topLeft.x)), duint(de::max(Type(0), topLeft.y)));
Vector2ui br(duint(de::max(Type(0), bottomRight.x)), duint(de::max(Type(0), bottomRight.y)));
return Rectangle<Vector2ui, Vector2ui>(tl, br);
}
bool contains(Corner const &point) const {
Expand Down

0 comments on commit 50a0ba1

Please sign in to comment.