satdump/src-core/common/widgets/timed_message.cpp

39 lines
906 B
C++
Raw Permalink Normal View History

#include "core/style.h"
2023-11-29 21:30:55 -05:00
#include "timed_message.h"
namespace widgets
{
TimedMessage::TimedMessage()
2023-11-29 21:30:55 -05:00
{
start_time = nullptr;
message = "";
}
TimedMessage::~TimedMessage()
{
delete start_time;
}
void TimedMessage::set_message(ImColor color, std::string message)
2023-11-29 21:30:55 -05:00
{
if(start_time == nullptr)
start_time = new std::chrono::time_point<std::chrono::steady_clock>();
*start_time = std::chrono::steady_clock::now();
this->message = message;
this->color = color;
2023-11-29 21:30:55 -05:00
}
void TimedMessage::draw()
{
if (start_time == nullptr)
return;
double time_running = std::chrono::duration<double>(std::chrono::steady_clock::now() - *start_time).count();
if (time_running > 5)
2023-11-29 21:30:55 -05:00
{
delete start_time;
start_time = nullptr;
return;
}
else if (time_running > 4)
color.Value.w = 1.0 - (time_running - 4.0);
2023-11-29 21:30:55 -05:00
ImGui::SameLine();
ImGui::TextColored(color, "%s", message.c_str());
}
}