mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-02-17 03:15:39 +00:00
CommonHostInterface: Add resize window to scale functions
This commit is contained in:
parent
0726ad1275
commit
e4d2b7331b
|
@ -92,6 +92,8 @@ public:
|
||||||
virtual void SetVSync(bool enabled) = 0;
|
virtual void SetVSync(bool enabled) = 0;
|
||||||
|
|
||||||
const s32 GetDisplayTopMargin() const { return m_display_top_margin; }
|
const s32 GetDisplayTopMargin() const { return m_display_top_margin; }
|
||||||
|
const s32 GetDisplayWidth() const { return m_display_width; }
|
||||||
|
const s32 GetDisplayHeight() const { return m_display_height; }
|
||||||
const float GetDisplayAspectRatio() const { return m_display_aspect_ratio; }
|
const float GetDisplayAspectRatio() const { return m_display_aspect_ratio; }
|
||||||
|
|
||||||
void SetDisplayMaxFPS(float max_fps);
|
void SetDisplayMaxFPS(float max_fps);
|
||||||
|
|
|
@ -442,6 +442,33 @@ float SDLHostInterface::GetFloatSettingValue(const char* section, const char* ke
|
||||||
return m_settings_interface->GetFloatValue(section, key, default_value);
|
return m_settings_interface->GetFloatValue(section, key, default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SDLHostInterface::RequestRenderWindowSize(s32 new_window_width, s32 new_window_height)
|
||||||
|
{
|
||||||
|
if (new_window_width <= 0 || new_window_height <= 0 || m_fullscreen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// use imgui scale as the dpr
|
||||||
|
const float dpi_scale = ImGui::GetIO().DisplayFramebufferScale.x;
|
||||||
|
const s32 scaled_width =
|
||||||
|
std::max<s32>(static_cast<s32>(std::ceil(static_cast<float>(new_window_width) * dpi_scale)), 1);
|
||||||
|
const s32 scaled_height = std::max<s32>(
|
||||||
|
static_cast<s32>(std::ceil(static_cast<float>(new_window_height) * dpi_scale)) + m_display->GetDisplayTopMargin(),
|
||||||
|
1);
|
||||||
|
|
||||||
|
SDL_SetWindowSize(m_window, scaled_width, scaled_height);
|
||||||
|
|
||||||
|
s32 window_width, window_height;
|
||||||
|
SDL_GetWindowSize(m_window, &window_width, &window_height);
|
||||||
|
m_display->ResizeRenderWindow(window_width, window_height);
|
||||||
|
|
||||||
|
UpdateFramebufferScale();
|
||||||
|
|
||||||
|
if (!System::IsShutdown())
|
||||||
|
g_gpu->UpdateResolutionScale();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void SDLHostInterface::LoadSettings()
|
void SDLHostInterface::LoadSettings()
|
||||||
{
|
{
|
||||||
// Settings need to be loaded prior to creating the window for OpenGL bits.
|
// Settings need to be loaded prior to creating the window for OpenGL bits.
|
||||||
|
@ -911,6 +938,18 @@ void SDLHostInterface::DrawQuickSettingsMenu()
|
||||||
if (ImGui::MenuItem("Fullscreen", nullptr, &fullscreen))
|
if (ImGui::MenuItem("Fullscreen", nullptr, &fullscreen))
|
||||||
RunLater([this, fullscreen] { SetFullscreen(fullscreen); });
|
RunLater([this, fullscreen] { SetFullscreen(fullscreen); });
|
||||||
|
|
||||||
|
if (ImGui::BeginMenu("Resize to Game", System::IsValid()))
|
||||||
|
{
|
||||||
|
static constexpr auto scales = make_array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||||
|
for (const u32 scale : scales)
|
||||||
|
{
|
||||||
|
if (ImGui::MenuItem(TinyString::FromFormat("%ux Scale", scale)))
|
||||||
|
RunLater([this, scale]() { RequestRenderWindowScale(static_cast<float>(scale)); });
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
settings_changed |= ImGui::MenuItem("VSync", nullptr, &m_settings_copy.video_sync_enabled);
|
settings_changed |= ImGui::MenuItem("VSync", nullptr, &m_settings_copy.video_sync_enabled);
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
int GetIntSettingValue(const char* section, const char* key, int default_value = 0) override;
|
int GetIntSettingValue(const char* section, const char* key, int default_value = 0) override;
|
||||||
float GetFloatSettingValue(const char* section, const char* key, float default_value = 0.0f) override;
|
float GetFloatSettingValue(const char* section, const char* key, float default_value = 0.0f) override;
|
||||||
|
|
||||||
|
bool RequestRenderWindowSize(s32 new_window_width, s32 new_window_height) override;
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -2534,6 +2534,28 @@ bool CommonHostInterface::ParseFullscreenMode(const std::string_view& mode, u32*
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CommonHostInterface::RequestRenderWindowSize(s32 new_window_width, s32 new_window_height)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommonHostInterface::RequestRenderWindowScale(float scale)
|
||||||
|
{
|
||||||
|
if (!System::IsValid() || scale == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const float y_scale =
|
||||||
|
(static_cast<float>(m_display->GetDisplayWidth()) / static_cast<float>(m_display->GetDisplayHeight())) /
|
||||||
|
m_display->GetDisplayAspectRatio();
|
||||||
|
|
||||||
|
const u32 requested_width =
|
||||||
|
std::max<u32>(static_cast<u32>(std::ceil(static_cast<float>(m_display->GetDisplayWidth()) * scale)), 1);
|
||||||
|
const u32 requested_height =
|
||||||
|
std::max<u32>(static_cast<u32>(std::ceil(static_cast<float>(m_display->GetDisplayHeight()) * y_scale * scale)), 1);
|
||||||
|
|
||||||
|
return RequestRenderWindowSize(static_cast<s32>(requested_width), static_cast<s32>(requested_height));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WITH_DISCORD_PRESENCE
|
#ifdef WITH_DISCORD_PRESENCE
|
||||||
|
|
||||||
void CommonHostInterface::SetDiscordPresenceEnabled(bool enabled)
|
void CommonHostInterface::SetDiscordPresenceEnabled(bool enabled)
|
||||||
|
|
|
@ -183,6 +183,12 @@ public:
|
||||||
/// Returns true if fast forwarding is currently active.
|
/// Returns true if fast forwarding is currently active.
|
||||||
bool IsFastForwardEnabled() const { return m_fast_forward_enabled; }
|
bool IsFastForwardEnabled() const { return m_fast_forward_enabled; }
|
||||||
|
|
||||||
|
/// Requests the specified size for the render window. Not guaranteed to succeed (e.g. if in fullscreen).
|
||||||
|
virtual bool RequestRenderWindowSize(s32 new_window_width, s32 new_window_height);
|
||||||
|
|
||||||
|
/// Requests a resize to a multiple of the render window size.
|
||||||
|
bool RequestRenderWindowScale(float scale);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum : u32
|
enum : u32
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue