HostDisplay: Add alignment setting

This commit is contained in:
Connor McLaughlin 2020-09-10 12:07:30 +10:00
parent 3b4ba17356
commit 5cc91dc78b
2 changed files with 42 additions and 2 deletions

View file

@ -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<s32>((window_height - static_cast<s32>(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<s32>((window_height - static_cast<s32>(display_height * scale)) / 2, 0);
break;
case Alignment::RightOrBottom:
*out_top_padding = std::max<s32>(window_height - static_cast<s32>(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<s32>((window_width - static_cast<s32>(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<s32>((window_width - static_cast<s32>(display_width * scale)) / 2, 0);
break;
case Alignment::RightOrBottom:
*out_left_padding = std::max<s32>(window_width - static_cast<s32>(display_width * scale), 0);
break;
}
}
if (out_top_padding)
{
if (m_display_integer_scaling)

View file

@ -31,6 +31,13 @@ public:
OpenGLES
};
enum class Alignment
{
LeftOrTop,
Center,
RightOrBottom
};
virtual ~HostDisplay();
ALWAYS_INLINE s32 GetWindowWidth() const { return static_cast<s32>(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<HostDisplayTexture> 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<HostDisplayTexture> m_cursor_texture;
float m_cursor_texture_scale = 1.0f;