#include "debug.h" #include // for max #include "resource.h" // for Resource #include "screen.h" // for Screen #include "text.h" // for Text #include "utils.h" // for Color // [SINGLETON] Debug *Debug::debug_ = nullptr; // [SINGLETON] Crearemos el objeto con esta función estática void Debug::init() { Debug::debug_ = new Debug(); } // [SINGLETON] Destruiremos el objeto con esta función estática void Debug::destroy() { delete Debug::debug_; } // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él Debug *Debug::get() { return Debug::debug_; } // Constructor Debug::Debug() // Copia la dirección de los objetos : screen_(Screen::get()), renderer_(Screen::get()->getRenderer()) { // Reserva memoria para los punteros texture_ = Resource::get()->getTexture("debug.png"); text_ = Resource::get()->getText("debug"); } // Actualiza las variables void Debug::update() { } // Dibuja en pantalla void Debug::render() { int y = 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 = y_; x_ += w * text_->getCharacterSize() + 2; } } y = 0; for (auto l : log_) { text_->writeColored(x_ + 10, y, l, Color(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; }