all repos — mgba @ 0883dc08150e44dbb3f7d66948e2fa5f0046c4fd

mGBA Game Boy Advance Emulator

src/platform/qt/Window.h (view raw)

  1/* Copyright (c) 2013-2017 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef QGBA_WINDOW
  7#define QGBA_WINDOW
  8
  9#include <QDateTime>
 10#include <QList>
 11#include <QMainWindow>
 12#include <QTimer>
 13
 14#include <functional>
 15#include <memory>
 16
 17#include <mgba/core/thread.h>
 18
 19#include "InputController.h"
 20#include "LoadSaveState.h"
 21#include "LogController.h"
 22struct mArguments;
 23
 24namespace QGBA {
 25
 26class AudioProcessor;
 27class ConfigController;
 28class CoreController;
 29class CoreManager;
 30class DebuggerConsoleController;
 31class Display;
 32class GDBController;
 33class GIFView;
 34class LibraryController;
 35class LogView;
 36class OverrideView;
 37class SensorView;
 38class ShaderSelector;
 39class ShortcutController;
 40class VideoView;
 41class WindowBackground;
 42
 43class Window : public QMainWindow {
 44Q_OBJECT
 45
 46public:
 47	Window(CoreManager* manager, ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
 48	virtual ~Window();
 49
 50	std::shared_ptr<CoreController> controller() { return m_controller; }
 51
 52	void setConfig(ConfigController*);
 53	void argumentsPassed(mArguments*);
 54
 55	void resizeFrame(const QSize& size);
 56
 57	void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
 58
 59signals:
 60	void startDrawing();
 61	void shutdown();
 62	void paused(bool);
 63
 64public slots:
 65	void setController(CoreController* controller, const QString& fname);
 66	void selectROM();
 67#ifdef USE_SQLITE3
 68	void selectROMInArchive();
 69	void addDirToLibrary();
 70#endif
 71	void selectSave(bool temporary);
 72	void selectPatch();
 73	void enterFullScreen();
 74	void exitFullScreen();
 75	void toggleFullScreen();
 76	void loadConfig();
 77	void reloadConfig();
 78	void saveConfig();
 79
 80	void loadCamImage();
 81
 82	void replaceROM();
 83
 84	void multiplayerChanged();
 85
 86	void importSharkport();
 87	void exportSharkport();
 88
 89	void openSettingsWindow();
 90
 91	void startVideoLog();
 92
 93#ifdef USE_DEBUGGERS
 94	void consoleOpen();
 95#endif
 96
 97#ifdef USE_FFMPEG
 98	void openVideoWindow();
 99#endif
100
101#ifdef USE_MAGICK
102	void openGIFWindow();
103#endif
104
105#ifdef USE_GDB_STUB
106	void gdbOpen();
107#endif
108
109protected:
110	virtual void keyPressEvent(QKeyEvent* event) override;
111	virtual void keyReleaseEvent(QKeyEvent* event) override;
112	virtual void resizeEvent(QResizeEvent*) override;
113	virtual void showEvent(QShowEvent*) override;
114	virtual void closeEvent(QCloseEvent*) override;
115	virtual void focusInEvent(QFocusEvent*) override;
116	virtual void focusOutEvent(QFocusEvent*) override;
117	virtual void dragEnterEvent(QDragEnterEvent*) override;
118	virtual void dropEvent(QDropEvent*) override;
119	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
120
121private slots:
122	void gameStarted();
123	void gameStopped();
124	void gameCrashed(const QString&);
125	void gameFailed();
126	void unimplementedBiosCall(int);
127
128	void reloadAudioDriver();
129	void reloadDisplayDriver();
130
131	void tryMakePortable();
132	void mustRestart();
133
134	void recordFrame();
135	void showFPS();
136	void focusCheck();
137
138private:
139	static const int FPS_TIMER_INTERVAL = 2000;
140	static const int FRAME_LIST_SIZE = 120;
141
142	void setupMenu(QMenuBar*);
143	void openStateWindow(LoadSave);
144
145	void attachWidget(QWidget* widget);
146	void detachWidget(QWidget* widget);
147
148	void appendMRU(const QString& fname);
149	void updateMRU();
150
151	void openView(QWidget* widget);
152
153	template <typename T, typename... A> std::function<void()> openTView(A... arg);
154	template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
155
156	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
157	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
158
159	void updateTitle(float fps = -1);
160
161	QString getFilters() const;
162	QString getFiltersArchive() const;
163
164	CoreManager* m_manager;
165	std::shared_ptr<CoreController> m_controller;
166	std::unique_ptr<AudioProcessor> m_audioProcessor;
167
168	std::unique_ptr<Display> m_display;
169	int m_savedScale;
170	// TODO: Move these to a new class
171	QList<QAction*> m_gameActions;
172	QList<QAction*> m_nonMpActions;
173#ifdef M_CORE_GBA
174	QList<QAction*> m_gbaActions;
175#endif
176	QAction* m_multiWindow;
177	QMap<int, QAction*> m_frameSizes;
178	LogController m_log{0};
179	LogView* m_logView;
180#ifdef USE_DEBUGGERS
181	DebuggerConsoleController* m_console = nullptr;
182#endif
183	LoadSaveState* m_stateWindow = nullptr;
184	WindowBackground* m_screenWidget;
185	QPixmap m_logo{":/res/mgba-1024.png"};
186	ConfigController* m_config;
187	InputController m_inputController;
188	QList<QDateTime> m_frameList;
189	QTimer m_fpsTimer;
190	QList<QString> m_mruFiles;
191	QMenu* m_mruMenu = nullptr;
192	QMenu* m_videoLayers;
193	QMenu* m_audioChannels;
194	ShortcutController* m_shortcutController;
195	std::unique_ptr<ShaderSelector> m_shaderView;
196	bool m_fullscreenOnStart = false;
197	QTimer m_focusCheck;
198	bool m_autoresume = false;
199	bool m_wasOpened = false;
200	QString m_pendingPatch;
201
202	bool m_hitUnimplementedBiosCall;
203
204	std::unique_ptr<OverrideView> m_overrideView;
205	std::unique_ptr<SensorView> m_sensorView;
206
207#ifdef USE_FFMPEG
208	VideoView* m_videoView = nullptr;
209#endif
210
211#ifdef USE_MAGICK
212	GIFView* m_gifView = nullptr;
213#endif
214
215#ifdef USE_GDB_STUB
216	GDBController* m_gdbController = nullptr;
217#endif
218
219#ifdef USE_SQLITE3
220	LibraryController* m_libraryView;
221#endif
222};
223
224class WindowBackground : public QLabel {
225Q_OBJECT
226
227public:
228	WindowBackground(QWidget* parent = 0);
229
230	void setSizeHint(const QSize& size);
231	virtual QSize sizeHint() const override;
232	void setDimensions(int width, int height);
233	void setLockIntegerScaling(bool lock);
234	void setLockAspectRatio(bool lock);
235
236protected:
237	virtual void paintEvent(QPaintEvent*) override;
238
239private:
240	QSize m_sizeHint;
241	int m_aspectWidth;
242	int m_aspectHeight;
243	bool m_lockAspectRatio;
244	bool m_lockIntegerScaling;
245};
246
247}
248
249#endif