2021-04-05 16:17:57 +02:00
|
|
|
#include "debughelper.h"
|
|
|
|
|
|
|
|
DebugHelper::DebugHelper(bool init) :
|
2021-04-06 19:39:29 +02:00
|
|
|
_toggled(init),
|
|
|
|
_red_pulse({0.f, 0.f}, sf::Color(255, 0, 0)),
|
|
|
|
_green_pulse({460.f, 0.f}, sf::Color(0, 255, 0)),
|
|
|
|
_blue_pulse({460.f, 360.f}, sf::Color(0, 100, 255))
|
2021-04-05 16:17:57 +02:00
|
|
|
{
|
|
|
|
_font.loadFromFile("VeraMono.ttf");
|
|
|
|
|
|
|
|
_time_print.setFont(_font);
|
|
|
|
_time_print.setPosition(60, 60);
|
|
|
|
_time_print.setFillColor(sf::Color(255, 255, 255));
|
|
|
|
_time_print.setCharacterSize(25);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugHelper::toggle()
|
|
|
|
{
|
|
|
|
_toggled = !_toggled;
|
|
|
|
}
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
void DebugHelper::update(const microsec µseconds)
|
2021-04-05 16:17:57 +02:00
|
|
|
{
|
|
|
|
_time_print.setString(std::to_string(microseconds));
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
_red_pulse.fade();
|
|
|
|
_green_pulse.fade();
|
|
|
|
_blue_pulse.fade();
|
2021-04-05 16:17:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-08 15:34:03 +02:00
|
|
|
void DebugHelper::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
2021-04-05 16:17:57 +02:00
|
|
|
{
|
|
|
|
if (_toggled)
|
|
|
|
{
|
2021-04-08 15:34:03 +02:00
|
|
|
target.draw(_green_pulse, states);
|
|
|
|
target.draw(_red_pulse, states);
|
|
|
|
target.draw(_blue_pulse, states);
|
|
|
|
target.draw(_time_print, states);
|
2021-04-05 16:17:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
void DebugHelper::spawnGreenPulse()
|
|
|
|
{
|
|
|
|
_green_pulse.appear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugHelper::spawnRedPulse()
|
|
|
|
{
|
|
|
|
_red_pulse.appear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugHelper::spawnBluePulse()
|
|
|
|
{
|
|
|
|
_blue_pulse.appear();
|
|
|
|
}
|
|
|
|
|
|
|
|
DebugHelper::Pulse::Pulse(sf::Vector2f position, sf::Color fill_color)
|
2021-04-05 16:17:57 +02:00
|
|
|
{
|
2021-04-06 19:39:29 +02:00
|
|
|
_pulse_shape.setSize({480, 360});
|
|
|
|
_pulse_shape.move(position.x, position.y);
|
|
|
|
|
|
|
|
fill_color.a = 0;
|
|
|
|
_pulse_shape.setFillColor(fill_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugHelper::Pulse::appear()
|
|
|
|
{
|
|
|
|
auto fill_color = _pulse_shape.getFillColor();
|
|
|
|
fill_color.a = 255;
|
|
|
|
_pulse_shape.setFillColor(fill_color);
|
2021-04-05 16:17:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
void DebugHelper::Pulse::fade()
|
2021-04-05 16:17:57 +02:00
|
|
|
{
|
2021-04-06 19:39:29 +02:00
|
|
|
auto fill_color = _pulse_shape.getFillColor();
|
|
|
|
|
|
|
|
if (fill_color.a == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto new_alpha = fill_color.a - 25;
|
|
|
|
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
|
|
|
|
|
|
|
|
_pulse_shape.setFillColor(fill_color);
|
2021-04-05 16:17:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-08 15:34:03 +02:00
|
|
|
void DebugHelper::Pulse::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
2021-04-05 16:17:57 +02:00
|
|
|
{
|
2021-04-08 15:34:03 +02:00
|
|
|
target.draw(_pulse_shape, states);
|
2021-04-05 16:17:57 +02:00
|
|
|
}
|