/**
 * Copyright (c) 2021 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#include "label.h"

void labelInit(label_t *label) {
  label->x = 0;
  label->y = 0;
  label->z = 0;
  label->fontSize = FONT_SIZE_DEFAULT;
  label->font = NULL;
  label->primitive.verticeCount = 0;
}

void labelSetText(label_t *label, font_t *font, char *text) {
  if(label->primitive.verticeCount != 0) {
    primitiveDispose(&label->primitive);
    label->primitive.verticeCount = 0;
  }

  label->font = font;
  fontTextClamp(font, &label->info, text, -1, label->fontSize);
  fontTextInit(font, &label->primitive, &label->info);
}

void labelRender(label_t *label, shader_t *shader) {
  if(label->primitive.verticeCount == 0) return;
  shaderUsePosition(shader, label->x, label->y, label->z, 0, 0, 0);
  shaderUseTexture(shader, &label->font->texture);
  primitiveDraw(&label->primitive, 0, -1);
}

void labelDispose(label_t *label) {
  primitiveDispose(&label->primitive);
}