Refactor: Add "window_has_focus" bool to overlay funcs

pull/169/head
Peter Repukat 2 years ago
parent d5feb390df
commit 94d106cde4

@ -135,12 +135,12 @@ void HidHide::hideDevices(const std::filesystem::path& steam_path)
void HidHide::disableHidHide() void HidHide::disableHidHide()
{ {
openCtrlDevice(); openCtrlDevice();
if (getActive()) { if (getActive()) {
setActive(false); setActive(false);
spdlog::info("Un-hid Gaming Devices"); spdlog::info("Un-hid Gaming Devices");
} }
closeCtrlDevice(); closeCtrlDevice();
} }
void HidHide::UnPatchValveHooks() void HidHide::UnPatchValveHooks()
@ -257,8 +257,7 @@ void HidHide::UnPatchHook(BYTE* address, const std::string& bytes)
void HidHide::enableOverlayElement() void HidHide::enableOverlayElement()
{ {
Overlay::AddOverlayElem([this]() { Overlay::AddOverlayElem([this](bool window_has_focus) {
if (overlay_elem_clock_.getElapsedTime().asSeconds() > OVERLAY_ELEM_REFRESH_INTERVAL_S_) {
openCtrlDevice(); openCtrlDevice();
bool hidehide_state_store = hidhide_active_; bool hidehide_state_store = hidhide_active_;
if (hidhide_active_) { if (hidhide_active_) {

@ -53,7 +53,7 @@ void InputRedirector::run()
max_controller_count_ = Settings::controller.maxControllers; max_controller_count_ = Settings::controller.maxControllers;
use_real_vid_pid_ = Settings::devices.realDeviceIds; use_real_vid_pid_ = Settings::devices.realDeviceIds;
#ifdef _WIN32 #ifdef _WIN32
Overlay::AddOverlayElem([this]() { Overlay::AddOverlayElem([this](bool window_has_focus) {
ImGui::SetNextWindowPos({650, 450}, ImGuiCond_FirstUseEver); ImGui::SetNextWindowPos({650, 450}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints({400, 270}, {1000, 1000}); ImGui::SetNextWindowSizeConstraints({400, 270}, {1000, 1000});
ImGui::Begin("Controller Emulation"); ImGui::Begin("Controller Emulation");

@ -153,7 +153,7 @@ void Overlay::update()
if (enabled_ || force_enable_) { if (enabled_ || force_enable_) {
window_.clear(sf::Color(0, 0, 0, 128)); // make window slightly dim screen with overlay window_.clear(sf::Color(0, 0, 0, 128)); // make window slightly dim screen with overlay
std::ranges::for_each(OVERLAY_ELEMS_, [this](const auto& elem) { std::ranges::for_each(OVERLAY_ELEMS_, [this](const auto& elem) {
elem.second(); elem.second(window_.hasFocus());
}); });
// ImGui::ShowDemoWindow(); // ImGui::ShowDemoWindow();
@ -183,7 +183,7 @@ void Overlay::AddLog(const spdlog::details::log_msg& msg)
LOG_MSGS_.push_back({.time = msg.time, .level = msg.level, .payload = msg.payload.data()}); LOG_MSGS_.push_back({.time = msg.time, .level = msg.level, .payload = msg.payload.data()});
} }
int Overlay::AddOverlayElem(const std::function<void()>& elem_fn) int Overlay::AddOverlayElem(const std::function<void(bool window_has_focus)>& elem_fn)
{ {
OVERLAY_ELEMS_.insert({overlay_element_id_, elem_fn}); OVERLAY_ELEMS_.insert({overlay_element_id_, elem_fn});
// keep this non confusing, but longer... // keep this non confusing, but longer...

@ -38,7 +38,7 @@ class Overlay {
static void Shutdown(); static void Shutdown();
static void AddLog(const spdlog::details::log_msg& msg); static void AddLog(const spdlog::details::log_msg& msg);
static int AddOverlayElem(const std::function<void()>& elem_fn); static int AddOverlayElem(const std::function<void(bool window_has_focus)>& elem_fn);
static void RemoveOverlayElem(int id); static void RemoveOverlayElem(int id);
private: private:
@ -62,10 +62,9 @@ class Overlay {
static constexpr int LOG_RETENTION_TIME_ = 5; static constexpr int LOG_RETENTION_TIME_ = 5;
static inline int overlay_element_id_ = 0; static inline int overlay_element_id_ = 0;
static inline std::map<int, std::function<void()>> OVERLAY_ELEMS_; static inline std::map<int, std::function<void(bool window_has_focus)>> OVERLAY_ELEMS_;
#ifdef _WIN32 #ifdef _WIN32
std::string config_file_name_; std::string config_file_name_;
#endif #endif
}; };

@ -7,14 +7,13 @@
namespace ProcessPriority { namespace ProcessPriority {
static int current_priority = HIGH_PRIORITY_CLASS; static int current_priority = HIGH_PRIORITY_CLASS;
inline void init() inline void init()
{ {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
Overlay::AddOverlayElem([]() { Overlay::AddOverlayElem([](bool window_has_focus) {
ImGui::SetNextWindowPos({913, 418}, ImGuiCond_FirstUseEver); ImGui::SetNextWindowPos({913, 418}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints({170, 325}, {1000, 1000}); ImGui::SetNextWindowSizeConstraints({170, 325}, {1000, 1000});
ImGui::Begin("Process Priority"); ImGui::Begin("Process Priority");
@ -45,7 +44,6 @@ inline void init()
} }
ImGui::End(); ImGui::End();
}); });
} }
} } // namespace ProcessPriority

@ -50,7 +50,7 @@ TargetWindow::TargetWindow(
{ {
createWindow(Settings::window.windowMode); createWindow(Settings::window.windowMode);
Overlay::AddOverlayElem([this]() { Overlay::AddOverlayElem([this](bool window_has_focus) {
bool windowed_copy = windowed_; bool windowed_copy = windowed_;
ImGui::SetNextWindowPos({window_.getSize().x - 370.f, 100}, ImGuiCond_FirstUseEver); ImGui::SetNextWindowPos({window_.getSize().x - 370.f, 100}, ImGuiCond_FirstUseEver);
ImGui::Begin("Window mode"); ImGui::Begin("Window mode");

@ -34,7 +34,7 @@ inline DWORD ExplorerPid()
return 0; return 0;
} }
} } // namespace internal
inline void EnableUwpOverlay() inline void EnableUwpOverlay()
{ {
@ -60,7 +60,7 @@ inline void EnableUwpOverlay()
inline void AddUwpOverlayOvWidget() inline void AddUwpOverlayOvWidget()
{ {
Overlay::AddOverlayElem([]() { Overlay::AddOverlayElem([](bool window_has_focus) {
ImGui::SetNextWindowPos({1200, 250}, ImGuiCond_FirstUseEver); ImGui::SetNextWindowPos({1200, 250}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints({170, 325}, {1000, 1000}); ImGui::SetNextWindowSizeConstraints({170, 325}, {1000, 1000});
ImGui::SetNextWindowCollapsed(true, ImGuiCond_FirstUseEver); ImGui::SetNextWindowCollapsed(true, ImGuiCond_FirstUseEver);
@ -80,4 +80,4 @@ inline void AddUwpOverlayOvWidget()
}); });
} }
} } // namespace UWPOverlayEnabler
Loading…
Cancel
Save