diff --git a/CMakeLists.txt b/CMakeLists.txt index 10ca7e23..374a8e23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -797,6 +797,7 @@ list(APPEND ue4poc_SOURCES "src/ue4poc-imgui/imgui_impl_dx11.cpp" "src/ue4poc-imgui/imgui_impl_dx12.cpp" "src/ue4poc-imgui/imgui_impl_win32.cpp" + "src/utility/ImGui.cpp" "src/ExceptionHandler.hpp" "src/Framework.hpp" "src/LicenseStrings.hpp" @@ -835,6 +836,7 @@ list(APPEND ue4poc_SOURCES "src/mods/vr/vtables/IXRTrackingSystemVTables.hpp" "src/ue4poc-imgui/font_robotomedium.hpp" "src/ue4poc-imgui/ue4poc_imconfig.hpp" + "src/utility/ImGui.hpp" "src/utility/Logging.hpp" "src/ue4poc-imgui/imgui_impl_dx11.h" "src/ue4poc-imgui/imgui_impl_dx12.h" diff --git a/src/mods/vr/OverlayComponent.cpp b/src/mods/vr/OverlayComponent.cpp index e697a316..c80508dc 100644 --- a/src/mods/vr/OverlayComponent.cpp +++ b/src/mods/vr/OverlayComponent.cpp @@ -3,6 +3,7 @@ #include "Framework.hpp" #include "../VR.hpp" +#include "../utility/ImGui.hpp" #include "OverlayComponent.hpp" @@ -101,9 +102,7 @@ void OverlayComponent::on_pre_imgui_frame() { // lerp towards the intersection point last_mouse_pos = glm::lerp(last_mouse_pos, glm::vec2{x, y}, delta_f * 10.0f); - if (last_mouse_pos.x >= window_pos.x && last_mouse_pos.x <= window_pos.x + window_size.x && - last_mouse_pos.y >= window_pos.y && last_mouse_pos.y <= window_pos.y + window_size.y) - { + if (imgui::is_point_intersecting_any(last_mouse_pos.x, last_mouse_pos.y)) { io.MousePos = ImVec2{ last_mouse_pos.x, last_mouse_pos.y diff --git a/src/utility/ImGui.cpp b/src/utility/ImGui.cpp new file mode 100644 index 00000000..35e11a24 --- /dev/null +++ b/src/utility/ImGui.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include + +#include "ImGui.hpp" + +namespace imgui { +bool is_point_intersecting_any(float x, float y) { + const ImGuiIO& io = ImGui::GetIO(); + const auto ctx = io.Ctx; + + if (ctx == nullptr) { + return false; + } + + for (int n = 0; n < ctx->Windows.Size; n++) { + const auto window = ctx->Windows[n]; + const auto pos = glm::vec2{window->Pos.x, window->Pos.y}; + const auto size = glm::vec2{window->Size.x, window->Size.y}; + const auto mx = pos + size; + + if (window->WasActive && window->Active) { + if (x >= window->Pos.x && x <= window->Pos.x + window->Size.x && + y >= window->Pos.y && y <= window->Pos.y + window->Size.y) + { + return true; + } + } + } + + return false; +} +} \ No newline at end of file diff --git a/src/utility/ImGui.hpp b/src/utility/ImGui.hpp new file mode 100644 index 00000000..69140020 --- /dev/null +++ b/src/utility/ImGui.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace imgui { +bool is_point_intersecting_any(float x, float y); +} \ No newline at end of file