Skip to content

Commit

Permalink
Client|Widgets: Apply Alignment template, GLTextComposer color argument
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 28, 2013
1 parent d5a1562 commit 3105b80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
1 change: 1 addition & 0 deletions doomsday/client/client.pro
Expand Up @@ -356,6 +356,7 @@ DENG_HEADERS += \
include/ui/ui2_main.h \
include/ui/ui_main.h \
include/ui/ui_panel.h \
include/ui/widgets/alignment.h \
include/ui/widgets/busywidget.h \
include/ui/widgets/buttonwidget.h \
include/ui/widgets/consolecommandwidget.h \
Expand Down
25 changes: 5 additions & 20 deletions doomsday/client/include/ui/widgets/gltextcomposer.h
Expand Up @@ -24,6 +24,7 @@
#include <de/Atlas>
#include <de/GLBuffer>

#include "alignment.h"
#include "fontlinewrapping.h"

/**
Expand All @@ -37,22 +38,6 @@ class GLTextComposer
typedef de::GLBufferT<Vertex> VertexBuf;
typedef VertexBuf::Builder Vertices;

/**
* Flags for specifying alignment.
*/
enum AlignmentFlag
{
AlignTop = 0x1,
AlignBottom = 0x2,
AlignLeft = 0x4,
AlignRight = 0x8,

AlignCenter = 0,

DefaultAlignment = AlignCenter
};
Q_DECLARE_FLAGS(Alignment, AlignmentFlag)

public:
GLTextComposer();

Expand All @@ -78,7 +63,8 @@ class GLTextComposer

void makeVertices(Vertices &triStrip,
de::Vector2i const &topLeft,
Alignment const &lineAlign);
Alignment const &lineAlign,
de::Vector4f const &color = de::Vector4f(1, 1, 1, 1));

/**
* Generates vertices for all the text lines and concatenates them
Expand All @@ -89,12 +75,11 @@ class GLTextComposer
void makeVertices(Vertices &triStrip,
de::Rectanglei const &rect,
Alignment const &alignInRect,
Alignment const &lineAlign);
Alignment const &lineAlign,
de::Vector4f const &color = de::Vector4f(1, 1, 1, 1));

private:
DENG2_PRIVATE(d)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(GLTextComposer::Alignment)

#endif // DENG_CLIENT_GLTEXTCOMPOSER_H
27 changes: 7 additions & 20 deletions doomsday/client/src/ui/widgets/gltextcomposer.cpp
Expand Up @@ -167,38 +167,25 @@ bool GLTextComposer::update()

void GLTextComposer::makeVertices(Vertices &triStrip,
Vector2i const &topLeft,
Alignment const &lineAlign)
Alignment const &lineAlign,
Vector4f const &color)
{
makeVertices(triStrip, Rectanglei(topLeft, topLeft), AlignTop | AlignLeft, lineAlign);
makeVertices(triStrip, Rectanglei(topLeft, topLeft), AlignTopLeft, lineAlign, color);
}

void GLTextComposer::makeVertices(Vertices &triStrip,
Rectanglei const &rect,
Alignment const &alignInRect,
Alignment const &lineAlign)
Alignment const &lineAlign,
Vector4f const &color)
{
// Top left corner.
Vector2f p = rect.topLeft;

Vector2i const contentSize(d->wraps->width(), d->wraps->totalHeightInPixels());

// Apply alignment within the provided rectangle.
if(alignInRect.testFlag(AlignRight))
{
p.x += int(rect.width()) - contentSize.x;
}
else if(!alignInRect.testFlag(AlignLeft))
{
p.x += (int(rect.width()) - contentSize.x) / 2;
}
if(alignInRect.testFlag(AlignBottom))
{
p.y += int(rect.height()) - contentSize.y;
}
else if(!alignInRect.testFlag(AlignTop))
{
p.y += (int(rect.height()) - contentSize.y) / 2;
}
p = applyAlignment(alignInRect, p, contentSize, rect);

DENG2_ASSERT(d->wraps->height() == d->lines.size());

Expand All @@ -223,7 +210,7 @@ void GLTextComposer::makeVertices(Vertices &triStrip,
linePos.x += (int(rect.width()) - int(size.x)) / 2;
}

triStrip.makeQuad(Rectanglef::fromSize(linePos, size), Vector4f(1, 1, 1, 1), uv);
triStrip.makeQuad(Rectanglef::fromSize(linePos, size), color, uv);
}
p.y += d->font->lineSpacing().value();
}
Expand Down

0 comments on commit 3105b80

Please sign in to comment.