summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2016-12-19 14:50:58 -0500
committerGravatar Lioncash2016-12-19 15:12:28 -0500
commitcc1f2c131b9d390bb4da3f997354ea78eb080c40 (patch)
treed8238d8600d14c8d75596d1a152f239c7e315b9e
parentMerge pull request #2318 from yuriks/trace-opt (diff)
downloadyuzu-cc1f2c131b9d390bb4da3f997354ea78eb080c40.tar.gz
yuzu-cc1f2c131b9d390bb4da3f997354ea78eb080c40.tar.xz
yuzu-cc1f2c131b9d390bb4da3f997354ea78eb080c40.zip
citra-qt: Move bits of constructor behavior to named functions
Makes the initialization process a tad easier to grok, since the constructor isn't just a glob of random unrelated behaviors.
-rw-r--r--src/citra_qt/main.cpp139
-rw-r--r--src/citra_qt/main.h28
2 files changed, 100 insertions, 67 deletions
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 74feec81f..4486f0870 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -60,6 +60,36 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
60 ui.setupUi(this); 60 ui.setupUi(this);
61 statusBar()->hide(); 61 statusBar()->hide();
62 62
63 InitializeWidgets();
64 InitializeDebugMenuActions();
65 InitializeRecentFileMenuActions();
66 InitializeHotkeys();
67
68 SetDefaultUIGeometry();
69 RestoreUIState();
70
71 ConnectWidgetEvents();
72
73 setWindowTitle(QString("Citra | %1-%2").arg(Common::g_scm_branch, Common::g_scm_desc));
74 show();
75
76 game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
77
78 QStringList args = QApplication::arguments();
79 if (args.length() >= 2) {
80 BootGame(args[1].toStdString());
81 }
82}
83
84GMainWindow::~GMainWindow() {
85 // will get automatically deleted otherwise
86 if (render_window->parent() == nullptr)
87 delete render_window;
88
89 Pica::g_debug_context.reset();
90}
91
92void GMainWindow::InitializeWidgets() {
63 render_window = new GRenderWindow(this, emu_thread.get()); 93 render_window = new GRenderWindow(this, emu_thread.get());
64 render_window->hide(); 94 render_window->hide();
65 95
@@ -95,25 +125,27 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
95 addDockWidget(Qt::RightDockWidgetArea, graphicsCommandsWidget); 125 addDockWidget(Qt::RightDockWidgetArea, graphicsCommandsWidget);
96 graphicsCommandsWidget->hide(); 126 graphicsCommandsWidget->hide();
97 127
98 auto graphicsBreakpointsWidget = new GraphicsBreakPointsWidget(Pica::g_debug_context, this); 128 graphicsBreakpointsWidget = new GraphicsBreakPointsWidget(Pica::g_debug_context, this);
99 addDockWidget(Qt::RightDockWidgetArea, graphicsBreakpointsWidget); 129 addDockWidget(Qt::RightDockWidgetArea, graphicsBreakpointsWidget);
100 graphicsBreakpointsWidget->hide(); 130 graphicsBreakpointsWidget->hide();
101 131
102 auto graphicsVertexShaderWidget = new GraphicsVertexShaderWidget(Pica::g_debug_context, this); 132 graphicsVertexShaderWidget = new GraphicsVertexShaderWidget(Pica::g_debug_context, this);
103 addDockWidget(Qt::RightDockWidgetArea, graphicsVertexShaderWidget); 133 addDockWidget(Qt::RightDockWidgetArea, graphicsVertexShaderWidget);
104 graphicsVertexShaderWidget->hide(); 134 graphicsVertexShaderWidget->hide();
105 135
106 auto graphicsTracingWidget = new GraphicsTracingWidget(Pica::g_debug_context, this); 136 graphicsTracingWidget = new GraphicsTracingWidget(Pica::g_debug_context, this);
107 addDockWidget(Qt::RightDockWidgetArea, graphicsTracingWidget); 137 addDockWidget(Qt::RightDockWidgetArea, graphicsTracingWidget);
108 graphicsTracingWidget->hide(); 138 graphicsTracingWidget->hide();
109 139
110 auto graphicsSurfaceViewerAction = new QAction(tr("Create Pica Surface Viewer"), this);
111 connect(graphicsSurfaceViewerAction, SIGNAL(triggered()), this,
112 SLOT(OnCreateGraphicsSurfaceViewer()));
113
114 waitTreeWidget = new WaitTreeWidget(this); 140 waitTreeWidget = new WaitTreeWidget(this);
115 addDockWidget(Qt::LeftDockWidgetArea, waitTreeWidget); 141 addDockWidget(Qt::LeftDockWidgetArea, waitTreeWidget);
116 waitTreeWidget->hide(); 142 waitTreeWidget->hide();
143}
144
145void GMainWindow::InitializeDebugMenuActions() {
146 auto graphicsSurfaceViewerAction = new QAction(tr("Create Pica Surface Viewer"), this);
147 connect(graphicsSurfaceViewerAction, SIGNAL(triggered()), this,
148 SLOT(OnCreateGraphicsSurfaceViewer()));
117 149
118 QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging")); 150 QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging"));
119 debug_menu->addAction(graphicsSurfaceViewerAction); 151 debug_menu->addAction(graphicsSurfaceViewerAction);
@@ -131,19 +163,47 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
131 debug_menu->addAction(graphicsVertexShaderWidget->toggleViewAction()); 163 debug_menu->addAction(graphicsVertexShaderWidget->toggleViewAction());
132 debug_menu->addAction(graphicsTracingWidget->toggleViewAction()); 164 debug_menu->addAction(graphicsTracingWidget->toggleViewAction());
133 debug_menu->addAction(waitTreeWidget->toggleViewAction()); 165 debug_menu->addAction(waitTreeWidget->toggleViewAction());
166}
167
168void GMainWindow::InitializeRecentFileMenuActions() {
169 for (int i = 0; i < max_recent_files_item; ++i) {
170 actions_recent_files[i] = new QAction(this);
171 actions_recent_files[i]->setVisible(false);
172 connect(actions_recent_files[i], SIGNAL(triggered()), this, SLOT(OnMenuRecentFile()));
173
174 ui.menu_recent_files->addAction(actions_recent_files[i]);
175 }
176
177 UpdateRecentFiles();
178}
179
180void GMainWindow::InitializeHotkeys() {
181 RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
182 RegisterHotkey("Main Window", "Swap Screens", QKeySequence::NextChild);
183 RegisterHotkey("Main Window", "Start Emulation");
184 LoadHotkeys();
185
186 connect(GetHotkey("Main Window", "Load File", this), SIGNAL(activated()), this,
187 SLOT(OnMenuLoadFile()));
188 connect(GetHotkey("Main Window", "Start Emulation", this), SIGNAL(activated()), this,
189 SLOT(OnStartGame()));
190 connect(GetHotkey("Main Window", "Swap Screens", render_window), SIGNAL(activated()), this,
191 SLOT(OnSwapScreens()));
192}
134 193
135 // Set default UI state 194void GMainWindow::SetDefaultUIGeometry() {
136 // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half 195 // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
137 QDesktopWidget* desktop = ((QApplication*)QApplication::instance())->desktop(); 196 const QRect screenRect = QApplication::desktop()->screenGeometry(this);
138 QRect screenRect = desktop->screenGeometry(this); 197
139 int x, y, w, h; 198 const int w = screenRect.width() * 2 / 3;
140 w = screenRect.width() * 2 / 3; 199 const int h = screenRect.height() / 2;
141 h = screenRect.height() / 2; 200 const int x = (screenRect.x() + screenRect.width()) / 2 - w / 2;
142 x = (screenRect.x() + screenRect.width()) / 2 - w / 2; 201 const int y = (screenRect.y() + screenRect.height()) / 2 - h * 55 / 100;
143 y = (screenRect.y() + screenRect.height()) / 2 - h * 55 / 100; 202
144 setGeometry(x, y, w, h); 203 setGeometry(x, y, w, h);
204}
145 205
146 // Restore UI state 206void GMainWindow::RestoreUIState() {
147 restoreGeometry(UISettings::values.geometry); 207 restoreGeometry(UISettings::values.geometry);
148 restoreState(UISettings::values.state); 208 restoreState(UISettings::values.state);
149 render_window->restoreGeometry(UISettings::values.renderwindow_geometry); 209 render_window->restoreGeometry(UISettings::values.renderwindow_geometry);
@@ -159,18 +219,9 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
159 219
160 ui.actionDisplay_widget_title_bars->setChecked(UISettings::values.display_titlebar); 220 ui.actionDisplay_widget_title_bars->setChecked(UISettings::values.display_titlebar);
161 OnDisplayTitleBars(ui.actionDisplay_widget_title_bars->isChecked()); 221 OnDisplayTitleBars(ui.actionDisplay_widget_title_bars->isChecked());
222}
162 223
163 // Prepare actions for recent files 224void GMainWindow::ConnectWidgetEvents() {
164 for (int i = 0; i < max_recent_files_item; ++i) {
165 actions_recent_files[i] = new QAction(this);
166 actions_recent_files[i]->setVisible(false);
167 connect(actions_recent_files[i], SIGNAL(triggered()), this, SLOT(OnMenuRecentFile()));
168
169 ui.menu_recent_files->addAction(actions_recent_files[i]);
170 }
171 UpdateRecentFiles();
172
173 // Setup connections
174 connect(game_list, SIGNAL(GameChosen(QString)), this, SLOT(OnGameListLoadFile(QString)), 225 connect(game_list, SIGNAL(GameChosen(QString)), this, SLOT(OnGameListLoadFile(QString)),
175 Qt::DirectConnection); 226 Qt::DirectConnection);
176 connect(game_list, SIGNAL(OpenSaveFolderRequested(u64)), this, 227 connect(game_list, SIGNAL(OpenSaveFolderRequested(u64)), this,
@@ -201,40 +252,6 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
201 connect(this, SIGNAL(EmulationStarting(EmuThread*)), waitTreeWidget, 252 connect(this, SIGNAL(EmulationStarting(EmuThread*)), waitTreeWidget,
202 SLOT(OnEmulationStarting(EmuThread*))); 253 SLOT(OnEmulationStarting(EmuThread*)));
203 connect(this, SIGNAL(EmulationStopping()), waitTreeWidget, SLOT(OnEmulationStopping())); 254 connect(this, SIGNAL(EmulationStopping()), waitTreeWidget, SLOT(OnEmulationStopping()));
204
205 // Setup hotkeys
206 RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
207 RegisterHotkey("Main Window", "Swap Screens", QKeySequence::NextChild);
208 RegisterHotkey("Main Window", "Start Emulation");
209 LoadHotkeys();
210
211 connect(GetHotkey("Main Window", "Load File", this), SIGNAL(activated()), this,
212 SLOT(OnMenuLoadFile()));
213 connect(GetHotkey("Main Window", "Start Emulation", this), SIGNAL(activated()), this,
214 SLOT(OnStartGame()));
215 connect(GetHotkey("Main Window", "Swap Screens", render_window), SIGNAL(activated()), this,
216 SLOT(OnSwapScreens()));
217
218 std::string window_title =
219 Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
220 setWindowTitle(window_title.c_str());
221
222 show();
223
224 game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
225
226 QStringList args = QApplication::arguments();
227 if (args.length() >= 2) {
228 BootGame(args[1].toStdString());
229 }
230}
231
232GMainWindow::~GMainWindow() {
233 // will get automatically deleted otherwise
234 if (render_window->parent() == nullptr)
235 delete render_window;
236
237 Pica::g_debug_context.reset();
238} 255}
239 256
240void GMainWindow::OnDisplayTitleBars(bool show) { 257void GMainWindow::OnDisplayTitleBars(bool show) {
diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h
index 035b68a35..a2fd45c47 100644
--- a/src/citra_qt/main.h
+++ b/src/citra_qt/main.h
@@ -9,18 +9,21 @@
9#include <QMainWindow> 9#include <QMainWindow>
10#include "ui_main.h" 10#include "ui_main.h"
11 11
12class CallstackWidget;
12class Config; 13class Config;
14class DisassemblerWidget;
15class EmuThread;
13class GameList; 16class GameList;
14class GImageInfo; 17class GImageInfo;
18class GPUCommandStreamWidget;
19class GPUCommandListWidget;
20class GraphicsBreakPointsWidget;
21class GraphicsTracingWidget;
22class GraphicsVertexShaderWidget;
15class GRenderWindow; 23class GRenderWindow;
16class EmuThread;
17class ProfilerWidget;
18class MicroProfileDialog; 24class MicroProfileDialog;
19class DisassemblerWidget; 25class ProfilerWidget;
20class RegistersWidget; 26class RegistersWidget;
21class CallstackWidget;
22class GPUCommandStreamWidget;
23class GPUCommandListWidget;
24class WaitTreeWidget; 27class WaitTreeWidget;
25 28
26class GMainWindow : public QMainWindow { 29class GMainWindow : public QMainWindow {
@@ -60,6 +63,16 @@ signals:
60 void EmulationStopping(); 63 void EmulationStopping();
61 64
62private: 65private:
66 void InitializeWidgets();
67 void InitializeDebugMenuActions();
68 void InitializeRecentFileMenuActions();
69 void InitializeHotkeys();
70
71 void SetDefaultUIGeometry();
72 void RestoreUIState();
73
74 void ConnectWidgetEvents();
75
63 /** 76 /**
64 * Initializes the emulation system. 77 * Initializes the emulation system.
65 * @param system_mode The system mode with which to intialize the kernel. 78 * @param system_mode The system mode with which to intialize the kernel.
@@ -136,6 +149,9 @@ private:
136 CallstackWidget* callstackWidget; 149 CallstackWidget* callstackWidget;
137 GPUCommandStreamWidget* graphicsWidget; 150 GPUCommandStreamWidget* graphicsWidget;
138 GPUCommandListWidget* graphicsCommandsWidget; 151 GPUCommandListWidget* graphicsCommandsWidget;
152 GraphicsBreakPointsWidget* graphicsBreakpointsWidget;
153 GraphicsVertexShaderWidget* graphicsVertexShaderWidget;
154 GraphicsTracingWidget* graphicsTracingWidget;
139 WaitTreeWidget* waitTreeWidget; 155 WaitTreeWidget* waitTreeWidget;
140 156
141 QAction* actions_recent_files[max_recent_files_item]; 157 QAction* actions_recent_files[max_recent_files_item];