Skip to content

Commit

Permalink
Move invariants outside of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
timangus committed Oct 27, 2023
1 parent 7733584 commit 9958c25
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions source/app/rendering/graphrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,24 @@ void GraphRenderer::createGPUGlyphData(const QString& text, const QColor& textCo

auto& textLayout = _textLayoutResults._layouts[text];

auto verticalCentre = -textLayout._xHeight * textScale * 0.5f;
auto top = elementSize;
auto bottom = (-elementSize) - (textLayout._xHeight * textScale);
const auto verticalCentre = -textLayout._xHeight * textScale * 0.5f;
const auto top = elementSize;
const auto bottom = (-elementSize) - (textLayout._xHeight * textScale);

auto horizontalCentre = -textLayout._width * textScale * 0.5f;
auto right = elementSize;
auto left = (-elementSize) - (textLayout._width * textScale);
const auto horizontalCentre = -textLayout._width * textScale * 0.5f;
const auto right = elementSize;
const auto left = (-elementSize) - (textLayout._width * textScale);

std::array<float, 2> baseOffset{{0.0f, 0.0f}};
switch(textAlignment)
{
default:
case TextAlignment::Right: baseOffset = {{right, verticalCentre}}; break;
case TextAlignment::Left: baseOffset = {{left, verticalCentre}}; break;
case TextAlignment::Centre: baseOffset = {{horizontalCentre, verticalCentre}}; break;
case TextAlignment::Top: baseOffset = {{horizontalCentre, top }}; break;
case TextAlignment::Bottom: baseOffset = {{horizontalCentre, bottom }}; break;
}

for(const auto& glyph : textLayout._glyphs)
{
Expand All @@ -196,17 +207,6 @@ void GraphRenderer::createGPUGlyphData(const QString& text, const QColor& textCo

glyphData._component = componentIndex;

std::array<float, 2> baseOffset{{0.0f, 0.0f}};
switch(textAlignment)
{
default:
case TextAlignment::Right: baseOffset = {{right, verticalCentre}}; break;
case TextAlignment::Left: baseOffset = {{left, verticalCentre}}; break;
case TextAlignment::Centre: baseOffset = {{horizontalCentre, verticalCentre}}; break;
case TextAlignment::Top: baseOffset = {{horizontalCentre, top }}; break;
case TextAlignment::Bottom: baseOffset = {{horizontalCentre, bottom }}; break;
}

glyphData._glyphOffset[0] = baseOffset[0] + (static_cast<float>(glyph._advance) * textScale);
glyphData._glyphOffset[1] = baseOffset[1] - ((textureGlyph._height + textureGlyph._ascent) * textScale);
glyphData._glyphSize[0] = textureGlyph._width;
Expand Down

0 comments on commit 9958c25

Please sign in to comment.