forked from NaiJi/project-kyoku
85 lines
2.1 KiB
C++
85 lines
2.1 KiB
C++
|
#include "debughelper.h"
|
||
|
|
||
|
DebugHelper::DebugHelper(bool init) :
|
||
|
_toggled(init)
|
||
|
{
|
||
|
_bpm_pulse.setSize({460, 360});
|
||
|
_bpm_pulse.setOrigin(0.f, 0.f);
|
||
|
_bpm_pulse.setFillColor(sf::Color(255, 0, 0, 0));
|
||
|
_tap_pulse.setSize({460, 360});
|
||
|
_tap_pulse.move(460.f, 0.f);
|
||
|
_tap_pulse.setFillColor(sf::Color(0, 255, 0, 0));
|
||
|
_death_pulse.setSize({460, 360});
|
||
|
_death_pulse.move(460.f, 360.f);
|
||
|
_death_pulse.setFillColor(sf::Color(0, 100, 255, 0));
|
||
|
|
||
|
_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;
|
||
|
}
|
||
|
|
||
|
static bool isVisible(const sf::Shape* shape)
|
||
|
{
|
||
|
return shape->getFillColor().a > 0;
|
||
|
}
|
||
|
|
||
|
void DebugHelper::update(const sf::Int64 µseconds)
|
||
|
{
|
||
|
_time_print.setString(std::to_string(microseconds));
|
||
|
|
||
|
if (isVisible(&_bpm_pulse))
|
||
|
{
|
||
|
const auto new_alpha = _bpm_pulse.getFillColor().a - 25;
|
||
|
_bpm_pulse.setFillColor(sf::Color(255, 0, 0, (new_alpha < 0) ? 0 : new_alpha));
|
||
|
}
|
||
|
|
||
|
if (isVisible(&_tap_pulse))
|
||
|
{
|
||
|
const auto new_alpha = _tap_pulse.getFillColor().a - 25;
|
||
|
_tap_pulse.setFillColor(sf::Color(0, 255, 0, (new_alpha < 0) ? 0 : new_alpha));
|
||
|
}
|
||
|
|
||
|
if (isVisible(&_death_pulse))
|
||
|
{
|
||
|
const auto new_alpha = _death_pulse.getFillColor().a - 25;
|
||
|
_death_pulse.setFillColor(sf::Color(0, 100, 255, (new_alpha < 0) ? 0 : new_alpha));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DebugHelper::drawOn(sf::RenderWindow &game_window) const
|
||
|
{
|
||
|
if (_toggled)
|
||
|
{
|
||
|
game_window.draw(_bpm_pulse);
|
||
|
game_window.draw(_tap_pulse);
|
||
|
game_window.draw(_death_pulse);
|
||
|
game_window.draw(_time_print);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DebugHelper::onUserTap()
|
||
|
{
|
||
|
const sf::Uint8 alpha = 255;
|
||
|
_tap_pulse.setFillColor(sf::Color(255, 0, 0, alpha));
|
||
|
}
|
||
|
|
||
|
void DebugHelper::onBeat()
|
||
|
{
|
||
|
const sf::Uint8 alpha = 255;
|
||
|
_bpm_pulse.setFillColor(sf::Color(0, 255, 0, alpha));
|
||
|
}
|
||
|
|
||
|
void DebugHelper::onDeath()
|
||
|
{
|
||
|
const sf::Uint8 alpha = 255;
|
||
|
_death_pulse.setFillColor(sf::Color(0, 100, 255, alpha));
|
||
|
}
|