Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Menu/OverlayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "HomePageRenderer.h"
#include "ThemeManager.h"

#include <dxgi.h>
#include <imgui.h>
#include <imgui_impl_dx11.h>
#include <imgui_impl_win32.h>
Expand Down Expand Up @@ -117,8 +118,16 @@ void OverlayRenderer::InitializeImGuiFrame(Menu& menu)
// Start the Dear ImGui frame
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

DXGI_SWAP_CHAIN_DESC desc{};
globals::d3d::swapChain->GetDesc(&desc);

Util::UpdateImGuiInput(
desc.OutputWindow,
static_cast<float>(desc.BufferDesc.Width),
static_cast<float>(desc.BufferDesc.Height));

ImGui::NewFrame();
ThemeManager::SetupImGuiStyle(menu);
}

Expand Down
42 changes: 42 additions & 0 deletions src/Utils/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <DirectXTex.h>
#include <d3d11.h>
#include <dinput.h>
#include <dxgi.h>
#include <imgui.h>
#include <imgui_internal.h>
#include <wrl/client.h>
Expand Down Expand Up @@ -45,6 +46,47 @@

namespace Util
{
static ImVec2 g_screenScaleRatio = { 1.0f, 1.0f };
static ImVec2 g_displaySize = { 0.0f, 0.0f };

static int g_lastWindowWidth = 0;
static int g_lastWindowHeight = 0;

void RefreshScreenScale(HWND hwnd, float bufferWidth, float bufferHeight)
{
RECT rect{};
if (!GetClientRect(hwnd, &rect) || rect.right <= 0 || rect.bottom <= 0)
return;

if (rect.right == g_lastWindowWidth && rect.bottom == g_lastWindowHeight)
return;

g_displaySize.x = bufferWidth;
g_displaySize.y = bufferHeight;

g_screenScaleRatio.x = bufferWidth / static_cast<float>(rect.right);
g_screenScaleRatio.y = bufferHeight / static_cast<float>(rect.bottom);

g_lastWindowWidth = rect.right;
g_lastWindowHeight = rect.bottom;
}

void UpdateImGuiInput(HWND hwnd, float bufferWidth, float bufferHeight)
{
RefreshScreenScale(hwnd, bufferWidth, bufferHeight);

auto& io = ImGui::GetIO();
io.DisplaySize = g_displaySize;

POINT cursorPos{};
if (GetCursorPos(&cursorPos) &&
ScreenToClient(hwnd, &cursorPos)) {
io.AddMousePosEvent(
static_cast<float>(cursorPos.x) * g_screenScaleRatio.x,
static_cast<float>(cursorPos.y) * g_screenScaleRatio.y);
}
}

HoverTooltipWrapper::HoverTooltipWrapper() :
previousFont(nullptr)
{
Expand Down
1 change: 1 addition & 0 deletions src/Utils/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Feature;

namespace Util
{
void UpdateImGuiInput(HWND hwnd, float bufferWidth, float bufferHeight);
/**
* Represents a single line and its color for any colored text rendering (tooltips, legends, etc.).
*/
Expand Down
Loading