Merge pull request #238 from TwilitRealm/26-04-05-locked-aspect-ratio

Add "lock aspect ratio" setting
This commit is contained in:
TakaRikka
2026-04-07 16:50:36 -07:00
committed by GitHub
8 changed files with 74 additions and 19 deletions
+8
View File
@@ -12,4 +12,12 @@ namespace dusk {
extern AuroraStats lastFrameAuroraStats;
}
constexpr u32 defaultWindowWidth = 608;
constexpr u32 defaultWindowHeight = 448;
constexpr u32 defaultAspectRatioW = 19;
constexpr u32 defaultAspectRatioH = 14;
static_assert(defaultWindowWidth / defaultAspectRatioW == defaultWindowHeight / defaultAspectRatioH);
#endif // DUSK_DUSK_H
+1
View File
@@ -16,6 +16,7 @@ struct UserSettings {
// Video
ConfigVar<bool> enableFullscreen;
ConfigVar<bool> enableVsync;
ConfigVar<bool> lockAspectRatio;
} video;
struct {
+16 -4
View File
@@ -5,36 +5,48 @@
#include "imgui.h"
namespace dusk::config {
inline void ImGuiCheckbox(const char* title, ConfigVar<bool>& var) {
inline bool ImGuiCheckbox(const char* title, ConfigVar<bool>& var) {
bool copy = var.getValue();
if (ImGui::Checkbox(title, &copy)) {
var.setValue(copy);
Save();
return true;
}
return false;
}
static void ImGuiSliderFloat(const char* label, ConfigVar<float>& var, float v_min, float v_max, const char* format = "%.3f", ImGuiSliderFlags flags = 0) {
static bool ImGuiSliderFloat(const char* label, ConfigVar<float>& var, float v_min, float v_max, const char* format = "%.3f", ImGuiSliderFlags flags = 0) {
float val = var;
if (ImGui::SliderFloat(label, &val, v_min, v_max, format, flags)) {
var.setValue(val);
Save();
return true;
}
return false;
}
static void ImGuiSliderInt(const char* label, ConfigVar<int>& var, int v_min, int v_max, const char* format = "%d", ImGuiSliderFlags flags = 0) {
static bool ImGuiSliderInt(const char* label, ConfigVar<int>& var, int v_min, int v_max, const char* format = "%d", ImGuiSliderFlags flags = 0) {
int val = var;
if (ImGui::SliderInt(label, &val, v_min, v_max, format, flags)) {
var.setValue(val);
Save();
return true;
}
return false;
}
static void ImGuiMenuItem(const char* label, const char* shortcut, ConfigVar<bool>& p_selected, bool enabled = true) {
static bool ImGuiMenuItem(const char* label, const char* shortcut, ConfigVar<bool>& p_selected, bool enabled = true) {
bool copy = p_selected.getValue();
if (ImGui::MenuItem(label, shortcut, &copy, enabled)) {
p_selected.setValue(copy);
Save();
return true;
}
return false;
}
}
+15 -3
View File
@@ -7,7 +7,6 @@
#include "fmt/format.h"
#include "imgui.h"
#include "aurora/gfx.h"
#include <imgui_internal.h>
#include "ImGuiConsole.hpp"
@@ -16,6 +15,7 @@
#include "dusk/config.hpp"
#include "dusk/settings.h"
#include "dusk/audio/DuskAudioSystem.h"
#include "dusk/dusk.h"
#if _WIN32
#define NOMINMAX
@@ -179,14 +179,26 @@ namespace dusk {
ImGuiConsole::ImGuiConsole() {}
void ImGuiConsole::InitSettings() {
bool lockAspect = getSettings().video.lockAspectRatio;
if (lockAspect) {
VILockAspectRatio(defaultAspectRatioW, defaultAspectRatioH);
} else {
VIUnlockAspectRatio();
}
dusk::audio::SetMasterVolume(getSettings().audio.masterVolume / 100.0f);
dusk::audio::SetEnableReverb(getSettings().audio.enableReverb);
}
void ImGuiConsole::UpdateSettings() {
dusk::audio::SetMasterVolume(dusk::getSettings().audio.masterVolume / 100.0f);
dusk::audio::SetEnableReverb(dusk::getSettings().audio.enableReverb);
getTransientSettings().skipFrameRateLimit = getSettings().game.enableTurboKeybind && ImGui::IsKeyDown(ImGuiKey_Tab);
}
void ImGuiConsole::PreDraw() {
if (!m_isLaunchInitialized) {
InitSettings();
m_toasts.emplace_back("Press F1 to toggle menu"s, 5.f);
m_isLaunchInitialized = true;
}
+1
View File
@@ -14,6 +14,7 @@ namespace dusk {
class ImGuiConsole {
public:
ImGuiConsole();
void InitSettings();
void UpdateSettings();
void PreDraw();
void PostDraw();
+29 -10
View File
@@ -7,8 +7,9 @@
#include <imgui_internal.h>
#include "JSystem/JUtility/JUTGamePad.h"
#include "dusk/audio/DuskDsp.hpp"
#include "dusk/audio/DuskAudioSystem.h"
#include "dusk/audio/DuskDsp.hpp"
#include "dusk/dusk.h"
#include "dusk/hotkeys.h"
#include "dusk/settings.h"
#include "m_Do/m_Do_controller_pad.h"
@@ -38,13 +39,6 @@ namespace dusk {
ToggleFullscreen();
}
bool vsync = getSettings().video.enableVsync;
if (ImGui::Checkbox("Enable Vsync", &vsync)) {
getSettings().video.enableVsync.setValue(vsync);
aurora_enable_vsync(vsync);
config::Save();
}
if (ImGui::MenuItem("Default Window Size")) {
getSettings().video.enableFullscreen.setValue(false);
VISetWindowFullscreen(false);
@@ -52,13 +46,38 @@ namespace dusk {
VICenterWindow();
}
bool vsync = getSettings().video.enableVsync;
if (ImGui::Checkbox("Enable Vsync", &vsync)) {
getSettings().video.enableVsync.setValue(vsync);
aurora_enable_vsync(vsync);
config::Save();
}
bool lockAspect = getSettings().video.lockAspectRatio;
if (ImGui::Checkbox("Force 4:3 Aspect Ratio", &lockAspect)) {
getSettings().video.lockAspectRatio.setValue(lockAspect);
if (lockAspect) {
VILockAspectRatio(defaultAspectRatioW, defaultAspectRatioH);
} else {
VIUnlockAspectRatio();
}
config::Save();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Audio")) {
ImGui::Text("Master Volume");
config::ImGuiSliderInt("##masterVolume", getSettings().audio.masterVolume, 0, 100);
config::ImGuiCheckbox("Enable Reverb", getSettings().audio.enableReverb);
if (config::ImGuiSliderInt("##masterVolume", getSettings().audio.masterVolume, 0, 100)) {
dusk::audio::SetMasterVolume(getSettings().audio.masterVolume / 100.0f);
}
if (config::ImGuiCheckbox("Enable Reverb", getSettings().audio.enableReverb)) {
dusk::audio::SetEnableReverb(getSettings().audio.enableReverb);
}
/*
// TODO: Implement additional settings
ImGui::Text("Main Music Volume");
+2
View File
@@ -7,6 +7,7 @@ UserSettings g_userSettings = {
.video = {
.enableFullscreen {"video.enableFullscreen", false},
.enableVsync {"video.enableVsync", true},
.lockAspectRatio {"video.lockAspectRatio", false},
},
.audio = {
@@ -65,6 +66,7 @@ void registerSettings() {
// Video
Register(g_userSettings.video.enableFullscreen);
Register(g_userSettings.video.enableVsync);
Register(g_userSettings.video.lockAspectRatio);
// Audio
Register(g_userSettings.audio.masterVolume);
+2 -2
View File
@@ -325,8 +325,8 @@ int game_main(int argc, char* argv[]) {
config.startFullscreen = dusk::getSettings().video.enableFullscreen;
config.windowPosX = -1;
config.windowPosY = -1;
config.windowWidth = FB_WIDTH * 2;
config.windowHeight = FB_HEIGHT * 2;
config.windowWidth = defaultWindowWidth * 2;
config.windowHeight = defaultWindowHeight * 2;
config.desiredBackend = ParseAuroraBackend(parsed_arg_options["backend"].as<std::string>());
config.logCallback = &aurora_log_callback;
config.logLevel = (AuroraLogLevel)parsed_arg_options["log-level"].as<uint8_t>();