From 2ae5d4462f11a045f2355a74376baa46cde5d3a2 Mon Sep 17 00:00:00 2001 From: Emmanuel AYME Date: Sun, 4 Jan 2026 21:28:36 +0100 Subject: [PATCH] Add Hotkeys and OSD manager libs --- libs/HotkeysManager.cpp | 32 ++++++++++++++++++++++++++++++++ libs/OSDManager.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 libs/HotkeysManager.cpp create mode 100644 libs/OSDManager.cpp diff --git a/libs/HotkeysManager.cpp b/libs/HotkeysManager.cpp new file mode 100644 index 0000000..fe22034 --- /dev/null +++ b/libs/HotkeysManager.cpp @@ -0,0 +1,32 @@ +#include "HotkeysManager.h" +#include + +struct Hotkey { + int vk; + Modifier mods; + std::function callback; + bool wasPressed = false; +}; + +static std::vector g_hotkeys; + +static bool IsModifierDown(reshade::api::effect_runtime* rt, Modifier m) { + if ((int)m & (int)Modifier::Alt && !rt->is_key_down(VK_MENU)) return false; + if ((int)m & (int)Modifier::Ctrl && !rt->is_key_down(VK_CONTROL)) return false; + if ((int)m & (int)Modifier::Shift && !rt->is_key_down(VK_SHIFT)) return false; + return true; +} + +void RegisterHotkey(int vk, Modifier mods, std::function callback) { + g_hotkeys.push_back({ vk, mods, std::move(callback) }); +} + +void ProcessHotkeys(reshade::api::effect_runtime* runtime) { + for (auto& hotkey : g_hotkeys) { + bool pressed = IsModifierDown(runtime, hotkey.mods) && runtime->is_key_down(hotkey.vk); + + if (pressed && !hotkey.wasPressed) hotkey.callback(); + + hotkey.wasPressed = pressed; + } +} diff --git a/libs/OSDManager.cpp b/libs/OSDManager.cpp new file mode 100644 index 0000000..6bbfe9a --- /dev/null +++ b/libs/OSDManager.cpp @@ -0,0 +1,33 @@ +#include "OSDManager.h" + +static float g_timer = 0.0f; +static OSDUpdateFn g_onUpdate; +static OSDEndFn g_onEnd; + +void ShowOSD(float duration, OSDUpdateFn onUpdate, OSDEndFn onEnd) { + g_timer = duration; + g_onUpdate = std::move(onUpdate); + g_onEnd = std::move(onEnd); +} + +void UpdateOSD(reshade::api::effect_runtime* runtime, float deltaTime) { + if (g_timer <= 0.0f) return; + + g_timer -= deltaTime; + + if (g_onUpdate) g_onUpdate(runtime); + + if (g_timer <= 0.0f) { + if (g_onEnd) g_onEnd(runtime); + + g_onUpdate = nullptr; + g_onEnd = nullptr; + } +} + +void ResetAllUniformVariables(reshade::api::effect_runtime* runtime, const char* effect_name) { + runtime->enumerate_uniform_variables(effect_name, [runtime](reshade::api::effect_runtime* rt, reshade::api::effect_uniform_variable OSDvar) { + runtime->reset_uniform_value(OSDvar); + }); +} +