all repos — mgba @ 55330698cb08493324a8be5e812e86f94e2ac1fe

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