From 5cc91dc78bcbc90253210a2e385868d66214537f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 10 Sep 2020 12:07:30 +1000 Subject: [PATCH] HostDisplay: Add alignment setting --- src/core/host_display.cpp | 35 +++++++++++++++++++++++++++++++++-- src/core/host_display.h | 9 +++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/core/host_display.cpp b/src/core/host_display.cpp index a6b8cc241..5b81ccb4c 100644 --- a/src/core/host_display.cpp +++ b/src/core/host_display.cpp @@ -94,7 +94,22 @@ void HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, s32* ou *out_left_padding = 0; } if (out_top_padding) - *out_top_padding = std::max((window_height - static_cast(display_height * scale)) / 2, 0); + { + switch (m_display_alignment) + { + case Alignment::LeftOrTop: + *out_top_padding = 0; + break; + + case Alignment::Center: + *out_top_padding = std::max((window_height - static_cast(display_height * scale)) / 2, 0); + break; + + case Alignment::RightOrBottom: + *out_top_padding = std::max(window_height - static_cast(display_height * scale), 0); + break; + } + } } else { @@ -104,7 +119,23 @@ void HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, s32* ou scale = std::max(std::floor(scale), 1.0f); if (out_left_padding) - *out_left_padding = std::max((window_width - static_cast(display_width * scale)) / 2, 0); + { + switch (m_display_alignment) + { + case Alignment::LeftOrTop: + *out_left_padding = 0; + break; + + case Alignment::Center: + *out_left_padding = std::max((window_width - static_cast(display_width * scale)) / 2, 0); + break; + + case Alignment::RightOrBottom: + *out_left_padding = std::max(window_width - static_cast(display_width * scale), 0); + break; + } + } + if (out_top_padding) { if (m_display_integer_scaling) diff --git a/src/core/host_display.h b/src/core/host_display.h index d6ab3bca7..58fc3d7ee 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -31,6 +31,13 @@ public: OpenGLES }; + enum class Alignment + { + LeftOrTop, + Center, + RightOrBottom + }; + virtual ~HostDisplay(); ALWAYS_INLINE s32 GetWindowWidth() const { return static_cast(m_window_info.surface_width); } @@ -122,6 +129,7 @@ public: void SetDisplayLinearFiltering(bool enabled) { m_display_linear_filtering = enabled; } void SetDisplayTopMargin(s32 height) { m_display_top_margin = height; } void SetDisplayIntegerScaling(bool enabled) { m_display_integer_scaling = enabled; } + void SetDisplayAlignment(Alignment alignment) { m_display_alignment = alignment; } /// Sets the software cursor to the specified texture. Ownership of the texture is transferred. void SetSoftwareCursor(std::unique_ptr texture, float scale = 1.0f); @@ -187,6 +195,7 @@ protected: s32 m_display_texture_view_height = 0; s32 m_display_top_margin = 0; + Alignment m_display_alignment = Alignment::Center; std::unique_ptr m_cursor_texture; float m_cursor_texture_scale = 1.0f;