2021-10-23 00:08:38 +00:00
|
|
|
/*
|
2022-01-06 23:38:21 +00:00
|
|
|
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
|
2021-10-23 00:08:38 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2021-10-22 10:17:46 +00:00
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
2021-10-22 16:07:08 +00:00
|
|
|
#define IMGUI_USER_CONFIG "imconfig.h"
|
|
|
|
#include "imgui-SFML.h"
|
|
|
|
#include "imgui.h"
|
|
|
|
|
2021-10-28 10:28:20 +00:00
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
2021-10-22 10:17:46 +00:00
|
|
|
class Overlay {
|
|
|
|
public:
|
2022-01-07 00:36:21 +00:00
|
|
|
Overlay(sf::RenderWindow& window, std::function<void()> on_close, std::function<void()> trigger_state_change, bool force_enable = false);
|
2021-10-22 10:17:46 +00:00
|
|
|
|
|
|
|
void setEnabled(bool enabled);
|
2021-10-22 13:40:37 +00:00
|
|
|
bool isEnabled() const;
|
2021-10-22 10:17:46 +00:00
|
|
|
bool toggle();
|
|
|
|
void update();
|
|
|
|
static void ProcessEvent(sf::Event evnt);
|
|
|
|
static void Shutdown();
|
2021-10-22 14:35:35 +00:00
|
|
|
static void AddLog(const spdlog::details::log_msg& msg);
|
|
|
|
|
2022-04-08 11:11:20 +00:00
|
|
|
static int AddOverlayElem(const std::function<void(bool window_has_focus)>& elem_fn);
|
2021-10-30 00:25:11 +00:00
|
|
|
static void RemoveOverlayElem(int id);
|
2021-10-22 14:35:35 +00:00
|
|
|
|
2021-10-22 10:17:46 +00:00
|
|
|
private:
|
|
|
|
sf::RenderWindow& window_;
|
|
|
|
sf::Clock update_clock_;
|
|
|
|
bool enabled_ = true;
|
|
|
|
std::function<void()> on_close_;
|
2022-01-07 00:36:21 +00:00
|
|
|
std::function<void()> trigger_state_change_;
|
2021-11-12 12:46:03 +00:00
|
|
|
void showLogs();
|
2022-01-07 00:36:21 +00:00
|
|
|
bool closeOverlayButton() const;
|
2021-10-22 14:35:35 +00:00
|
|
|
[[nodiscard]] bool closeButton() const;
|
2022-09-20 12:29:47 +00:00
|
|
|
void saveSettingsButton() const;
|
2021-10-28 11:38:16 +00:00
|
|
|
bool force_enable_ = false;
|
2021-11-12 12:46:03 +00:00
|
|
|
bool log_expanded_ = true;
|
2022-09-22 20:10:37 +00:00
|
|
|
sf::Clock time_since_start_clock_;
|
2021-10-22 13:40:37 +00:00
|
|
|
|
|
|
|
struct Log {
|
|
|
|
std::chrono::system_clock::time_point time;
|
|
|
|
spdlog::level::level_enum level;
|
|
|
|
std::string payload;
|
|
|
|
};
|
|
|
|
static inline std::vector<Log> LOG_MSGS_;
|
|
|
|
static constexpr int LOG_RETENTION_TIME_ = 5;
|
2022-09-22 20:10:37 +00:00
|
|
|
static constexpr int HIDE_NORMAL_LOGS_AFTER_S = 20;
|
2021-10-22 13:40:37 +00:00
|
|
|
|
2021-10-30 00:25:11 +00:00
|
|
|
static inline int overlay_element_id_ = 0;
|
2022-04-08 11:11:20 +00:00
|
|
|
static inline std::map<int, std::function<void(bool window_has_focus)>> OVERLAY_ELEMS_;
|
2021-10-22 14:35:35 +00:00
|
|
|
|
2021-10-23 15:17:05 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
std::string config_file_name_;
|
|
|
|
#endif
|
2021-10-22 10:17:46 +00:00
|
|
|
};
|