Gtk: Add UI option to configure size, indicators.

This commit is contained in:
BearOso 2023-04-25 17:20:24 -05:00
parent 909d899512
commit 945cd27841
8 changed files with 125 additions and 26 deletions

View File

@ -67,7 +67,7 @@ static void ImGui_DrawPressedKeys(int spacing)
draw_list->AddRectFilled(ImVec2(x, y), draw_list->AddRectFilled(ImVec2(x, y),
ImVec2(x + box_width, y + box_height), ImVec2(x + box_width, y + box_height),
settings.box_color, settings.box_color,
3.0f); spacing / 2);
draw_list->AddText(ImVec2(x + spacing, y + spacing), settings.text_color, string); draw_list->AddText(ImVec2(x + spacing, y + spacing), settings.text_color, string);
@ -85,7 +85,7 @@ static void ImGui_DrawPressedKeys(int spacing)
draw_list->AddRectFilled(ImVec2(x, y), draw_list->AddRectFilled(ImVec2(x, y),
ImVec2(x + box_width, y + box_height), ImVec2(x + box_width, y + box_height),
settings.box_color, settings.box_color,
spacing / 3); spacing / 2);
x += spacing; x += spacing;
y += spacing; y += spacing;
@ -132,12 +132,15 @@ static void ImGui_DrawTextOverlay(const char *text,
draw_list->AddRectFilled(ImVec2(x, y), draw_list->AddRectFilled(ImVec2(x, y),
ImVec2(x + box_size.x, y + box_size.y), ImVec2(x + box_size.x, y + box_size.y),
settings.box_color, settings.box_color,
settings.spacing / 3); settings.spacing / 2);
draw_list->AddText(ImVec2(x + padding, y + padding), settings.text_color, text); draw_list->AddText(ImVec2(x + padding, y + padding), settings.text_color, text);
} }
bool S9xImGuiDraw(int width, int height) bool S9xImGuiDraw(int width, int height)
{ {
if (Memory.ROMFilename.empty())
return false;
if (!ImGui::GetCurrentContext()) if (!ImGui::GetCurrentContext())
return false; return false;
@ -147,15 +150,6 @@ bool S9xImGuiDraw(int width, int height)
ImGui::GetIO().DisplayFramebufferScale.y = 1.0; ImGui::GetIO().DisplayFramebufferScale.y = 1.0;
ImGui::NewFrame(); ImGui::NewFrame();
if (!GFX.InfoString.empty())
ImGui_DrawTextOverlay(GFX.InfoString.c_str(),
settings.spacing,
height - settings.spacing,
settings.spacing,
ImGui::DrawTextAlignment::BEGIN,
ImGui::DrawTextAlignment::END,
width - settings.spacing * 4);
if (Settings.DisplayTime) if (Settings.DisplayTime)
{ {
char string[256]; char string[256];
@ -206,20 +200,32 @@ bool S9xImGuiDraw(int width, int height)
ImGui_DrawPressedKeys(settings.spacing / 2); ImGui_DrawPressedKeys(settings.spacing / 2);
} }
if (Settings.Paused || Settings.ForcedPause) if (Settings.DisplayIndicators)
{ {
ImGui_DrawTextOverlay("❚❚", if (Settings.Paused || Settings.ForcedPause)
settings.spacing, {
settings.spacing, ImGui_DrawTextOverlay("❚❚",
settings.spacing); settings.spacing,
settings.spacing,
settings.spacing);
}
else if (Settings.TurboMode)
{
ImGui_DrawTextOverlay("▶▶",
settings.spacing,
settings.spacing,
settings.spacing);
}
} }
else if (Settings.TurboMode)
{ if (!GFX.InfoString.empty())
ImGui_DrawTextOverlay("▶▶", ImGui_DrawTextOverlay(GFX.InfoString.c_str(),
settings.spacing, settings.spacing,
height - settings.spacing,
settings.spacing, settings.spacing,
settings.spacing); ImGui::DrawTextAlignment::BEGIN,
} ImGui::DrawTextAlignment::END,
width - settings.spacing * 4);
ImGui::Render(); ImGui::Render();

View File

@ -96,6 +96,7 @@ int Snes9xConfig::load_defaults()
allow_xv = false; allow_xv = false;
allow_xrandr = false; allow_xrandr = false;
auto_vrr = false; auto_vrr = false;
osd_size = 24;
force_inverted_byte_order = false; force_inverted_byte_order = false;
hires_effect = HIRES_NORMAL; hires_effect = HIRES_NORMAL;
pause_emulation_on_switch = false; pause_emulation_on_switch = false;
@ -165,6 +166,7 @@ int Snes9xConfig::load_defaults()
Settings.Transparency = true; Settings.Transparency = true;
Settings.DisplayTime = false; Settings.DisplayTime = false;
Settings.DisplayFrameRate = false; Settings.DisplayFrameRate = false;
Settings.DisplayIndicators = false;
Settings.SixteenBitSound = true; Settings.SixteenBitSound = true;
Settings.Stereo = true; Settings.Stereo = true;
Settings.ReverseStereo = false; Settings.ReverseStereo = false;
@ -236,6 +238,7 @@ int Snes9xConfig::save_config_file()
outstring("HardwareAcceleration", display_driver, "none, opengl, xv, vulkan"); outstring("HardwareAcceleration", display_driver, "none, opengl, xv, vulkan");
outint("SplashBackground", splash_image, "0: Black, 1: Color bars, 2: Pattern, 3: Blue, 4: Default"); outint("SplashBackground", splash_image, "0: Black, 1: Color bars, 2: Pattern, 3: Blue, 4: Default");
outbool("AutoVRR", auto_vrr, "Automatically use the best settings for variable sync in fullscreen mode"); outbool("AutoVRR", auto_vrr, "Automatically use the best settings for variable sync in fullscreen mode");
outint("OSDSize", osd_size, "Size of on-screen display elements. Default: 24pt");
section = "NTSC"; section = "NTSC";
outstring("Hue", std::to_string(ntsc_setup.hue)); outstring("Hue", std::to_string(ntsc_setup.hue));
@ -316,6 +319,7 @@ int Snes9xConfig::save_config_file()
outbool("DisplayTime", Settings.DisplayTime); outbool("DisplayTime", Settings.DisplayTime);
outbool("DisplayFrameRate", Settings.DisplayFrameRate); outbool("DisplayFrameRate", Settings.DisplayFrameRate);
outbool("DisplayPressedKeys", Settings.DisplayPressedKeys); outbool("DisplayPressedKeys", Settings.DisplayPressedKeys);
outbool("DisplayIndicators", Settings.DisplayIndicators);
outint("SpeedControlMethod", Settings.SkipFrames, "0: Time the frames to 50 or 60Hz, 1: Same, but skip frames if too slow, 2: Synchronize to the sound buffer, 3: Unlimited, except potentially by vsync"); outint("SpeedControlMethod", Settings.SkipFrames, "0: Time the frames to 50 or 60Hz, 1: Same, but skip frames if too slow, 2: Synchronize to the sound buffer, 3: Unlimited, except potentially by vsync");
outint("SaveSRAMEveryNSeconds", Settings.AutoSaveDelay); outint("SaveSRAMEveryNSeconds", Settings.AutoSaveDelay);
outbool("BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster); outbool("BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster);
@ -460,6 +464,7 @@ int Snes9xConfig::load_config_file()
inbool("BilinearFilter", Settings.BilinearFilter); inbool("BilinearFilter", Settings.BilinearFilter);
inint("SplashBackground", splash_image); inint("SplashBackground", splash_image);
inbool("AutoVRR", auto_vrr); inbool("AutoVRR", auto_vrr);
inint("OSDSize", osd_size);
section = "NTSC"; section = "NTSC";
indouble("Hue", ntsc_setup.hue); indouble("Hue", ntsc_setup.hue);
@ -541,6 +546,7 @@ int Snes9xConfig::load_config_file()
inint("SaveSRAMEveryNSeconds", Settings.AutoSaveDelay); inint("SaveSRAMEveryNSeconds", Settings.AutoSaveDelay);
inbool("BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster); inbool("BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster);
inbool("AllowDPadContradictions", Settings.UpAndDown); inbool("AllowDPadContradictions", Settings.UpAndDown);
inbool("DisplayIndicators", Settings.DisplayIndicators);
section = "Hacks"; section = "Hacks";
inint("SuperFXClockMultiplier", Settings.SuperFXClockMultiplier); inint("SuperFXClockMultiplier", Settings.SuperFXClockMultiplier);

View File

@ -72,6 +72,7 @@ class Snes9xConfig
bool force_inverted_byte_order; bool force_inverted_byte_order;
int splash_image; int splash_image;
bool auto_vrr; bool auto_vrr;
int osd_size;
snes_ntsc_setup_t ntsc_setup; snes_ntsc_setup_t ntsc_setup;
int ntsc_format; int ntsc_format;

View File

@ -407,7 +407,10 @@ int S9xOpenGLDisplayDriver::init()
if (version >= 33) if (version >= 33)
{ {
S9xImGuiInit(); auto defaults = S9xImGuiGetDefaults();
defaults.font_size = gui_config->osd_size;
defaults.spacing = defaults.font_size / 2.4;
S9xImGuiInit(&defaults);
ImGui_ImplOpenGL3_Init(); ImGui_ImplOpenGL3_Init();
} }

View File

@ -31,7 +31,10 @@ S9xVulkanDisplayDriver::~S9xVulkanDisplayDriver()
bool S9xVulkanDisplayDriver::init_imgui() bool S9xVulkanDisplayDriver::init_imgui()
{ {
S9xImGuiInit(); auto defaults = S9xImGuiGetDefaults();
defaults.font_size = gui_config->osd_size;
defaults.spacing = defaults.font_size / 2.4;
S9xImGuiInit(&defaults);
ImGui_ImplVulkan_LoadFunctions([](const char *function, void *instance) { ImGui_ImplVulkan_LoadFunctions([](const char *function, void *instance) {
return VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr(*((VkInstance *)instance), function); return VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr(*((VkInstance *)instance), function);

View File

@ -394,6 +394,8 @@ void Snes9xPreferences::move_settings_to_dialog()
set_check("show_time", Settings.DisplayTime); set_check("show_time", Settings.DisplayTime);
set_check("show_frame_rate", Settings.DisplayFrameRate); set_check("show_frame_rate", Settings.DisplayFrameRate);
set_check("show_pressed_keys", Settings.DisplayPressedKeys); set_check("show_pressed_keys", Settings.DisplayPressedKeys);
set_check("show_indicators", Settings.DisplayIndicators);
set_spin("osd_size", config->osd_size);
set_check("change_display_resolution", config->change_display_resolution); set_check("change_display_resolution", config->change_display_resolution);
set_check("scale_to_fit", config->scale_to_fit); set_check("scale_to_fit", config->scale_to_fit);
set_check("overscan", config->overscan); set_check("overscan", config->overscan);
@ -554,6 +556,10 @@ void Snes9xPreferences::get_settings_from_dialog()
if (config->force_inverted_byte_order != get_check("force_inverted_byte_order")) if (config->force_inverted_byte_order != get_check("force_inverted_byte_order"))
gfx_needs_restart = true; gfx_needs_restart = true;
if (config->osd_size != get_spin("osd_size"))
gfx_needs_restart = true;
config->enable_icons = get_check("force_enable_icons"); config->enable_icons = get_check("force_enable_icons");
auto settings = Gtk::Settings::get_default(); auto settings = Gtk::Settings::get_default();
settings->set_property("gtk-menu-images", gui_config->enable_icons); settings->set_property("gtk-menu-images", gui_config->enable_icons);
@ -563,6 +569,8 @@ void Snes9xPreferences::get_settings_from_dialog()
Settings.DisplayTime = get_check("show_time"); Settings.DisplayTime = get_check("show_time");
Settings.DisplayFrameRate = get_check("show_frame_rate"); Settings.DisplayFrameRate = get_check("show_frame_rate");
Settings.DisplayPressedKeys = get_check("show_pressed_keys"); Settings.DisplayPressedKeys = get_check("show_pressed_keys");
Settings.DisplayIndicators = get_check("show_indicators");
config->osd_size = get_spin("osd_size");
config->scale_to_fit = get_check("scale_to_fit"); config->scale_to_fit = get_check("scale_to_fit");
config->overscan = get_check("overscan"); config->overscan = get_check("overscan");
config->maintain_aspect_ratio = get_check("maintain_aspect_ratio"); config->maintain_aspect_ratio = get_check("maintain_aspect_ratio");

View File

@ -209,6 +209,13 @@
<property name="step_increment">1</property> <property name="step_increment">1</property>
<property name="page_increment">1</property> <property name="page_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="osd_size_adjustment">
<property name="lower">12</property>
<property name="upper">128</property>
<property name="value">24</property>
<property name="step_increment">1</property>
<property name="page_increment">1</property>
</object>
<object class="GtkAdjustment" id="adjustment4"> <object class="GtkAdjustment" id="adjustment4">
<property name="lower">1</property> <property name="lower">1</property>
<property name="upper">100</property> <property name="upper">100</property>
@ -2866,6 +2873,21 @@
<property name="position">3</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkCheckButton" id="show_indicators">
<property name="label" translatable="yes">Show fast-forward and pause indicators</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
<child> <child>
<object class="GtkCheckButton" id="overscan"> <object class="GtkCheckButton" id="overscan">
<property name="label" translatable="yes">Use overscanned height</property> <property name="label" translatable="yes">Use overscanned height</property>
@ -2879,9 +2901,56 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">4</property> <property name="position">5</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkHBox" id="osd_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="osdlabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">On-screen display size:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="osd_size">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Connect to specified TCP port on remote computer</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<property name="adjustment">osd_size_adjustment</property>
<property name="snap_to_ticks">True</property>
<property name="width_chars">6</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">7</property>
</packing>
</child>
<child> <child>
<object class="GtkHBox" id="resolution_box"> <object class="GtkHBox" id="resolution_box">
<property name="visible">True</property> <property name="visible">True</property>
@ -2925,9 +2994,11 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">5</property> <property name="position">6</property>
</packing> </packing>
</child> </child>
</object> </object>
</child> </child>
</object> </object>

View File

@ -254,6 +254,7 @@ struct SSettings
bool8 DisplayWatchedAddresses; bool8 DisplayWatchedAddresses;
bool8 DisplayPressedKeys; bool8 DisplayPressedKeys;
bool8 DisplayMovieFrame; bool8 DisplayMovieFrame;
bool DisplayIndicators;
bool8 AutoDisplayMessages; bool8 AutoDisplayMessages;
uint32 InitialInfoStringTimeout; uint32 InitialInfoStringTimeout;
uint16 DisplayColor; uint16 DisplayColor;