ImGuiManager: Add 'Screen Margins' (i.e. safe zone)

This commit is contained in:
Stenzek 2024-10-20 13:14:18 +10:00
parent dbb2274d2d
commit 056b629837
No known key found for this signature in database
11 changed files with 78 additions and 16 deletions

View File

@ -3161,6 +3161,10 @@ void FullscreenUI::DrawInterfaceSettingsPage()
DrawIntSpinBoxSetting(bsi, FSUI_ICONSTR(ICON_FA_SEARCH, "OSD Scale"),
FSUI_CSTR("Determines how large the on-screen messages and monitor are."), "Display",
"OSDScale", 100, 25, 500, 1, "%d%%");
DrawFloatSpinBoxSetting(bsi, FSUI_ICONSTR(ICON_FA_RULER, "Screen Margins"),
FSUI_CSTR("Determines the margin between the edge of the screen and on-screen messages."),
"Display", "OSDMargin", ImGuiManager::DEFAULT_SCREEN_MARGIN, 0.0f, 100.0f, 1.0f, 1.0f,
"%.0fpx");
DrawToggleSetting(bsi, FSUI_ICONSTR(ICON_FA_LIST, "Show OSD Messages"),
FSUI_CSTR("Shows on-screen-display messages when events occur."), "Display", "ShowOSDMessages",
true);
@ -3170,7 +3174,7 @@ void FullscreenUI::DrawInterfaceSettingsPage()
"Shows the current emulation speed of the system in the top-right corner of the display as a percentage."),
"Display", "ShowSpeed", false);
DrawToggleSetting(
bsi, FSUI_ICONSTR(ICON_FA_RULER, "Show FPS"),
bsi, FSUI_ICONSTR(ICON_FA_STOPWATCH, "Show FPS"),
FSUI_CSTR("Shows the number of frames (or v-syncs) displayed per second by the system in the top-right "
"corner of the display."),
"Display", "ShowFPS", false);
@ -3178,7 +3182,7 @@ void FullscreenUI::DrawInterfaceSettingsPage()
FSUI_CSTR("Shows information about the emulated GPU in the top-right corner of the display."),
"Display", "ShowGPUStatistics", false);
DrawToggleSetting(
bsi, FSUI_ICONSTR(ICON_FA_STOPWATCH, "Show Latency Statistics"),
bsi, FSUI_ICONSTR(ICON_FA_COGS, "Show Latency Statistics"),
FSUI_CSTR("Shows information about input and audio latency in the top-right corner of the display."), "Display",
"ShowLatencyStatistics", false);
DrawToggleSetting(
@ -7452,7 +7456,7 @@ TRANSLATE_NOOP("FullscreenUI", "Change Selection");
TRANSLATE_NOOP("FullscreenUI", "Change View");
TRANSLATE_NOOP("FullscreenUI", "Changes settings for the application.");
TRANSLATE_NOOP("FullscreenUI", "Changes the aspect ratio used to display the console's output to the screen.");
TRANSLATE_NOOP("FullscreenUI", "Cheat List");
TRANSLATE_NOOP("FullscreenUI", "Cheats");
TRANSLATE_NOOP("FullscreenUI", "Chooses the backend to use for rendering the console/game visuals.");
TRANSLATE_NOOP("FullscreenUI", "Chooses the language used for UI elements.");
TRANSLATE_NOOP("FullscreenUI", "Clean Boot");
@ -7515,6 +7519,7 @@ TRANSLATE_NOOP("FullscreenUI", "Determines that field that the game list will be
TRANSLATE_NOOP("FullscreenUI", "Determines the amount of audio buffered before being pulled by the host API.");
TRANSLATE_NOOP("FullscreenUI", "Determines the emulated hardware type.");
TRANSLATE_NOOP("FullscreenUI", "Determines the format that screenshots will be saved/compressed with.");
TRANSLATE_NOOP("FullscreenUI", "Determines the margin between the edge of the screen and on-screen messages.");
TRANSLATE_NOOP("FullscreenUI", "Determines the position on the screen when black borders must be added.");
TRANSLATE_NOOP("FullscreenUI", "Determines the rotation of the simulated TV screen.");
TRANSLATE_NOOP("FullscreenUI", "Determines the size of screenshots created by DuckStation.");
@ -7572,8 +7577,10 @@ TRANSLATE_NOOP("FullscreenUI", "Enables an additional 6MB of RAM to obtain a tot
TRANSLATE_NOOP("FullscreenUI", "Enables an additional three controller slots on each port. Not supported in all games.");
TRANSLATE_NOOP("FullscreenUI", "Enables caching of guest textures, required for texture replacement.");
TRANSLATE_NOOP("FullscreenUI", "Enables dumping of textures to image files, which can be replaced. Not compatible with all games.");
TRANSLATE_NOOP("FullscreenUI", "Enables loading of cheats for this game from DuckStation's database.");
TRANSLATE_NOOP("FullscreenUI", "Enables loading of replacement textures. Not compatible with all games.");
TRANSLATE_NOOP("FullscreenUI", "Enables smooth scrolling of menus in Big Picture UI.");
TRANSLATE_NOOP("FullscreenUI", "Enables the cheats that are selected below.");
TRANSLATE_NOOP("FullscreenUI", "Enables the older, less accurate MDEC decoding routines. May be required for old replacement backgrounds to match/load.");
TRANSLATE_NOOP("FullscreenUI", "Enables the replacement of background textures in supported games.");
TRANSLATE_NOOP("FullscreenUI", "Encore Mode");
@ -7617,6 +7624,7 @@ TRANSLATE_NOOP("FullscreenUI", "GPU adapter will be applied after restarting.");
TRANSLATE_NOOP("FullscreenUI", "Game Grid");
TRANSLATE_NOOP("FullscreenUI", "Game List");
TRANSLATE_NOOP("FullscreenUI", "Game List Settings");
TRANSLATE_NOOP("FullscreenUI", "Game Patches");
TRANSLATE_NOOP("FullscreenUI", "Game Properties");
TRANSLATE_NOOP("FullscreenUI", "Game Quick Save");
TRANSLATE_NOOP("FullscreenUI", "Game Slot {0}##game_slot_{0}");
@ -7630,7 +7638,7 @@ TRANSLATE_NOOP("FullscreenUI", "Game settings initialized with global settings f
TRANSLATE_NOOP("FullscreenUI", "Game title copied to clipboard.");
TRANSLATE_NOOP("FullscreenUI", "Game type copied to clipboard.");
TRANSLATE_NOOP("FullscreenUI", "Game: {} ({})");
TRANSLATE_NOOP("FullscreenUI", "Genre: %s");
TRANSLATE_NOOP("FullscreenUI", "Genre: %.*s");
TRANSLATE_NOOP("FullscreenUI", "Geometry Tolerance");
TRANSLATE_NOOP("FullscreenUI", "GitHub Repository");
TRANSLATE_NOOP("FullscreenUI", "Global Slot {0} - {1}##global_slot_{0}");
@ -7655,6 +7663,7 @@ TRANSLATE_NOOP("FullscreenUI", "Input profile '{}' saved.");
TRANSLATE_NOOP("FullscreenUI", "Integration");
TRANSLATE_NOOP("FullscreenUI", "Interface Settings");
TRANSLATE_NOOP("FullscreenUI", "Internal Resolution");
TRANSLATE_NOOP("FullscreenUI", "Language: ");
TRANSLATE_NOOP("FullscreenUI", "Last Played");
TRANSLATE_NOOP("FullscreenUI", "Last Played: %s");
TRANSLATE_NOOP("FullscreenUI", "Latency Control");
@ -7667,6 +7676,7 @@ TRANSLATE_NOOP("FullscreenUI", "Leaderboards");
TRANSLATE_NOOP("FullscreenUI", "Leaderboards are not enabled.");
TRANSLATE_NOOP("FullscreenUI", "Line Detection");
TRANSLATE_NOOP("FullscreenUI", "List Settings");
TRANSLATE_NOOP("FullscreenUI", "Load Database Cheats");
TRANSLATE_NOOP("FullscreenUI", "Load Devices From Save States");
TRANSLATE_NOOP("FullscreenUI", "Load Global State");
TRANSLATE_NOOP("FullscreenUI", "Load Profile");
@ -7714,8 +7724,9 @@ TRANSLATE_NOOP("FullscreenUI", "Mute CD Audio");
TRANSLATE_NOOP("FullscreenUI", "Navigate");
TRANSLATE_NOOP("FullscreenUI", "No Binding");
TRANSLATE_NOOP("FullscreenUI", "No Game Selected");
TRANSLATE_NOOP("FullscreenUI", "No cheats found for {}.");
TRANSLATE_NOOP("FullscreenUI", "No cheats are available for this game.");
TRANSLATE_NOOP("FullscreenUI", "No input profiles available.");
TRANSLATE_NOOP("FullscreenUI", "No patches are available for this game.");
TRANSLATE_NOOP("FullscreenUI", "No resume save state found.");
TRANSLATE_NOOP("FullscreenUI", "No save present in this slot.");
TRANSLATE_NOOP("FullscreenUI", "No save states found.");
@ -7831,6 +7842,7 @@ TRANSLATE_NOOP("FullscreenUI", "Scales the dithering pattern with the internal r
TRANSLATE_NOOP("FullscreenUI", "Scaling");
TRANSLATE_NOOP("FullscreenUI", "Scan For New Games");
TRANSLATE_NOOP("FullscreenUI", "Scanning Subdirectories");
TRANSLATE_NOOP("FullscreenUI", "Screen Margins");
TRANSLATE_NOOP("FullscreenUI", "Screen Position");
TRANSLATE_NOOP("FullscreenUI", "Screen Rotation");
TRANSLATE_NOOP("FullscreenUI", "Screenshot Format");
@ -7957,6 +7969,7 @@ TRANSLATE_NOOP("FullscreenUI", "UI Language");
TRANSLATE_NOOP("FullscreenUI", "Uncompressed Size");
TRANSLATE_NOOP("FullscreenUI", "Uncompressed Size: %.2f MB");
TRANSLATE_NOOP("FullscreenUI", "Undo Load State");
TRANSLATE_NOOP("FullscreenUI", "Ungrouped");
TRANSLATE_NOOP("FullscreenUI", "Unknown");
TRANSLATE_NOOP("FullscreenUI", "Unknown File Size");
TRANSLATE_NOOP("FullscreenUI", "Unlimited");
@ -7982,6 +7995,8 @@ TRANSLATE_NOOP("FullscreenUI", "Value: {} | Default: {} | Minimum: {} | Maximum:
TRANSLATE_NOOP("FullscreenUI", "Version: %s");
TRANSLATE_NOOP("FullscreenUI", "Vertex Cache");
TRANSLATE_NOOP("FullscreenUI", "Vertical Sync (VSync)");
TRANSLATE_NOOP("FullscreenUI", "WARNING: Activating cheats can cause unpredictable behavior, crashing, soft-locks, or broken saved games.");
TRANSLATE_NOOP("FullscreenUI", "WARNING: Activating game patches can cause unpredictable behavior, crashing, soft-locks, or broken saved games.");
TRANSLATE_NOOP("FullscreenUI", "WARNING: Your game is still saving to the memory card. Continuing to {0} may IRREVERSIBLY DESTROY YOUR MEMORY CARD. We recommend resuming your game and waiting 5 seconds for it to finish saving.\n\nDo you want to {0} anyway?");
TRANSLATE_NOOP("FullscreenUI", "When enabled and logged in, DuckStation will scan for achievements on startup.");
TRANSLATE_NOOP("FullscreenUI", "When enabled, DuckStation will assume all achievements are locked and not send any unlock notifications to the server.");

View File

@ -339,7 +339,7 @@ bool Host::CreateGPUDevice(RenderAPI api, bool fullscreen, Error* error)
return false;
}
if (!ImGuiManager::Initialize(g_settings.display_osd_scale / 100.0f, &create_error))
if (!ImGuiManager::Initialize(g_settings.display_osd_scale / 100.0f, g_settings.display_osd_margin, &create_error))
{
ERROR_LOG("Failed to initialize ImGuiManager: {}", create_error.GetDescription());
Error::SetStringFmt(error, "Failed to initialize ImGuiManager: {}", create_error.GetDescription());

View File

@ -276,7 +276,7 @@ void ImGuiManager::RenderTextOverlays()
if (state != System::State::Shutdown)
{
const float scale = ImGuiManager::GetGlobalScale();
const float margin = std::ceil(10.0f * scale);
const float margin = std::ceil(ImGuiManager::GetScreenMargin() * scale);
const float spacing = std::ceil(5.0f * scale);
float position_y = margin;
DrawPerformanceOverlay(position_y, scale, margin, spacing);
@ -558,7 +558,7 @@ void ImGuiManager::DrawEnhancementsOverlay()
const float scale = ImGuiManager::GetGlobalScale();
const float shadow_offset = 1.0f * scale;
const float margin = 10.0f * scale;
const float margin = ImGuiManager::GetScreenMargin() * scale;
ImFont* font = ImGuiManager::GetFixedFont();
const float position_y = ImGui::GetIO().DisplaySize.y - margin - font->FontSize;
@ -686,7 +686,7 @@ void ImGuiManager::DrawInputsOverlay()
{
const float scale = ImGuiManager::GetGlobalScale();
const float shadow_offset = 1.0f * scale;
const float margin = 10.0f * scale;
const float margin = ImGuiManager::GetScreenMargin() * scale;
const float spacing = 5.0f * scale;
ImFont* font = ImGuiManager::GetOSDFont();

View File

@ -102,6 +102,7 @@ const MediaCaptureBackend Settings::DEFAULT_MEDIA_CAPTURE_BACKEND = MediaCapture
Settings::Settings()
{
display_osd_margin = ImGuiManager::DEFAULT_SCREEN_MARGIN;
controller_types[0] = DEFAULT_CONTROLLER_1_TYPE;
memory_card_types[0] = DEFAULT_MEMORY_CARD_1_TYPE;
for (u32 i = 1; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
@ -321,6 +322,7 @@ void Settings::Load(SettingsInterface& si, SettingsInterface& controller_si)
display_stretch_vertically = si.GetBoolValue("Display", "StretchVertically", false);
display_auto_resize_window = si.GetBoolValue("Display", "AutoResizeWindow", false);
display_osd_scale = si.GetFloatValue("Display", "OSDScale", DEFAULT_OSD_SCALE);
display_osd_margin = si.GetFloatValue("Display", "OSDMargin", ImGuiManager::DEFAULT_SCREEN_MARGIN);
save_state_compression = ParseSaveStateCompressionModeName(
si.GetStringValue("Main", "SaveStateCompression",
@ -608,6 +610,7 @@ void Settings::Save(SettingsInterface& si, bool ignore_base) const
si.SetBoolValue("Display", "ShowInputs", display_show_inputs);
si.SetBoolValue("Display", "ShowEnhancements", display_show_enhancements);
si.SetFloatValue("Display", "OSDScale", display_osd_scale);
si.SetFloatValue("Display", "OSDMargin", display_osd_margin);
}
si.SetBoolValue("Display", "StretchVertically", display_stretch_vertically);

View File

@ -169,6 +169,7 @@ struct Settings
bool display_auto_resize_window : 1 = false;
float display_pre_frame_sleep_buffer = DEFAULT_DISPLAY_PRE_FRAME_SLEEP_BUFFER;
float display_osd_scale = 100.0f;
float display_osd_margin = 0.0f;
float gpu_pgxp_tolerance = -1.0f;
float gpu_pgxp_depth_clear_threshold = DEFAULT_GPU_PGXP_DEPTH_THRESHOLD / GPU_PGXP_DEPTH_THRESHOLD_SCALE;

View File

@ -4601,6 +4601,8 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
{
if (g_settings.display_osd_scale != old_settings.display_osd_scale)
ImGuiManager::SetGlobalScale(g_settings.display_osd_scale / 100.0f);
if (g_settings.display_osd_margin != old_settings.display_osd_margin)
ImGuiManager::SetScreenMargin(g_settings.display_osd_margin);
}
if (g_settings.multitap_mode != old_settings.multitap_mode)

View File

@ -11,6 +11,7 @@
#include "core/gpu.h"
#include "core/settings.h"
#include "util/imgui_manager.h"
#include "util/ini_settings_interface.h"
#include "util/media_capture.h"
@ -182,6 +183,8 @@ GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* dialog, QWidget*
// OSD Tab
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.osdScale, "Display", "OSDScale", 100);
SettingWidgetBinder::BindWidgetToFloatSetting(sif, m_ui.osdMargin, "Display", "OSDMargin",
ImGuiManager::DEFAULT_SCREEN_MARGIN);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.showOSDMessages, "Display", "ShowOSDMessages", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.showFPS, "Display", "ShowFPS", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.showSpeed, "Display", "ShowSpeed", false);

View File

@ -633,7 +633,7 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QCheckBox" name="showFPS">
@ -721,6 +721,23 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Screen Margins:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="osdMargin">
<property name="suffix">
<string>px</string>
</property>
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
static constexpr ImWchar FA_ICON_RANGE[] = { 0xe06f,0xe06f,0xe086,0xe086,0xf002,0xf002,0xf005,0xf005,0xf007,0xf007,0xf00c,0xf00e,0xf011,0xf011,0xf013,0xf013,0xf017,0xf017,0xf019,0xf019,0xf01c,0xf01c,0xf021,0xf021,0xf023,0xf023,0xf025,0xf025,0xf02e,0xf02e,0xf030,0xf030,0xf03a,0xf03a,0xf03d,0xf03d,0xf04a,0xf04c,0xf050,0xf050,0xf05e,0xf05e,0xf062,0xf063,0xf067,0xf067,0xf071,0xf071,0xf075,0xf075,0xf077,0xf078,0xf07b,0xf07c,0xf084,0xf085,0xf091,0xf091,0xf0ac,0xf0ad,0xf0c3,0xf0c3,0xf0c5,0xf0c5,0xf0c7,0xf0c9,0xf0cb,0xf0cb,0xf0d0,0xf0d0,0xf0dc,0xf0dc,0xf0e2,0xf0e2,0xf0e7,0xf0e7,0xf0eb,0xf0eb,0xf0f1,0xf0f1,0xf0f3,0xf0f3,0xf0fe,0xf0fe,0xf110,0xf110,0xf119,0xf119,0xf11b,0xf11c,0xf140,0xf140,0xf14a,0xf14a,0xf15b,0xf15b,0xf15d,0xf15d,0xf191,0xf192,0xf1ab,0xf1ab,0xf1dd,0xf1de,0xf1e6,0xf1e6,0xf1eb,0xf1eb,0xf1f8,0xf1f8,0xf1fc,0xf1fc,0xf240,0xf240,0xf242,0xf242,0xf245,0xf245,0xf26c,0xf26c,0xf279,0xf279,0xf2d0,0xf2d0,0xf2db,0xf2db,0xf2f2,0xf2f2,0xf3fd,0xf3fd,0xf410,0xf410,0xf462,0xf462,0xf466,0xf466,0xf4ce,0xf4ce,0xf500,0xf500,0xf51f,0xf51f,0xf538,0xf538,0xf545,0xf545,0xf547,0xf548,0xf57a,0xf57a,0xf5a2,0xf5a2,0xf5aa,0xf5aa,0xf5e7,0xf5e7,0xf65d,0xf65e,0xf6cf,0xf6cf,0xf70c,0xf70c,0xf794,0xf794,0xf7a0,0xf7a0,0xf7c2,0xf7c2,0xf807,0xf807,0xf815,0xf815,0xf818,0xf818,0xf84c,0xf84c,0xf8cc,0xf8cc,0x0,0x0 };
static constexpr ImWchar FA_ICON_RANGE[] = { 0xe06f,0xe06f,0xe086,0xe086,0xf002,0xf002,0xf005,0xf005,0xf007,0xf007,0xf00c,0xf00e,0xf011,0xf011,0xf013,0xf013,0xf017,0xf017,0xf019,0xf019,0xf01c,0xf01c,0xf021,0xf021,0xf023,0xf023,0xf025,0xf025,0xf02e,0xf02e,0xf030,0xf030,0xf03a,0xf03a,0xf03d,0xf03d,0xf04a,0xf04c,0xf050,0xf050,0xf05e,0xf05e,0xf062,0xf063,0xf067,0xf067,0xf071,0xf071,0xf075,0xf075,0xf077,0xf078,0xf07b,0xf07c,0xf084,0xf085,0xf091,0xf091,0xf0ac,0xf0ad,0xf0c3,0xf0c3,0xf0c5,0xf0c5,0xf0c7,0xf0c9,0xf0cb,0xf0cb,0xf0d0,0xf0d0,0xf0dc,0xf0dc,0xf0e2,0xf0e2,0xf0e7,0xf0e7,0xf0eb,0xf0eb,0xf0f1,0xf0f1,0xf0f3,0xf0f3,0xf0fe,0xf0fe,0xf110,0xf110,0xf119,0xf119,0xf11b,0xf11c,0xf140,0xf140,0xf14a,0xf14a,0xf15b,0xf15b,0xf15d,0xf15d,0xf191,0xf192,0xf1ab,0xf1ab,0xf1dd,0xf1de,0xf1e6,0xf1e6,0xf1eb,0xf1eb,0xf1f8,0xf1f8,0xf1fc,0xf1fc,0xf240,0xf240,0xf242,0xf242,0xf245,0xf245,0xf26c,0xf26c,0xf279,0xf279,0xf2d0,0xf2d0,0xf2db,0xf2db,0xf2f2,0xf2f2,0xf3fd,0xf3fd,0xf410,0xf410,0xf462,0xf462,0xf466,0xf466,0xf4ce,0xf4ce,0xf500,0xf500,0xf51f,0xf51f,0xf538,0xf538,0xf545,0xf545,0xf547,0xf548,0xf5a2,0xf5a2,0xf5aa,0xf5aa,0xf5e7,0xf5e7,0xf65d,0xf65e,0xf6cf,0xf6cf,0xf70c,0xf70c,0xf794,0xf794,0xf7a0,0xf7a0,0xf7c2,0xf7c2,0xf807,0xf807,0xf815,0xf815,0xf818,0xf818,0xf84c,0xf84c,0xf8cc,0xf8cc,0x0,0x0 };
static constexpr ImWchar PF_ICON_RANGE[] = { 0x2196,0x2199,0x219e,0x21a1,0x21b0,0x21b3,0x21ba,0x21c3,0x21c7,0x21ca,0x21d0,0x21d4,0x21dc,0x21dd,0x21e0,0x21e3,0x21ed,0x21ee,0x21f7,0x21f8,0x21fa,0x21fb,0x227a,0x227f,0x2284,0x2284,0x2349,0x2349,0x235e,0x235e,0x2360,0x2361,0x2364,0x2366,0x23b2,0x23b4,0x23ce,0x23ce,0x23f4,0x23f7,0x2427,0x243a,0x243c,0x243e,0x2460,0x246b,0x248f,0x248f,0x24f5,0x24fd,0x24ff,0x24ff,0x2717,0x2717,0x278a,0x278e,0x27fc,0x27fc,0xe001,0xe001,0xff21,0xff3a,0x1f52b,0x1f52b,0x0,0x0 };

View File

@ -85,8 +85,9 @@ static void UpdateSoftwareCursorTexture(u32 index);
static void DestroySoftwareCursorTextures();
static void DrawSoftwareCursor(const SoftwareCursor& sc, const std::pair<float, float>& pos);
static float s_global_prescale = 1.0f; // before window scale
static float s_global_scale = 1.0f;
static float s_global_prescale = 0.0f; // before window scale
static float s_global_scale = 0.0f;
static float s_screen_margin = 0.0f;
static constexpr std::array<ImWchar, 4> s_ascii_font_range = {{0x20, 0x7F, 0x00, 0x00}};
@ -226,7 +227,7 @@ void ImGuiManager::SetShowOSDMessages(bool enable)
Host::ClearOSDMessages(false);
}
bool ImGuiManager::Initialize(float global_scale, Error* error)
bool ImGuiManager::Initialize(float global_scale, float screen_margin, Error* error)
{
if (!LoadFontData())
{
@ -237,6 +238,7 @@ bool ImGuiManager::Initialize(float global_scale, Error* error)
s_global_prescale = global_scale;
s_global_scale = std::max(
(g_gpu_device->HasMainSwapChain() ? g_gpu_device->GetMainSwapChain()->GetScale() : 1.0f) * global_scale, 1.0f);
s_screen_margin = std::max(screen_margin, 0.0f);
s_scale_changed = false;
s_imgui_context = ImGui::CreateContext();
@ -303,6 +305,11 @@ ImGuiContext* ImGuiManager::GetMainContext()
return s_imgui_context;
}
void ImGuiManager::SetScreenMargin(float margin)
{
s_screen_margin = std::max(margin, 0.0f);
}
float ImGuiManager::GetWindowWidth()
{
return s_window_width;
@ -885,7 +892,7 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time)
ImFont* const font = s_osd_font;
const float scale = s_global_scale;
const float spacing = std::ceil(6.0f * scale);
const float margin = std::ceil(11.0f * scale);
const float margin = std::ceil(s_screen_margin * scale);
const float padding = std::ceil(9.0f * scale);
const float rounding = std::ceil(6.0f * scale);
const float max_width = s_window_width - (margin + padding) * 2.0f;
@ -1022,6 +1029,11 @@ float ImGuiManager::GetGlobalScale()
return s_global_scale;
}
float ImGuiManager::GetScreenMargin()
{
return s_screen_margin;
}
ImFont* ImGuiManager::GetStandardFont()
{
return s_standard_font;

View File

@ -53,6 +53,9 @@ namespace ImGuiManager {
using WCharType = u32;
/// Default size for screen margins.
static constexpr float DEFAULT_SCREEN_MARGIN = 10.0f;
/// Sets the path to the font to use. Empty string means to use the default.
void SetFontPathAndRange(std::string path, std::vector<WCharType> range);
@ -71,7 +74,7 @@ bool IsShowingOSDMessages();
void SetShowOSDMessages(bool enable);
/// Initializes ImGui, creates fonts, etc.
bool Initialize(float global_scale, Error* error);
bool Initialize(float global_scale, float screen_margin, Error* error);
/// Frees all ImGui resources.
void Shutdown();
@ -79,6 +82,9 @@ void Shutdown();
/// Returns main ImGui context.
ImGuiContext* GetMainContext();
/// Sets the size of the screen margins, or "safe zone".
void SetScreenMargin(float margin);
/// Returns the size of the display window. Can be safely called from any thread.
float GetWindowWidth();
float GetWindowHeight();
@ -98,6 +104,9 @@ void RenderOSDMessages();
/// Returns the scale of all on-screen elements.
float GetGlobalScale();
/// Returns the screen margins, or "safe zone".
float GetScreenMargin();
/// Returns true if fullscreen fonts are present.
bool HasFullscreenFonts();