#include "NotifyLayer.h" #include #include "../ManagementContext/StyleManagmentContext.h" void NotifyAppLayer::OnActivate() { isActive = true; } void NotifyAppLayer::OnDeactivate() { isActive = false; } void NotifyAppLayer::OnRender() { if (secondsLeft <= 0.0) { return; } secondsLeft -= (SDL_GetTicks() - startTime) / 1000.0; startTime = SDL_GetTicks(); const float paddingHorizontal = 16.0f; const float paddingVertical = 8.0f; float gray = secondsLeft > 0.5 ? 0.5f : secondsLeft; StyleManagmentContext::Push(NOTIFY); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.25f, 0.25f, 0.25f, gray)); const ImGuiViewport* viewport = ImGui::GetMainViewport(); ImVec2 work_pos = viewport->WorkPos; ImVec2 work_size = viewport->WorkSize; ImVec2 window_pos; ImVec2 messageSize = ImGui::CalcTextSize(message.c_str()); float messageWidth = messageSize.x + paddingHorizontal * 2; window_pos.x = work_pos.x + (work_size.x / 2) - (messageWidth / 2); window_pos.y = work_pos.y + 8 + messageSize.y + (paddingVertical * 2); ImGui::SetNextWindowPos((window_pos), 0, ImVec2(0.0f, 1.0f)); ImGui::SetNextWindowBgAlpha(secondsLeft > 0.5 ? 0.5f : secondsLeft); ImGui::Begin("Notification", (bool*)NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove); ImGui::Text("%s", message.c_str()); ImGui::End(); ImGui::PopStyleColor(); StyleManagmentContext::Pop(); } void NotifyAppLayer::SetMessage(std::string message, double seconds) { NotifyAppLayer::message = message; secondsLeft = seconds; startTime = SDL_GetTicks(); } std::string NotifyAppLayer::message; double NotifyAppLayer::secondsLeft = 0.0; long int NotifyAppLayer::startTime = 0;