106 lines
1.7 KiB
C++
106 lines
1.7 KiB
C++
#include "debug.h"
|
|
|
|
// Constructor
|
|
Debug::Debug(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
|
{
|
|
// Copia la dirección de los objetos
|
|
this->renderer = renderer;
|
|
this->screen = screen;
|
|
this->asset = asset;
|
|
|
|
// Reserva memoria para los punteros
|
|
texture = new Texture(renderer, asset->get("debug.png"));
|
|
text = new Text(asset->get("debug.txt"), texture, renderer);
|
|
|
|
// Inicializa variables
|
|
x = 0;
|
|
y = 0;
|
|
enabled = false;
|
|
}
|
|
|
|
// Destructor
|
|
Debug::~Debug()
|
|
{
|
|
delete texture;
|
|
delete text;
|
|
}
|
|
|
|
// Actualiza las variables
|
|
void Debug::update()
|
|
{
|
|
}
|
|
|
|
// Dibuja en pantalla
|
|
void Debug::render()
|
|
{
|
|
int y = this->y;
|
|
int w = 0;
|
|
|
|
for (auto s : slot)
|
|
{
|
|
text->write(x, y, s);
|
|
w = (std::max(w, (int)s.length()));
|
|
y += text->getCharacterSize() + 1;
|
|
if (y > 192 - text->getCharacterSize())
|
|
{
|
|
y = this->y;
|
|
x += w * text->getCharacterSize() + 2;
|
|
}
|
|
}
|
|
|
|
y = 0;
|
|
for (auto l : log)
|
|
{
|
|
text->writeColored(x + 10, y, l, {255, 255, 255});
|
|
y += text->getCharacterSize() + 1;
|
|
}
|
|
}
|
|
|
|
// Establece la posición donde se colocará la información de debug
|
|
void Debug::setPos(SDL_Point p)
|
|
{
|
|
x = p.x;
|
|
y = p.y;
|
|
}
|
|
|
|
// Añade un texto para mostrar
|
|
void Debug::add(std::string text)
|
|
{
|
|
slot.push_back(text);
|
|
}
|
|
|
|
// Borra la información de debug
|
|
void Debug::clear()
|
|
{
|
|
slot.clear();
|
|
}
|
|
|
|
// Añade un texto para mostrar en el apartado log
|
|
void Debug::addToLog(std::string text)
|
|
{
|
|
log.push_back(text);
|
|
}
|
|
|
|
// Borra la información de debug del apartado log
|
|
void Debug::clearLog()
|
|
{
|
|
log.clear();
|
|
}
|
|
|
|
// Establece el valor de la variable
|
|
void Debug::setEnabled(bool value)
|
|
{
|
|
enabled = value;
|
|
}
|
|
|
|
// Obtiene el valor de la variable
|
|
bool Debug::getEnabled()
|
|
{
|
|
return enabled;
|
|
}
|
|
|
|
// Cambia el valor de la variable
|
|
void Debug::switchEnabled()
|
|
{
|
|
enabled = !enabled;
|
|
} |