diff --git a/doomsday/client/client.pro b/doomsday/client/client.pro index 6e9da6cf6e..c1a61789c8 100644 --- a/doomsday/client/client.pro +++ b/doomsday/client/client.pro @@ -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 \ diff --git a/doomsday/client/include/ui/widgets/gltextcomposer.h b/doomsday/client/include/ui/widgets/gltextcomposer.h index 22dba536ad..006b360acf 100644 --- a/doomsday/client/include/ui/widgets/gltextcomposer.h +++ b/doomsday/client/include/ui/widgets/gltextcomposer.h @@ -24,6 +24,7 @@ #include #include +#include "alignment.h" #include "fontlinewrapping.h" /** @@ -37,22 +38,6 @@ class GLTextComposer typedef de::GLBufferT 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(); @@ -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 @@ -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 diff --git a/doomsday/client/src/ui/widgets/gltextcomposer.cpp b/doomsday/client/src/ui/widgets/gltextcomposer.cpp index 2533f38cba..cb8e14dcf9 100644 --- a/doomsday/client/src/ui/widgets/gltextcomposer.cpp +++ b/doomsday/client/src/ui/widgets/gltextcomposer.cpp @@ -167,15 +167,17 @@ 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; @@ -183,22 +185,7 @@ void GLTextComposer::makeVertices(Vertices &triStrip, 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()); @@ -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(); }