Skip to content

Commit

Permalink
Client|UI|GLTextComposer: Better way to set partial range of lines
Browse files Browse the repository at this point in the history
GLTextComposer also needs to allocate only the visible lines, so just
doing the geometry is not enough.
  • Loading branch information
skyjake committed Jul 28, 2013
1 parent ba33772 commit c0de527
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
20 changes: 7 additions & 13 deletions doomsday/client/include/ui/widgets/gltextcomposer.h
Expand Up @@ -51,6 +51,13 @@ class GLTextComposer : public de::Asset
void setStyledText(de::String const &styledText);
void setText(de::String const &text, de::Font::RichFormat const &format);

/**
* Sets the range of visible lines.
*
* @param visibleLineRage Visible range of lines.
*/
void setRange(de::Rangei const &visibleLineRange);

/**
* Makes sure all the lines are allocated on the atlas. After this all the
* allocated lines match the ones in the wrapping. This must be called
Expand All @@ -76,12 +83,6 @@ class GLTextComposer : public de::Asset
ui::Alignment const &lineAlign,
de::Vector4f const &color = de::Vector4f(1, 1, 1, 1));

void makeVerticesForRange(de::Rangei const &lineRange,
Vertices &triStrip,
de::Vector2i const &topLeft,
ui::Alignment const &lineAlign,
de::Vector4f const &color = de::Vector4f(1, 1, 1, 1));

/**
* Generates vertices for all the text lines and concatenates them
* onto the existing triangle strip in @a triStrip.
Expand All @@ -94,13 +95,6 @@ class GLTextComposer : public de::Asset
ui::Alignment const &lineAlign,
de::Vector4f const &color = de::Vector4f(1, 1, 1, 1));

void makeVerticesForRange(de::Rangei const &lineRange,
Vertices &triStrip,
de::Rectanglei const &rect,
ui::Alignment const &alignInRect,
ui::Alignment const &lineAlign,
de::Vector4f const &color = de::Vector4f(1, 1, 1, 1));

private:
DENG2_PRIVATE(d)
};
Expand Down
48 changes: 20 additions & 28 deletions doomsday/client/src/ui/widgets/gltextcomposer.cpp
Expand Up @@ -31,6 +31,7 @@ DENG2_PIMPL(GLTextComposer)
FontLineWrapping const *wraps;
Font::RichFormat format;
bool needRedo;
Rangei visibleLineRange; ///< Only these lines will be updated/drawn.

struct Line {
struct Segment {
Expand All @@ -49,7 +50,9 @@ DENG2_PIMPL(GLTextComposer)
typedef QList<Line> Lines;
Lines lines;

Instance(Public *i) : Base(i), font(0), atlas(0), wraps(0), needRedo(false)
Instance(Public *i)
: Base(i), font(0), atlas(0), wraps(0), needRedo(false),
visibleLineRange(0, 0x7fffffff)
{}

~Instance()
Expand Down Expand Up @@ -82,6 +85,11 @@ DENG2_PIMPL(GLTextComposer)
ln.segs.clear();
}

bool isLineVisible(int line) const
{
return visibleLineRange.contains(line);
}

String segmentText(int seg, FontLineWrapping::LineInfo const &info) const
{
return text.substr(info.segs[seg].range);
Expand Down Expand Up @@ -125,7 +133,7 @@ DENG2_PIMPL(GLTextComposer)
if(i < lines.size())
{
// Is the rasterized copy up to date?
if(matchingSegments(i, info))
if(!isLineVisible(i) || matchingSegments(i, info))
{
// This line can be kept as is.
continue;
Expand All @@ -152,7 +160,7 @@ DENG2_PIMPL(GLTextComposer)
Line::Segment seg;
seg.range = info.segs[k].range;
seg.text = segmentText(k, info);
if(seg.range.size() > 0)
if(isLineVisible(i) && seg.range.size() > 0)
{
// The color is white unless a style is defined.
Vector4ub fgColor(255, 255, 255, 255);
Expand Down Expand Up @@ -226,6 +234,11 @@ void GLTextComposer::setText(String const &text, Font::RichFormat const &format)
setState(false);
}

void GLTextComposer::setRange(Rangei const &visibleLineRange)
{
d->visibleLineRange = visibleLineRange;
}

bool GLTextComposer::update()
{
DENG2_ASSERT(d->wraps != 0);
Expand Down Expand Up @@ -259,32 +272,11 @@ void GLTextComposer::makeVertices(Vertices &triStrip,
makeVertices(triStrip, Rectanglei(topLeft, topLeft), AlignTopLeft, lineAlign, color);
}

void GLTextComposer::makeVerticesForRange(Rangei const &lineRange,
Vertices &triStrip,
Vector2i const &topLeft,
Alignment const &lineAlign,
Vector4f const &color)
{
makeVerticesForRange(lineRange, triStrip, Rectanglei(topLeft, topLeft),
AlignTopLeft, lineAlign, color);
}

void GLTextComposer::makeVertices(Vertices &triStrip,
Rectanglei const &rect,
Alignment const &alignInRect,
Alignment const &lineAlign,
Vector4f const &color)
{
makeVerticesForRange(Rangei(0, d->lines.size()), triStrip,
rect, alignInRect, lineAlign, color);
}

void GLTextComposer::makeVerticesForRange(Rangei const &lineRange,
Vertices &triStrip,
Rectanglei const &rect,
Alignment const &alignInRect,
Alignment const &lineAlign,
Vector4f const &color)
{
if(!isReady()) return;

Expand Down Expand Up @@ -380,12 +372,12 @@ void GLTextComposer::makeVerticesForRange(Rangei const &lineRange,
for(int i = 0; i < d->wraps->height(); ++i)
{
Instance::Line const &line = d->lines[i];
FontLineWrapping::LineInfo const &info = d->wraps->lineInfo(i);

Vector2f linePos = p;

if(lineRange.contains(i))
if(d->isLineVisible(i))
{
FontLineWrapping::LineInfo const &info = d->wraps->lineInfo(i);
Vector2f linePos = p;

for(int k = 0; k < info.segs.size(); ++k)
{
Instance::Line::Segment const &seg = line.segs[k];
Expand Down

0 comments on commit c0de527

Please sign in to comment.