Skip to content

Commit

Permalink
Merge pull request #2907 from CeruleanSky/DisAlignSet
Browse files Browse the repository at this point in the history
Expose Display Host Alignment as a setting in ini
  • Loading branch information
stenzek committed Oct 13, 2022
2 parents 0cd3316 + 553d580 commit c9cba5e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/core/host_display.cpp
Expand Up @@ -233,18 +233,18 @@ void HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, float*
}
if (out_top_padding)
{
switch (m_display_alignment)
switch (g_settings.display_alignment)
{
case Alignment::RightOrBottom:
case DisplayAlignment::RightOrBottom:
*out_top_padding = std::max<float>(static_cast<float>(window_height) - (display_height * scale), 0.0f);
break;

case Alignment::Center:
case DisplayAlignment::Center:
*out_top_padding =
std::max<float>((static_cast<float>(window_height) - (display_height * scale)) / 2.0f, 0.0f);
break;

case Alignment::LeftOrTop:
case DisplayAlignment::LeftOrTop:
default:
*out_top_padding = 0.0f;
break;
Expand All @@ -260,18 +260,18 @@ void HostDisplay::CalculateDrawRect(s32 window_width, s32 window_height, float*

if (out_left_padding)
{
switch (m_display_alignment)
switch (g_settings.display_alignment)
{
case Alignment::RightOrBottom:
case DisplayAlignment::RightOrBottom:
*out_left_padding = std::max<float>(static_cast<float>(window_width) - (display_width * scale), 0.0f);
break;

case Alignment::Center:
case DisplayAlignment::Center:
*out_left_padding =
std::max<float>((static_cast<float>(window_width) - (display_width * scale)) / 2.0f, 0.0f);
break;

case Alignment::LeftOrTop:
case DisplayAlignment::LeftOrTop:
default:
*out_left_padding = 0.0f;
break;
Expand Down
34 changes: 34 additions & 0 deletions src/core/settings.cpp
Expand Up @@ -242,6 +242,10 @@ void Settings::Load(SettingsInterface& si)
std::clamp<int>(si.GetIntValue("Display", "CustomAspectRatioNumerator", 4), 1, std::numeric_limits<u16>::max()));
display_aspect_ratio_custom_denominator = static_cast<u16>(
std::clamp<int>(si.GetIntValue("Display", "CustomAspectRatioDenominator", 3), 1, std::numeric_limits<u16>::max()));
display_alignment =
ParseDisplayAlignment(
si.GetStringValue("Display", "Alignment", GetDisplayAlignmentName(DEFAULT_DISPLAY_ALIGNMENT)).c_str())
.value_or(DEFAULT_DISPLAY_ALIGNMENT);
display_force_4_3_for_24bit = si.GetBoolValue("Display", "Force4_3For24Bit", false);
display_active_start_offset = static_cast<s16>(si.GetIntValue("Display", "ActiveStartOffset", 0));
display_active_end_offset = static_cast<s16>(si.GetIntValue("Display", "ActiveEndOffset", 0));
Expand Down Expand Up @@ -454,6 +458,7 @@ void Settings::Save(SettingsInterface& si) const
si.SetIntValue("Display", "LineEndOffset", display_line_end_offset);
si.SetBoolValue("Display", "Force4_3For24Bit", display_force_4_3_for_24bit);
si.SetStringValue("Display", "AspectRatio", GetDisplayAspectRatioName(display_aspect_ratio));
si.SetStringValue("Display", "Alignment", GetDisplayAlignmentName(display_alignment));
si.SetIntValue("Display", "CustomAspectRatioNumerator", display_aspect_ratio_custom_numerator);
si.GetIntValue("Display", "CustomAspectRatioDenominator", display_aspect_ratio_custom_denominator);
si.SetBoolValue("Display", "LinearFiltering", display_linear_filtering);
Expand Down Expand Up @@ -1046,6 +1051,35 @@ float Settings::GetDisplayAspectRatioValue() const
}
}

static std::array<const char*, 3> s_display_alignment_names = {{"LeftOrTop", "Center", "RightOrBottom"}};
static std::array<const char*, 3> s_display_alignment_display_names = {
{TRANSLATABLE("DisplayAlignment", "LeftOrTop"), TRANSLATABLE("DisplayAlignment", "Center"),
TRANSLATABLE("DisplayAlignment", "RightOrBottom")}};

std::optional<DisplayAlignment> Settings::ParseDisplayAlignment(const char* str)
{
int index = 0;
for (const char* name : s_display_alignment_names)
{
if (StringUtil::Strcasecmp(name, str) == 0)
return static_cast<DisplayAlignment>(index);

index++;
}

return std::nullopt;
}

const char* Settings::GetDisplayAlignmentName(DisplayAlignment alignment)
{
return s_display_alignment_names[static_cast<int>(alignment)];
}

const char* Settings::GetDisplayAlignmentDisplayName(DisplayAlignment alignment)
{
return s_display_alignment_display_names[static_cast<int>(alignment)];
}

static constexpr const char* s_audio_backend_names[] = {
"Null",
#ifdef WITH_CUBEB
Expand Down
6 changes: 6 additions & 0 deletions src/core/settings.h
Expand Up @@ -115,6 +115,7 @@ struct Settings
bool gpu_pgxp_depth_buffer = false;
DisplayCropMode display_crop_mode = DEFAULT_DISPLAY_CROP_MODE;
DisplayAspectRatio display_aspect_ratio = DEFAULT_DISPLAY_ASPECT_RATIO;
DisplayAlignment display_alignment = DEFAULT_DISPLAY_ALIGNMENT;
u16 display_aspect_ratio_custom_numerator = 0;
u16 display_aspect_ratio_custom_denominator = 0;
s16 display_active_start_offset = 0;
Expand Down Expand Up @@ -359,6 +360,10 @@ struct Settings
static std::optional<DisplayAspectRatio> ParseDisplayAspectRatio(const char* str);
static const char* GetDisplayAspectRatioName(DisplayAspectRatio ar);

static std::optional<DisplayAlignment> ParseDisplayAlignment(const char* str);
static const char* GetDisplayAlignmentName(DisplayAlignment alignment);
static const char* GetDisplayAlignmentDisplayName(DisplayAlignment alignment);

static std::optional<AudioBackend> ParseAudioBackend(const char* str);
static const char* GetAudioBackendName(AudioBackend backend);
static const char* GetAudioBackendDisplayName(AudioBackend backend);
Expand Down Expand Up @@ -416,6 +421,7 @@ struct Settings

static constexpr DisplayCropMode DEFAULT_DISPLAY_CROP_MODE = DisplayCropMode::Overscan;
static constexpr DisplayAspectRatio DEFAULT_DISPLAY_ASPECT_RATIO = DisplayAspectRatio::Auto;
static constexpr DisplayAlignment DEFAULT_DISPLAY_ALIGNMENT = DisplayAlignment::Center;
static constexpr float DEFAULT_OSD_SCALE = 100.0f;

static constexpr u8 DEFAULT_CDROM_READAHEAD_SECTORS = 8;
Expand Down
1 change: 1 addition & 0 deletions src/core/system.cpp
Expand Up @@ -3179,6 +3179,7 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
g_settings.gpu_downsample_mode != old_settings.gpu_downsample_mode ||
g_settings.display_crop_mode != old_settings.display_crop_mode ||
g_settings.display_aspect_ratio != old_settings.display_aspect_ratio ||
g_settings.display_alignment != old_settings.display_alignment ||
g_settings.gpu_pgxp_enable != old_settings.gpu_pgxp_enable ||
g_settings.gpu_pgxp_texture_correction != old_settings.gpu_pgxp_texture_correction ||
g_settings.gpu_pgxp_color_correction != old_settings.gpu_pgxp_color_correction ||
Expand Down
7 changes: 7 additions & 0 deletions src/core/types.h
Expand Up @@ -109,6 +109,13 @@ enum class DisplayAspectRatio : u8
Count
};

enum class DisplayAlignment
{
LeftOrTop,
Center,
RightOrBottom
};

enum class AudioBackend : u8
{
Null,
Expand Down

0 comments on commit c9cba5e

Please sign in to comment.