mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-02 16:17:09 +02:00
[qt] fix aspect ratio enum mismatch for framebuffer (#2792)
the framebuffer:
```c++
enum class AspectRatio {
Default,
R4_3,
R21_9,
R16_10,
StretchToWindow,
};
```
the actual enum
```c++
ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch);
```
If someone were to add a new setting it would likely cause catastrophe.
1280/720 = 16/9
Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2792
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
df26fe2cac
commit
d0206c35fb
4 changed files with 48 additions and 87 deletions
|
|
@ -14,69 +14,54 @@
|
||||||
namespace Layout {
|
namespace Layout {
|
||||||
|
|
||||||
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
|
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
|
||||||
template <class T>
|
static Common::Rectangle<u32> MaxRectangle(Common::Rectangle<u32> window_area, float screen_aspect_ratio) noexcept {
|
||||||
static Common::Rectangle<T> MaxRectangle(Common::Rectangle<T> window_area,
|
const float scale = (std::min)(float(window_area.GetWidth()), float(window_area.GetHeight()) / screen_aspect_ratio);
|
||||||
float screen_aspect_ratio) {
|
return Common::Rectangle<u32>{0, 0, u32(std::round(scale)), u32(std::round(scale * screen_aspect_ratio))};
|
||||||
const float scale = (std::min)(static_cast<float>(window_area.GetWidth()),
|
|
||||||
static_cast<float>(window_area.GetHeight()) / screen_aspect_ratio);
|
|
||||||
return Common::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)),
|
|
||||||
static_cast<T>(std::round(scale * screen_aspect_ratio))};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout DefaultFrameLayout(u32 width, u32 height) {
|
/// @brief Factory method for constructing a default FramebufferLayout
|
||||||
ASSERT(width > 0);
|
/// @param width Window framebuffer width in pixels
|
||||||
ASSERT(height > 0);
|
/// @param height Window framebuffer height in pixels
|
||||||
// The drawing code needs at least somewhat valid values for both screens
|
/// @return Newly created FramebufferLayout object with default screen regions initialized
|
||||||
// so just calculate them both even if the other isn't showing.
|
FramebufferLayout DefaultFrameLayout(u32 width, u32 height) noexcept {
|
||||||
FramebufferLayout res{
|
ASSERT(width > 0 && height > 0);
|
||||||
.width = width,
|
auto const window_aspect_ratio = float(height) / float(width);
|
||||||
.height = height,
|
auto const emulation_aspect_ratio = EmulationAspectRatio(Settings::values.aspect_ratio.GetValue(), window_aspect_ratio);
|
||||||
.screen = {},
|
Common::Rectangle<u32> const screen_window_area{0, 0, width, height};
|
||||||
.is_srgb = false,
|
auto screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
|
||||||
};
|
|
||||||
|
|
||||||
const float window_aspect_ratio = static_cast<float>(height) / static_cast<float>(width);
|
|
||||||
const float emulation_aspect_ratio = EmulationAspectRatio(
|
|
||||||
static_cast<AspectRatio>(Settings::values.aspect_ratio.GetValue()), window_aspect_ratio);
|
|
||||||
|
|
||||||
const Common::Rectangle<u32> screen_window_area{0, 0, width, height};
|
|
||||||
Common::Rectangle<u32> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
|
|
||||||
|
|
||||||
if (window_aspect_ratio < emulation_aspect_ratio) {
|
if (window_aspect_ratio < emulation_aspect_ratio) {
|
||||||
screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
|
screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
|
||||||
} else {
|
} else {
|
||||||
screen = screen.TranslateY((height - screen.GetHeight()) / 2);
|
screen = screen.TranslateY((height - screen.GetHeight()) / 2);
|
||||||
}
|
}
|
||||||
|
// The drawing code needs at least somewhat valid values for both screens
|
||||||
res.screen = screen;
|
// so just calculate them both even if the other isn't showing.
|
||||||
return res;
|
return FramebufferLayout{
|
||||||
|
.width = width,
|
||||||
|
.height = height,
|
||||||
|
.screen = screen,
|
||||||
|
.is_srgb = false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout FrameLayoutFromResolutionScale(f32 res_scale) {
|
/// @brief Convenience method to determine emulation aspect ratio
|
||||||
const bool is_docked = Settings::IsDockedMode();
|
/// @param aspect Represents the index of aspect ratio stored in Settings::values.aspect_ratio
|
||||||
const u32 screen_width = is_docked ? ScreenDocked::Width : ScreenUndocked::Width;
|
/// @param window_aspect_ratio Current window aspect ratio
|
||||||
const u32 screen_height = is_docked ? ScreenDocked::Height : ScreenUndocked::Height;
|
/// @return Emulation render window aspect ratio
|
||||||
|
float EmulationAspectRatio(Settings::AspectRatio aspect, float window_aspect_ratio) noexcept {
|
||||||
const u32 width = static_cast<u32>(static_cast<f32>(screen_width) * res_scale);
|
|
||||||
const u32 height = static_cast<u32>(static_cast<f32>(screen_height) * res_scale);
|
|
||||||
|
|
||||||
return DefaultFrameLayout(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
float EmulationAspectRatio(AspectRatio aspect, float window_aspect_ratio) {
|
|
||||||
switch (aspect) {
|
switch (aspect) {
|
||||||
case AspectRatio::Default:
|
case Settings::AspectRatio::R16_9:
|
||||||
return static_cast<float>(ScreenUndocked::Height) / ScreenUndocked::Width;
|
return 9.0f / 16.0f;
|
||||||
case AspectRatio::R4_3:
|
case Settings::AspectRatio::R4_3:
|
||||||
return 3.0f / 4.0f;
|
return 3.0f / 4.0f;
|
||||||
case AspectRatio::R21_9:
|
case Settings::AspectRatio::R21_9:
|
||||||
return 9.0f / 21.0f;
|
return 9.0f / 21.0f;
|
||||||
case AspectRatio::R16_10:
|
case Settings::AspectRatio::R16_10:
|
||||||
return 10.0f / 16.0f;
|
return 10.0f / 16.0f;
|
||||||
case AspectRatio::StretchToWindow:
|
case Settings::AspectRatio::Stretch:
|
||||||
return window_aspect_ratio;
|
return window_aspect_ratio;
|
||||||
default:
|
default:
|
||||||
return static_cast<float>(ScreenUndocked::Height) / ScreenUndocked::Width;
|
return float(ScreenUndocked::Height) / ScreenUndocked::Width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
|
@ -6,6 +9,10 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
|
|
||||||
|
namespace Settings {
|
||||||
|
enum class AspectRatio : u32;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Layout {
|
namespace Layout {
|
||||||
|
|
||||||
namespace MinimumSize {
|
namespace MinimumSize {
|
||||||
|
|
@ -23,15 +30,7 @@ constexpr u32 Width = 1920;
|
||||||
constexpr u32 Height = 1080;
|
constexpr u32 Height = 1080;
|
||||||
} // namespace ScreenDocked
|
} // namespace ScreenDocked
|
||||||
|
|
||||||
enum class AspectRatio {
|
/// @brief Describes the layout of the window framebuffer
|
||||||
Default,
|
|
||||||
R4_3,
|
|
||||||
R21_9,
|
|
||||||
R16_10,
|
|
||||||
StretchToWindow,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Describes the layout of the window framebuffer
|
|
||||||
struct FramebufferLayout {
|
struct FramebufferLayout {
|
||||||
u32 width{ScreenUndocked::Width};
|
u32 width{ScreenUndocked::Width};
|
||||||
u32 height{ScreenUndocked::Height};
|
u32 height{ScreenUndocked::Height};
|
||||||
|
|
@ -39,26 +38,7 @@ struct FramebufferLayout {
|
||||||
bool is_srgb{};
|
bool is_srgb{};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
FramebufferLayout DefaultFrameLayout(u32 width, u32 height) noexcept;
|
||||||
* Factory method for constructing a default FramebufferLayout
|
float EmulationAspectRatio(Settings::AspectRatio aspect, float window_aspect_ratio) noexcept;
|
||||||
* @param width Window framebuffer width in pixels
|
|
||||||
* @param height Window framebuffer height in pixels
|
|
||||||
* @return Newly created FramebufferLayout object with default screen regions initialized
|
|
||||||
*/
|
|
||||||
FramebufferLayout DefaultFrameLayout(u32 width, u32 height);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience method to get frame layout by resolution scale
|
|
||||||
* @param res_scale resolution scale factor
|
|
||||||
*/
|
|
||||||
FramebufferLayout FrameLayoutFromResolutionScale(f32 res_scale);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience method to determine emulation aspect ratio
|
|
||||||
* @param aspect Represents the index of aspect ratio stored in Settings::values.aspect_ratio
|
|
||||||
* @param window_aspect_ratio Current window aspect ratio
|
|
||||||
* @return Emulation render window aspect ratio
|
|
||||||
*/
|
|
||||||
float EmulationAspectRatio(AspectRatio aspect, float window_aspect_ratio);
|
|
||||||
|
|
||||||
} // namespace Layout
|
} // namespace Layout
|
||||||
|
|
|
||||||
|
|
@ -3422,9 +3422,7 @@ void GMainWindow::ToggleWindowMode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMainWindow::ResetWindowSize(u32 width, u32 height) {
|
void GMainWindow::ResetWindowSize(u32 width, u32 height) {
|
||||||
const auto aspect_ratio = Layout::EmulationAspectRatio(
|
const auto aspect_ratio = Layout::EmulationAspectRatio(Settings::values.aspect_ratio.GetValue(), float(height) / width);
|
||||||
static_cast<Layout::AspectRatio>(Settings::values.aspect_ratio.GetValue()),
|
|
||||||
static_cast<float>(height) / width);
|
|
||||||
if (!ui->action_Single_Window_Mode->isChecked()) {
|
if (!ui->action_Single_Window_Mode->isChecked()) {
|
||||||
render_window->resize(height / aspect_ratio, height);
|
render_window->resize(height / aspect_ratio, height);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -235,9 +235,9 @@ int main(int argc, char** argv) {
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
int arg = getopt_long(argc, argv, "g:fhvp::c:u:d:", long_options, &option_index);
|
int arg = getopt_long(argc, argv, "g:fhvp::c:u:d:", long_options, &option_index);
|
||||||
if (arg != -1) {
|
if (arg != -1) {
|
||||||
switch (static_cast<char>(arg)) {
|
switch (char(arg)) {
|
||||||
case 'd':
|
case 'd':
|
||||||
override_gdb_port = static_cast<uint16_t>(atoi(optarg));
|
override_gdb_port = uint16_t(atoi(optarg));
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
config_path = optarg;
|
config_path = optarg;
|
||||||
|
|
@ -249,11 +249,9 @@ int main(int argc, char** argv) {
|
||||||
case 'h':
|
case 'h':
|
||||||
PrintHelp(argv[0]);
|
PrintHelp(argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
case 'g': {
|
case 'g':
|
||||||
const std::string str_arg(optarg);
|
filepath = std::string(optarg);
|
||||||
filepath = str_arg;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case 'm': {
|
case 'm': {
|
||||||
use_multiplayer = true;
|
use_multiplayer = true;
|
||||||
const std::string str_arg(optarg);
|
const std::string str_arg(optarg);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue