all repos — mgba @ a1acf8bcef00cbc2c3a8f7506d6e9db70a943c28

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