Skip to content

Commit 29de0dc

Browse files
committed
Make imgui menus scale independently from window size
1 parent 2d380ef commit 29de0dc

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

include/pch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ struct ModSettings {
472472
std::atomic<float> playerHeightOffset = 0.0f;
473473
std::atomic_bool leftHanded = false;
474474
std::atomic_bool uiFollowsGaze = true;
475-
std::atomic_bool cropFlatTo16x9 = false;
475+
std::atomic_bool cropFlatTo16x9 = true;
476476

477477
// advanced settings
478478
std::atomic_bool enableDebugOverlay = false;

src/hooking/settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static void Settings_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry,
3131
if (sscanf(line, "EnableDebugOverlay=%d", &i_val) == 1) { s->enableDebugOverlay.store(i_val); return; }
3232
if (sscanf(line, "BuggyAngularVelocity=%d", &i_val) == 1) { s->buggyAngularVelocity.store((AngularVelocityFixerMode)i_val); return; }
3333
if (sscanf(line, "PerformanceOverlay=%d", &i_val) == 1) { s->performanceOverlay.store(i_val); return; }
34+
if (sscanf(line, "PerformanceOverlayFrequency=%d", &i_val) == 1) { s->performanceOverlayFrequency.store(i_val); return; }
3435
}
3536

3637
static void Settings_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) {
@@ -49,6 +50,7 @@ static void Settings_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
4950
buf->appendf("EnableDebugOverlay=%d\n", (int)s.enableDebugOverlay.load());
5051
buf->appendf("BuggyAngularVelocity=%d\n", (int)s.buggyAngularVelocity.load());
5152
buf->appendf("PerformanceOverlay=%d\n", (int)s.performanceOverlay.load());
53+
buf->appendf("PerformanceOverlayFrequency=%d\n", (int)s.performanceOverlayFrequency.load());
5254
buf->appendf("\n");
5355
}
5456

src/rendering/vulkan_imgui.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ RND_Renderer::ImGuiOverlay::~ImGuiOverlay() {
260260
}
261261

262262
void RND_Renderer::ImGuiOverlay::Update() {
263-
ImGui::GetIO().FontGlobalScale = 0.9f;
263+
ImGui::GetIO().FontGlobalScale = 1.0f;
264264

265265
POINT p;
266266
GetCursorPos(&p);
@@ -284,14 +284,22 @@ void RND_Renderer::ImGuiOverlay::Update() {
284284
ImVec2 physicalRes = ImVec2(renderPhysicalWidth, renderPhysicalHeight);
285285
ImVec2 framebufferRes = ImVec2((float)m_outputRes.width, (float)m_outputRes.height);
286286

287-
ImGui::GetIO().DisplaySize = physicalRes;
287+
// calculate a virtual resolution to keep UI size consistent
288+
float uiScaleFactor = (float)renderPhysicalHeight / 1080.0f;
289+
if (uiScaleFactor < 0.1f) uiScaleFactor = 0.1f;
290+
291+
uiScaleFactor *= 2.0f;
292+
293+
ImVec2 logicalRes = ImVec2(physicalRes.x / uiScaleFactor, physicalRes.y / uiScaleFactor);
294+
295+
ImGui::GetIO().DisplaySize = logicalRes;
288296

289297
// calculate the black bars
290298
uint32_t blackBarWidth = (nonCenteredWindowWidth - renderPhysicalWidth) / 2;
291299
uint32_t blackBarHeight = (nonCenteredWindowHeight - renderPhysicalHeight) / 2;
292300

293301
// adjust the framebuffer scale
294-
ImGui::GetIO().DisplayFramebufferScale = framebufferRes / physicalRes;
302+
ImGui::GetIO().DisplayFramebufferScale = framebufferRes / logicalRes;
295303

296304
// the actual window is centered, so add offsets to both x and y on both sides
297305
p.x = p.x - blackBarWidth;
@@ -303,7 +311,7 @@ void RND_Renderer::ImGuiOverlay::Update() {
303311
ImGui::GetIO().AddFocusEvent(isWindowFocused);
304312
if (isWindowFocused) {
305313
// update mouse state depending on if the window is focused
306-
ImGui::GetIO().AddMousePosEvent((float)p.x, (float)p.y);
314+
ImGui::GetIO().AddMousePosEvent((float)p.x / uiScaleFactor, (float)p.y / uiScaleFactor);
307315

308316
ImGui::GetIO().AddMouseButtonEvent(0, GetAsyncKeyState(VK_LBUTTON) & 0x8000);
309317
ImGui::GetIO().AddMouseButtonEvent(1, GetAsyncKeyState(VK_RBUTTON) & 0x8000);
@@ -525,7 +533,7 @@ void RND_Renderer::ImGuiOverlay::DrawHelpMenu() {
525533
ImGui::SetNextWindowSize(windowWidth, ImGuiCond_Always);
526534
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
527535

528-
if (ImGui::Begin("BetterVR Settings & Help##Settings", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
536+
if (ImGui::Begin("BetterVR Settings & Help | Long-Press Right Thumbstick To Exit Or Press B##Settings", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
529537
bool changed = false;
530538

531539
if (ImGui::BeginTabBar("HelpMenuTabs")) {
@@ -611,7 +619,7 @@ void RND_Renderer::ImGuiOverlay::DrawHelpMenu() {
611619
if (performanceOverlay >= 1) {
612620
static const int freqOptions[] = { 30, 60, 72, 80, 90, 120, 144 };
613621
int currentFreq = (int)settings.performanceOverlayFrequency.load();
614-
int freqIdx = 1; // Default to 60
622+
int freqIdx = 5; // Default to 90
615623
for (int i = 0; i < std::size(freqOptions); i++) {
616624
if (freqOptions[i] == currentFreq) {
617625
freqIdx = i;

0 commit comments

Comments
 (0)