Skip to content

Commit

Permalink
Refactor|libappfw: Animating procedural images, fold panel indicator
Browse files Browse the repository at this point in the history
If a procedural image is animating, it will return indication of
that from its update() method.

The fold panel indicator now turns 90 degrees with an animation
depending on whether the fold is open or closed.
  • Loading branch information
skyjake committed Apr 12, 2014
1 parent ccdac3c commit 57ca804
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
Expand Up @@ -79,13 +79,15 @@ class LIBAPPFW_PUBLIC AtlasProceduralImage : public ProceduralImage
setSize(image.size());
}

void update()
bool update()
{
if(_needUpdate)
{
alloc();
_needUpdate = false;
return true;
}
return false;
}

void glInit()
Expand Down
9 changes: 8 additions & 1 deletion doomsday/libappfw/include/de/framework/proceduralimage.h
Expand Up @@ -49,7 +49,14 @@ class LIBAPPFW_PUBLIC ProceduralImage
void setSize(Size const &size);
void setColor(Color const &color);

virtual void update();
/**
* Updates the image.
*
* @return @c true, if the geometry has changed and it should be remade. Otherwise
* @c false if nothing has been changed.
*/
virtual bool update();

virtual void glInit();
virtual void glDeinit();
virtual void glMakeGeometry(DefaultVertexBuf::Builder &verts, Rectanglef const &rect) = 0;
Expand Down
2 changes: 0 additions & 2 deletions doomsday/libappfw/include/de/framework/styleproceduralimage.h
Expand Up @@ -49,8 +49,6 @@ class StyleProceduralImage : public ProceduralImage
setSize(root().atlas().imageRect(_id).size());
}

void update() {}

void glInit()
{
alloc();
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libappfw/src/proceduralimage.cpp
Expand Up @@ -46,9 +46,10 @@ void ProceduralImage::setColor(Color const &color)
_color = color;
}

void ProceduralImage::update()
bool ProceduralImage::update()
{
// optional for derived classes
return false;
}

void ProceduralImage::glInit()
Expand Down
56 changes: 44 additions & 12 deletions doomsday/libappfw/src/widgets/foldpanelwidget.cpp
Expand Up @@ -27,18 +27,53 @@ using namespace ui;

DENG2_PIMPL_NOREF(FoldPanelWidget)
{
/**
* Indicator that shows whether a fold panel is open or closed.
*/
struct FoldImage : public ProceduralImage
{
FoldPanelWidget &fold;
bool needUpdate;

FoldImage(FoldPanelWidget &owner) : fold(owner), needUpdate(true)
bool needSize;
bool animating;
Animation angle;

FoldImage(FoldPanelWidget &owner)
: fold(owner)
, needSize(true)
, animating(false)
, angle(0, Animation::EaseBoth)
{}

void update()
/// We'll report the status as changed if the image was animating or its
/// size was updated.
bool update()
{
float h = fold.title().font().height().value();
setSize(Vector2f(h, h));
bool changed = animating;

float target = (fold.isOpen()? 0 : 90);
if(target != angle.target())
{
angle.setValue(target, 1);
animating = true;
changed = true;
}

if(needSize)
{
needSize = false;
changed = true;

float h = fold.title().font().height().value();
setSize(Vector2f(h, h));
}

// Stop animating?
if(animating && angle.done())
{
animating = false;
}

return changed;
}

void glMakeGeometry(DefaultVertexBuf::Builder &verts, Rectanglef const &rect)
Expand All @@ -47,16 +82,13 @@ DENG2_PIMPL_NOREF(FoldPanelWidget)
Atlas &atlas = root.atlas();
ColorBank::Colorf const &textColor = fold.title().textColorf();

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

Rectanglef uv = atlas.imageRectf(root.styleTexture("fold"));
if(!fold.isOpen())
{
// Flip it.
uv = Rectanglef(uv.bottomLeft(), uv.topRight());
}
verts.makeQuad(rect, textColor * Vector4f(1, 1, 1, .5f), uv);
Matrix4f const turn = Matrix4f::rotateAround(rect.middle(), angle);
verts.makeQuad(rect, textColor * Vector4f(1, 1, 1, .5f), uv, &turn);
}
};

Expand Down
8 changes: 4 additions & 4 deletions doomsday/libappfw/src/widgets/labelwidget.cpp
Expand Up @@ -483,13 +483,13 @@ public Font::RichFormat::IStyle
void updateGeometry()
{
// Update the image on the atlas.
if(!image.isNull())
if(!image.isNull() && image->update())
{
image->update();
self.requestGeometry();
}
if(!overlayImage.isNull())
if(!overlayImage.isNull() && overlayImage->update())
{
overlayImage->update();
self.requestGeometry();
}

glText.setLineWrapWidth(availableTextWidth());
Expand Down
5 changes: 3 additions & 2 deletions doomsday/libappfw/src/widgets/togglewidget.cpp
Expand Up @@ -51,13 +51,14 @@ DENG2_OBSERVES(ButtonWidget, Press)
_animating = true;
}

void update()
bool update()
{
if(_animating)
{
_owner.requestGeometry();
if(_pos.done()) _animating = false;
return true;
}
return false;
}

void glMakeGeometry(DefaultVertexBuf::Builder &verts, Rectanglef const &rect)
Expand Down

0 comments on commit 57ca804

Please sign in to comment.