<commit_before>//
// Created by dar on 2/11/16.
//

#include "TextRender.h"
#include <gui/GuiText.h>

TextRender::TextRender() : GuiElementRender("font", "font") { }

void TextRender::render(const GuiElement *const element, glm::mat4 projectionMatrix, glm::mat4 viewMatrix, double scale) {
    const GuiText *const text = (const GuiText *const) element;
    texture.bindTexture(0);
    this->shaderProgram.useProgram();
    this->shaderProgram.setUniform("projectionMatrix", projectionMatrix);
    this->shaderProgram.setUniform("gSampler", texture.getBoundId());

    scale *= text->getScale();

    double x = text->getX();
    for (int i = 0; i < text->getString().length(); i++) {
        int texId = text->getTexPos(i);
        if (texId == -1) {
            x += text->TEXT_SPACESIZE * scale + text->SPACING_PX;
            continue;
        }
        this->tmpModelMatrix = glm::translate(this->modelMatrix, glm::vec3(-(x + scale), -(text->getY() + scale), 0.0f));
        this->tmpModelMatrix = glm::scale(this->tmpModelMatrix, glm::vec3(scale, scale, 1.0f));

        shaderProgram.setUniform("modelViewMatrix", viewMatrix * this->tmpModelMatrix);

        int texX = texId % atlasSize,  texY = texId / atlasSize;
        shaderProgram.setUniform("texPosX", 0.5f / texture.getWidth() + (float) texX / atlasSize);
        shaderProgram.setUniform("texPosY", 0.5f / texture.getHeight() + (float) texY / atlasSize);

        int color = text->getColor();
        float r = ((color & 0xFF000000) >> 24) / 255.0f;
        float g = ((color & 0x00FF0000) >> 16) / 255.0f;
        float b = ((color & 0x0000FF00) >> 8) / 255.0f;
        float a = (color & 0x000000FF) / 255.0f;

        shaderProgram.setUniform("colorMod", glm::vec4(r, g, b, a));

        glBindVertexArray(this->vao);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

        x += text->getGlyphSize(texId) * scale + text->SPACING_PX;
    }
}<commit_msg>Handle '\n' character in TextRender<commit_after>//
// Created by dar on 2/11/16.
//

#include "TextRender.h"
#include <gui/GuiText.h>

TextRender::TextRender() : GuiElementRender("font", "font") { }

void TextRender::render(const GuiElement *const element, glm::mat4 projectionMatrix, glm::mat4 viewMatrix, double scale) {
    const GuiText *const text = (const GuiText *const) element;
    texture.bindTexture(0);
    this->shaderProgram.useProgram();
    this->shaderProgram.setUniform("projectionMatrix", projectionMatrix);
    this->shaderProgram.setUniform("gSampler", texture.getBoundId());

    scale *= text->getScale();

    double x = text->getX();
    double y = text->getY();
    for (int i = 0; i < text->getString().length(); i++) {
        if (text->getString().at(i) == '\n') {
            x = text->getX();
            y += scale + 2 * text->SPACING_PX;
            continue;
        }
        int texId = text->getTexPos(i);
        if (texId == -1) {
            x += text->TEXT_SPACESIZE * scale + text->SPACING_PX;
            continue;
        }
        this->tmpModelMatrix = glm::translate(this->modelMatrix, glm::vec3(-(x + scale), -(y + scale), 0.0f));
        this->tmpModelMatrix = glm::scale(this->tmpModelMatrix, glm::vec3(scale, scale, 1.0f));

        shaderProgram.setUniform("modelViewMatrix", viewMatrix * this->tmpModelMatrix);

        int texX = texId % atlasSize,  texY = texId / atlasSize;
        shaderProgram.setUniform("texPosX", 0.5f / texture.getWidth() + (float) texX / atlasSize);
        shaderProgram.setUniform("texPosY", 0.5f / texture.getHeight() + (float) texY / atlasSize);

        int color = text->getColor();
        float r = ((color & 0xFF000000) >> 24) / 255.0f;
        float g = ((color & 0x00FF0000) >> 16) / 255.0f;
        float b = ((color & 0x0000FF00) >> 8) / 255.0f;
        float a = (color & 0x000000FF) / 255.0f;

        shaderProgram.setUniform("colorMod", glm::vec4(r, g, b, a));

        glBindVertexArray(this->vao);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

        x += text->getGlyphSize(texId) * scale + text->SPACING_PX;
    }
}
{'fraction_non_alphanumeric': 0.16501731815932708, 'fraction_numerical': 0.03587333003463632, 'mean_word_length': 2.955968688845401, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7367005', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1366, 'n_words': 285}