
#include <Spectre/Graphics/BatchRenderer2D.h>
#include <Spectre/Input/InputModule.h>
#include <Spectre/Graphics/Font.h>
#include <Spectre/Graphics/Text.h>
#include "Game.h"

Font smallFont;
Font myFont;
Font fntLarge;

Text myText;
Text txtLarge;
Text txtKerning;
Text fpsText;
Text txtSmall;

Camera2D guiCamera;

BatchRenderer2D *renderer;

void TextExample::init()
{
	Graphics* g = getGraphics();

	g->setClearColor(52.0f / 255.0f, 58.0f / 255.0f, 80.0f / 255.0f);

	smallFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf");
	myFont.loadFromFile("assets/fonts/RobotoCondensed-Regular.ttf");
	fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf");

	myText.setFont(myFont);
	myText.setColor(Color::Green);
	myText.setString("Hello");
	myText.setPosition(25.0f, 50.0f);

	txtLarge.setFont(myFont);
	txtLarge.setColor(Color(200, 100, 0));
	txtLarge.setString("Large Text, Looks good?");
	txtLarge.setPosition(300.0f, 150.0f);
	txtLarge.setScale(2.0f);

	txtKerning.setFont(fntLarge);
	txtKerning.setColor(Color(150, 0, 230));
	txtKerning.setString("Kerning: VA Ta");
	txtKerning.setPosition(150.0f, 200.0f);

	txtSmall.setFont(smallFont);
	txtSmall.setString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a rhoncus odio, nec finibus libero.");
	txtSmall.setPosition(50.0f, 450.0f);

	fpsText.setFont(myFont);
	fpsText.setString("FPS: 0");
	fpsText.setPosition(10.0f, 10.0f);

	renderer = new BatchRenderer2D();
}

void TextExample::update(double dt)
{
	InputModule* input = getInput();
	input->update();

	if (getFpsCounter().update()) {
		std::string str = "FPS: " + core::to_string(getFpsCounter().getFPS(), 0);
		fpsText.setString(str);
	}
}

void TextExample::render()
{
	Graphics* g = getGraphics();

	g->clearBuffer();

	renderer->begin();

	renderer->submit(fpsText);
	renderer->submit(myText);
	renderer->submit(txtLarge);
	renderer->submit(txtKerning);
	renderer->submit(txtSmall);

	renderer->setCamera(guiCamera);
	renderer->render();

	g->swapBuffers();
}