Fnct. to add overlay elems

pull/130/head
Peter Repukat 3 years ago
parent b829c4b680
commit 0bf9ec1108

@ -1,10 +1,12 @@
#include "Overlay.h"
#include <utility>
#define IMGUI_USER_CONFIG "imconfig.h"
#include "imgui-SFML.h"
#include "imgui.h"
Overlay::Overlay(sf::RenderWindow& window, std::function<void()> on_close) : window_(window), on_close_(on_close)
Overlay::Overlay(sf::RenderWindow& window, const std::function<void()>& on_close) : window_(window), on_close_(on_close)
{
ImGui::SFML::Init(window_);
ImGuiIO& io = ImGui::GetIO();
@ -104,7 +106,7 @@ void Overlay::update()
if (enabled_) {
window_.clear(sf::Color(0, 0, 0, 64)); // make window slightly dim screen with overlay
std::ranges::for_each(OVERLAY_ELEMS_, [](const auto& fn) { fn(); });
if (closeButton()) {
return;
@ -124,11 +126,16 @@ void Overlay::Shutdown()
ImGui::SFML::Shutdown();
}
void Overlay::ShowNotification(const spdlog::details::log_msg& msg)
void Overlay::AddLog(const spdlog::details::log_msg& msg)
{
LOG_MSGS_.push_back({.time = msg.time, .level = msg.level, .payload = msg.payload.data()});
}
void Overlay::AddOverlayElem(const std::function<void()>& elem_fn)
{
OVERLAY_ELEMS_.push_back(elem_fn);
}
void Overlay::showLogs() const
{
std::vector<Log> logs;

@ -7,7 +7,7 @@
class Overlay {
public:
Overlay(sf::RenderWindow& window, std::function<void()> on_close);
Overlay(sf::RenderWindow& window, const std::function<void()>& on_close);
void setEnabled(bool enabled);
bool isEnabled() const;
@ -15,15 +15,17 @@ class Overlay {
void update();
static void ProcessEvent(sf::Event evnt);
static void Shutdown();
static void ShowNotification(const spdlog::details::log_msg& msg);
static void AddLog(const spdlog::details::log_msg& msg);
static void AddOverlayElem(const std::function<void()>& elem_fn);
private:
sf::RenderWindow& window_;
sf::Clock update_clock_;
bool enabled_ = true;
std::function<void()> on_close_;
void showLogs() const;
bool closeButton() const;
[[nodiscard]] bool closeButton() const;
struct Log {
std::chrono::system_clock::time_point time;
@ -33,4 +35,6 @@ class Overlay {
static inline std::vector<Log> LOG_MSGS_;
static constexpr int LOG_RETENTION_TIME_ = 5;
static inline std::vector<std::function<void()>> OVERLAY_ELEMS_;
};

@ -14,7 +14,7 @@ class overlay_sink : public spdlog::sinks::base_sink<Mutex> {
protected:
void sink_it_(const spdlog::details::log_msg& msg) override
{
Overlay::ShowNotification(msg);
Overlay::AddLog(msg);
}
void flush_() override

Loading…
Cancel
Save