| 1 | // Copyright 2025 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/Settings/OnScreenDisplayPane.h" |
| 5 | |
| 6 | #include <QGridLayout> |
| 7 | #include <QGroupBox> |
| 8 | #include <QLabel> |
| 9 | #include <QVBoxLayout> |
| 10 | #include <QWidget> |
| 11 | |
| 12 | #include "Core/Config/GraphicsSettings.h" |
| 13 | #include "Core/Config/MainSettings.h" |
| 14 | |
| 15 | #include "DolphinQt/Config/ConfigControls/ConfigBool.h" |
| 16 | #include "DolphinQt/Config/ConfigControls/ConfigInteger.h" |
| 17 | |
| 18 | OnScreenDisplayPane::OnScreenDisplayPane(QWidget* parent) : QWidget(parent) |
| 19 | { |
| 20 | CreateLayout(); |
| 21 | ConnectLayout(); |
| 22 | AddDescriptions(); |
| 23 | } |
| 24 | |
| 25 | void OnScreenDisplayPane::CreateLayout() |
| 26 | { |
| 27 | // General |
| 28 | auto* general_box = new QGroupBox(tr("General")); |
| 29 | auto* general_layout = new QGridLayout(); |
| 30 | general_box->setLayout(general_layout); |
| 31 | |
| 32 | m_enable_osd = new ConfigBool(tr("Show Messages"), Config::MAIN_OSD_MESSAGES); |
| 33 | m_font_size = new ConfigInteger(12, 40, Config::MAIN_OSD_FONT_SIZE); |
| 34 | |
| 35 | general_layout->addWidget(m_enable_osd, 0, 0); |
| 36 | general_layout->addWidget(new QLabel(tr("Font Size:")), 1, 0); |
| 37 | m_font_size->SetTitle(tr("Font Size")); |
| 38 | general_layout->addWidget(m_font_size, 1, 1); |
| 39 | |
| 40 | // Performance |
| 41 | auto* performance_box = new QGroupBox(tr("Performance Statistics")); |
| 42 | auto* performance_layout = new QGridLayout(); |
| 43 | performance_box->setLayout(performance_layout); |
| 44 | |
| 45 | m_show_fps = new ConfigBool(tr("Show FPS"), Config::GFX_SHOW_FPS); |
| 46 | m_show_internal_resolution = |
| 47 | new ConfigBool(tr("Show Internal Resolution"), Config::GFX_SHOW_INTERNAL_RESOLUTION); |
| 48 | m_show_ftimes = new ConfigBool(tr("Show Frame Times"), Config::GFX_SHOW_FTIMES); |
| 49 | m_show_vps = new ConfigBool(tr("Show VPS"), Config::GFX_SHOW_VPS); |
| 50 | m_show_vtimes = new ConfigBool(tr("Show VBlank Times"), Config::GFX_SHOW_VTIMES); |
| 51 | m_show_speed = new ConfigBool(tr("Show % Speed"), Config::GFX_SHOW_SPEED); |
| 52 | m_show_graph = new ConfigBool(tr("Show Performance Graphs"), Config::GFX_SHOW_GRAPHS); |
| 53 | m_speed_colors = new ConfigBool(tr("Show Speed Colors"), Config::GFX_SHOW_SPEED_COLORS); |
| 54 | m_perf_sample_window = new ConfigInteger(0, 10000, Config::GFX_PERF_SAMP_WINDOW, 100); |
| 55 | |
| 56 | performance_layout->addWidget(m_show_fps, 0, 0); |
| 57 | performance_layout->addWidget(m_show_ftimes, 0, 1); |
| 58 | performance_layout->addWidget(m_show_vps, 1, 0); |
| 59 | performance_layout->addWidget(m_show_vtimes, 1, 1); |
| 60 | performance_layout->addWidget(m_show_speed, 2, 0); |
| 61 | performance_layout->addWidget(m_show_graph, 2, 1); |
| 62 | performance_layout->addWidget(m_speed_colors, 3, 0); |
| 63 | performance_layout->addWidget(new QLabel(tr("Performance Sample Window (ms):")), 4, 0); |
| 64 | m_perf_sample_window->SetTitle(tr("Performance Sample Window (ms)")); |
| 65 | performance_layout->addWidget(m_perf_sample_window, 4, 1); |
| 66 | |
| 67 | // Movie |
| 68 | auto* movie_box = new QGroupBox(tr("Movie Window")); |
| 69 | auto* movie_layout = new QGridLayout(); |
| 70 | movie_box->setLayout(movie_layout); |
| 71 | |
| 72 | m_movie_window = new ConfigBool(tr("Show Movie Window"), Config::MAIN_MOVIE_SHOW_OSD); |
| 73 | m_rerecord_counter = |
| 74 | new ConfigBool(tr("Show Rerecord Counter"), Config::MAIN_MOVIE_SHOW_RERECORD); |
| 75 | m_lag_counter = new ConfigBool(tr("Show Lag Counter"), Config::MAIN_SHOW_LAG); |
| 76 | m_frame_counter = new ConfigBool(tr("Show Frame Counter"), Config::MAIN_SHOW_FRAME_COUNT); |
| 77 | m_input_display = new ConfigBool(tr("Show Input Display"), Config::MAIN_MOVIE_SHOW_INPUT_DISPLAY); |
| 78 | m_system_clock = new ConfigBool(tr("Show System Clock"), Config::MAIN_MOVIE_SHOW_RTC); |
| 79 | |
| 80 | movie_layout->addWidget(m_movie_window, 0, 0); |
| 81 | movie_layout->addWidget(m_rerecord_counter, 1, 0); |
| 82 | movie_layout->addWidget(m_lag_counter, 1, 1); |
| 83 | movie_layout->addWidget(m_frame_counter, 2, 0); |
| 84 | movie_layout->addWidget(m_input_display, 2, 1); |
| 85 | movie_layout->addWidget(m_system_clock, 3, 0); |
| 86 | |
| 87 | // NetPlay |
| 88 | auto* netplay_box = new QGroupBox(tr("Netplay")); |
| 89 | auto* netplay_layout = new QGridLayout(); |
| 90 | netplay_box->setLayout(netplay_layout); |
| 91 | |
| 92 | m_show_ping = new ConfigBool(tr("Show NetPlay Ping"), Config::GFX_SHOW_NETPLAY_PING); |
| 93 | m_show_chat = new ConfigBool(tr("Show NetPlay Chat"), Config::GFX_SHOW_NETPLAY_MESSAGES); |
| 94 | |
| 95 | netplay_layout->addWidget(m_show_ping, 0, 0); |
| 96 | netplay_layout->addWidget(m_show_chat, 0, 1); |
| 97 | |
| 98 | // Debug |
| 99 | auto* debug_box = new QGroupBox(tr("Debug")); |
| 100 | auto* debug_layout = new QGridLayout(); |
| 101 | debug_box->setLayout(debug_layout); |
| 102 | |
| 103 | m_show_statistics = new ConfigBool(tr("Show Statistics"), Config::GFX_OVERLAY_STATS); |
| 104 | m_show_proj_statistics = |
| 105 | new ConfigBool(tr("Show Projection Statistics"), Config::GFX_OVERLAY_PROJ_STATS); |
| 106 | |
| 107 | debug_layout->addWidget(m_show_statistics, 0, 0); |
| 108 | debug_layout->addWidget(m_show_proj_statistics, 0, 1); |
| 109 | debug_layout->addWidget(m_show_internal_resolution, 1, 0); |
| 110 | |
| 111 | // Stack GroupBoxes |
| 112 | auto* main_layout = new QVBoxLayout; |
| 113 | main_layout->addWidget(general_box); |
| 114 | main_layout->addWidget(performance_box); |
| 115 | main_layout->addWidget(movie_box); |
| 116 | main_layout->addWidget(netplay_box); |
| 117 | main_layout->addWidget(debug_box); |
| 118 | main_layout->addStretch(); |
| 119 | setLayout(main_layout); |
| 120 | } |
| 121 | |
| 122 | void OnScreenDisplayPane::ConnectLayout() |
| 123 | { |
| 124 | // Disable movie window options when window is closed. |
| 125 | auto enable_movie_items = [this](bool checked) { |
| 126 | for (auto* widget : |
| 127 | {m_rerecord_counter, m_frame_counter, m_lag_counter, m_system_clock, m_input_display}) |
| 128 | { |
| 129 | widget->setEnabled(checked); |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | enable_movie_items(m_movie_window->isChecked()); |
| 134 | connect(m_movie_window, &QCheckBox::toggled, this, [this, enable_movie_items](bool checked) { |
| 135 | enable_movie_items(m_movie_window->isChecked()); |
| 136 | }); |
| 137 | } |
| 138 | |
| 139 | void OnScreenDisplayPane::AddDescriptions() |
| 140 | { |
| 141 | static constexpr char TR_ENABLE_OSD_DESCRIPTION[] = |
| 142 | QT_TR_NOOP("Shows on-screen display messages over the render window. These messages " |
| 143 | "disappear after several seconds." |
| 144 | "<br><br><dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>"); |
| 145 | static const char TR_OSD_FONT_SIZE_DESCRIPTION[] = QT_TR_NOOP( |
| 146 | "Changes the font size of the On-Screen Display. Affects features such as performance " |
| 147 | "statistics, frame counter, and netplay chat." |
| 148 | "<br><br>The font can be changed by placing a TTF font file into Dolphin's User/Load " |
| 149 | "folder, and renaming it OSD_Font.ttf." |
| 150 | "<br><br><dolphin_emphasis>If unsure, leave this at 13.</dolphin_emphasis>"); |
| 151 | |
| 152 | static const char TR_SHOW_FPS_DESCRIPTION[] = |
| 153 | QT_TR_NOOP("Shows the number of distinct frames rendered per second as a measure of " |
| 154 | "visual smoothness.<br><br><dolphin_emphasis>If unsure, leave this " |
| 155 | "unchecked.</dolphin_emphasis>"); |
| 156 | |
| 157 | static const char TR_SHOW_INTERNAL_RESOLUTION_DESCRIPTION[] = |
| 158 | QT_TR_NOOP("Shows the internal resolution in pixels, as a product of " |
| 159 | "width and height. <br><br><dolphin_emphasis>If unsure, leave this " |
| 160 | "unchecked.</dolphin_emphasis>"); |
| 161 | static const char TR_SHOW_FTIMES_DESCRIPTION[] = |
| 162 | QT_TR_NOOP("Shows the average time in ms between each distinct rendered frame alongside " |
| 163 | "the standard deviation.<br><br><dolphin_emphasis>If unsure, leave this " |
| 164 | "unchecked.</dolphin_emphasis>"); |
| 165 | static const char TR_SHOW_VPS_DESCRIPTION[] = |
| 166 | QT_TR_NOOP("Shows the number of frames rendered per second as a measure of " |
| 167 | "emulation speed.<br><br><dolphin_emphasis>If unsure, leave this " |
| 168 | "unchecked.</dolphin_emphasis>"); |
| 169 | static const char TR_SHOW_VTIMES_DESCRIPTION[] = |
| 170 | QT_TR_NOOP("Shows the average time in ms between each rendered frame alongside " |
| 171 | "the standard deviation.<br><br><dolphin_emphasis>If unsure, leave this " |
| 172 | "unchecked.</dolphin_emphasis>"); |
| 173 | static const char TR_SHOW_GRAPHS_DESCRIPTION[] = |
| 174 | QT_TR_NOOP("Shows frametime graph along with statistics as a representation of " |
| 175 | "emulation performance.<br><br><dolphin_emphasis>If unsure, leave this " |
| 176 | "unchecked.</dolphin_emphasis>"); |
| 177 | static const char TR_SHOW_SPEED_DESCRIPTION[] = |
| 178 | QT_TR_NOOP("Shows the % speed of emulation compared to full speed." |
| 179 | "<br><br><dolphin_emphasis>If unsure, leave this " |
| 180 | "unchecked.</dolphin_emphasis>"); |
| 181 | static const char TR_SHOW_SPEED_COLORS_DESCRIPTION[] = |
| 182 | QT_TR_NOOP("Changes the color of the FPS counter depending on emulation speed." |
| 183 | "<br><br><dolphin_emphasis>If unsure, leave this " |
| 184 | "checked.</dolphin_emphasis>"); |
| 185 | static const char TR_PERF_SAMP_WINDOW_DESCRIPTION[] = |
| 186 | QT_TR_NOOP("The amount of time the FPS and VPS counters will sample over." |
| 187 | "<br><br>The higher the value, the more stable the FPS/VPS counter will be, " |
| 188 | "but the slower it will be to update." |
| 189 | "<br><br><dolphin_emphasis>If unsure, leave this " |
| 190 | "at 1000ms.</dolphin_emphasis>"); |
| 191 | |
| 192 | static const char TR_SHOW_NETPLAY_PING_DESCRIPTION[] = QT_TR_NOOP( |
| 193 | "Shows the player's maximum ping while playing on " |
| 194 | "NetPlay.<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"); |
| 195 | static const char TR_SHOW_NETPLAY_MESSAGES_DESCRIPTION[] = |
| 196 | QT_TR_NOOP("Shows chat messages, buffer changes, and desync alerts " |
| 197 | "while playing NetPlay.<br><br><dolphin_emphasis>If unsure, leave " |
| 198 | "this unchecked.</dolphin_emphasis>"); |
| 199 | |
| 200 | static const char TR_MOVIE_WINDOW_DESCRIPTION[] = |
| 201 | QT_TR_NOOP("Shows a window that can be filled with information related to movie recordings. " |
| 202 | "The other options in this group determine what appears in the window. " |
| 203 | "<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"); |
| 204 | static const char TR_RERECORD_COUNTER_DESCRIPTION[] = |
| 205 | QT_TR_NOOP("Shows how many times the input recording has been overwritten by using " |
| 206 | "savestates.<br><br><dolphin_emphasis>If unsure, leave " |
| 207 | "this unchecked.</dolphin_emphasis>"); |
| 208 | static const char TR_LAG_COUNTER_DESCRIPTION[] = QT_TR_NOOP( |
| 209 | "Shows how many frames have occurred without controller inputs being checked. Resets to 1 " |
| 210 | "when inputs are processed. <br><br><dolphin_emphasis>If unsure, leave " |
| 211 | "this unchecked.</dolphin_emphasis>"); |
| 212 | static const char TR_FRAME_COUNTER_DESCRIPTION[] = |
| 213 | QT_TR_NOOP("Shows how many frames have passed. <br><br><dolphin_emphasis>If unsure, leave " |
| 214 | "this unchecked.</dolphin_emphasis>"); |
| 215 | static const char TR_INPUT_DISPLAY_DESCRIPTION[] = QT_TR_NOOP( |
| 216 | "Shows the controls currently being input.<br><br><dolphin_emphasis>If unsure, leave " |
| 217 | "this unchecked.</dolphin_emphasis>"); |
| 218 | static const char TR_SYSTEM_CLOCK_DESCRIPTION[] = |
| 219 | QT_TR_NOOP("Shows current system time.<br><br><dolphin_emphasis>If unsure, leave " |
| 220 | "this unchecked.</dolphin_emphasis>"); |
| 221 | |
| 222 | static const char TR_SHOW_STATS_DESCRIPTION[] = |
| 223 | QT_TR_NOOP("Shows various rendering statistics.<br><br><dolphin_emphasis>If unsure, " |
| 224 | "leave this unchecked.</dolphin_emphasis>"); |
| 225 | static const char TR_SHOW_PROJ_STATS_DESCRIPTION[] = |
| 226 | QT_TR_NOOP("Shows various projection statistics.<br><br><dolphin_emphasis>If unsure, " |
| 227 | "leave this unchecked.</dolphin_emphasis>"); |
| 228 | |
| 229 | m_enable_osd->SetDescription(tr(TR_ENABLE_OSD_DESCRIPTION)); |
| 230 | m_font_size->SetDescription(tr(TR_OSD_FONT_SIZE_DESCRIPTION)); |
| 231 | |
| 232 | m_show_fps->SetDescription(tr(TR_SHOW_FPS_DESCRIPTION)); |
| 233 | m_show_internal_resolution->SetDescription(tr(TR_SHOW_INTERNAL_RESOLUTION_DESCRIPTION)); |
| 234 | m_show_ftimes->SetDescription(tr(TR_SHOW_FTIMES_DESCRIPTION)); |
| 235 | m_show_vps->SetDescription(tr(TR_SHOW_VPS_DESCRIPTION)); |
| 236 | m_show_vtimes->SetDescription(tr(TR_SHOW_VTIMES_DESCRIPTION)); |
| 237 | m_show_graph->SetDescription(tr(TR_SHOW_GRAPHS_DESCRIPTION)); |
| 238 | m_show_speed->SetDescription(tr(TR_SHOW_SPEED_DESCRIPTION)); |
| 239 | m_perf_sample_window->SetDescription(tr(TR_PERF_SAMP_WINDOW_DESCRIPTION)); |
| 240 | m_speed_colors->SetDescription(tr(TR_SHOW_SPEED_COLORS_DESCRIPTION)); |
| 241 | |
| 242 | m_show_ping->SetDescription(tr(TR_SHOW_NETPLAY_PING_DESCRIPTION)); |
| 243 | m_show_chat->SetDescription(tr(TR_SHOW_NETPLAY_MESSAGES_DESCRIPTION)); |
| 244 | |
| 245 | m_movie_window->SetDescription(tr(TR_MOVIE_WINDOW_DESCRIPTION)); |
| 246 | m_rerecord_counter->SetDescription(tr(TR_RERECORD_COUNTER_DESCRIPTION)); |
| 247 | m_lag_counter->SetDescription(tr(TR_LAG_COUNTER_DESCRIPTION)); |
| 248 | m_frame_counter->SetDescription(tr(TR_FRAME_COUNTER_DESCRIPTION)); |
| 249 | m_input_display->SetDescription(tr(TR_INPUT_DISPLAY_DESCRIPTION)); |
| 250 | m_system_clock->SetDescription(tr(TR_SYSTEM_CLOCK_DESCRIPTION)); |
| 251 | |
| 252 | m_show_statistics->SetDescription(tr(TR_SHOW_STATS_DESCRIPTION)); |
| 253 | m_show_proj_statistics->SetDescription(tr(TR_SHOW_PROJ_STATS_DESCRIPTION)); |
| 254 | } |