all repos — mgba @ cb7f150cc2b647ae5a9dca2175bd5464d7d5e42f

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#pragma once
  7
  8#include <QAction>
  9#include <QDateTime>
 10#include <QElapsedTimer>
 11#include <QList>
 12#include <QMainWindow>
 13#include <QTimer>
 14
 15#include <functional>
 16#include <memory>
 17
 18#include <mgba/core/core.h>
 19#include <mgba/core/thread.h>
 20
 21#include "ActionMapper.h"
 22#include "InputController.h"
 23#include "LoadSaveState.h"
 24#include "LogController.h"
 25struct mArguments;
 26
 27namespace QGBA {
 28
 29class AudioProcessor;
 30class ConfigController;
 31class CoreController;
 32class CoreManager;
 33class DebuggerConsoleController;
 34class Display;
 35class FrameView;
 36class GDBController;
 37class GIFView;
 38class LibraryController;
 39class LogView;
 40class OverrideView;
 41class SensorView;
 42class ShaderSelector;
 43class ShortcutController;
 44class VideoView;
 45class WindowBackground;
 46
 47class Window : public QMainWindow {
 48Q_OBJECT
 49
 50public:
 51	Window(CoreManager* manager, ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
 52	virtual ~Window();
 53
 54	std::shared_ptr<CoreController> controller() { return m_controller; }
 55
 56	void setConfig(ConfigController*);
 57	void argumentsPassed(mArguments*);
 58
 59	void resizeFrame(const QSize& size);
 60
 61	void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
 62
 63signals:
 64	void startDrawing();
 65	void shutdown();
 66	void paused(bool);
 67
 68public slots:
 69	void setController(CoreController* controller, const QString& fname);
 70	void selectROM();
 71#ifdef USE_SQLITE3
 72	void selectROMInArchive();
 73	void addDirToLibrary();
 74#endif
 75	void selectSave(bool temporary);
 76	void selectState(bool load);
 77	void selectPatch();
 78	void scanCard();
 79	void enterFullScreen();
 80	void exitFullScreen();
 81	void toggleFullScreen();
 82	void loadConfig();
 83	void reloadConfig();
 84	void saveConfig();
 85
 86	void loadCamImage();
 87
 88	void replaceROM();
 89
 90	void multiplayerChanged();
 91
 92	void importSharkport();
 93	void exportSharkport();
 94
 95	void openSettingsWindow();
 96
 97	void startVideoLog();
 98
 99#ifdef USE_DEBUGGERS
100	void consoleOpen();
101#endif
102
103#ifdef USE_FFMPEG
104	void openVideoWindow();
105	void openGIFWindow();
106#endif
107
108#ifdef USE_GDB_STUB
109	void gdbOpen();
110#endif
111
112protected:
113	virtual void keyPressEvent(QKeyEvent* event) override;
114	virtual void keyReleaseEvent(QKeyEvent* event) override;
115	virtual void resizeEvent(QResizeEvent*) override;
116	virtual void showEvent(QShowEvent*) override;
117	virtual void hideEvent(QHideEvent*) override;
118	virtual void closeEvent(QCloseEvent*) override;
119	virtual void focusInEvent(QFocusEvent*) override;
120	virtual void focusOutEvent(QFocusEvent*) override;
121	virtual void dragEnterEvent(QDragEnterEvent*) override;
122	virtual void dropEvent(QDropEvent*) override;
123	virtual void mouseDoubleClickEvent(QMouseEvent*) override;
124
125private slots:
126	void gameStarted();
127	void gameStopped();
128	void gameCrashed(const QString&);
129	void gameFailed();
130	void unimplementedBiosCall(int);
131
132	void reloadAudioDriver();
133	void reloadDisplayDriver();
134	void attachDisplay();
135	void changeRenderer();
136
137	void tryMakePortable();
138	void mustRestart();
139
140	void recordFrame();
141	void showFPS();
142	void focusCheck();
143
144	void updateFrame();
145
146	void setLogo();
147
148private:
149	static const int FPS_TIMER_INTERVAL = 2000;
150	static const int MUST_RESTART_TIMEOUT = 10000;
151
152	void setupMenu(QMenuBar*);
153	void openStateWindow(LoadSave);
154
155	void attachWidget(QWidget* widget);
156	void detachWidget(QWidget* widget);
157
158	void appendMRU(const QString& fname);
159	void clearMRU();
160	void updateMRU();
161
162	void openView(QWidget* widget);
163
164	template <typename T, typename... A> std::function<void()> openTView(A... arg);
165	template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
166
167	Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
168	template<typename T, typename V> Action* addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
169	template<typename V> Action* addGameAction(const QString& visibleName, const QString& name, V (CoreController::*action)(), const QString& menu = {}, const QKeySequence& = {});
170	Action* addGameAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
171
172	void updateTitle(float fps = -1);
173
174	QString getFilters() const;
175	QString getFiltersArchive() const;
176
177	CoreManager* m_manager;
178	std::shared_ptr<CoreController> m_controller;
179	std::unique_ptr<AudioProcessor> m_audioProcessor;
180
181	std::unique_ptr<Display> m_display;
182	int m_savedScale;
183
184	// TODO: Move these to a new class
185	ActionMapper m_actions;
186	QList<Action*> m_gameActions;
187	QList<Action*> m_nonMpActions;
188#ifdef M_CORE_GBA
189	QMultiMap<mPlatform, Action*> m_platformActions;
190#endif
191	Action* m_multiWindow;
192	QMap<int, Action*> m_frameSizes;
193
194	LogController m_log{0};
195	LogView* m_logView;
196#ifdef USE_DEBUGGERS
197	DebuggerConsoleController* m_console = nullptr;
198#endif
199	LoadSaveState* m_stateWindow = nullptr;
200	WindowBackground* m_screenWidget;
201	QPixmap m_logo{":/res/mgba-1024.png"};
202	ConfigController* m_config;
203	InputController m_inputController;
204	QList<qint64> m_frameList;
205	QElapsedTimer m_frameTimer;
206	QTimer m_fpsTimer;
207	QTimer m_mustRestart;
208	QList<QString> m_mruFiles;
209	ShortcutController* m_shortcutController;
210#if defined(BUILD_GL) || defined(BUILD_GLES2)
211	std::unique_ptr<ShaderSelector> m_shaderView;
212#endif
213	bool m_fullscreenOnStart = false;
214	QTimer m_focusCheck;
215	bool m_autoresume = false;
216	bool m_wasOpened = false;
217	QString m_pendingPatch;
218	QString m_pendingState;
219	bool m_pendingPause = false;
220	bool m_pendingClose = false;
221
222	bool m_hitUnimplementedBiosCall;
223
224	std::unique_ptr<OverrideView> m_overrideView;
225	std::unique_ptr<SensorView> m_sensorView;
226	FrameView* m_frameView = nullptr;
227
228#ifdef USE_FFMPEG
229	VideoView* m_videoView = nullptr;
230	GIFView* m_gifView = nullptr;
231#endif
232
233#ifdef USE_GDB_STUB
234	GDBController* m_gdbController = nullptr;
235#endif
236
237#ifdef USE_SQLITE3
238	LibraryController* m_libraryView;
239#endif
240};
241
242class WindowBackground : public QWidget {
243Q_OBJECT
244
245public:
246	WindowBackground(QWidget* parent = 0);
247
248	void setPixmap(const QPixmap& pixmap);
249	void setSizeHint(const QSize& size);
250	virtual QSize sizeHint() const override;
251	void setDimensions(int width, int height);
252	void setLockIntegerScaling(bool lock);
253	void setLockAspectRatio(bool lock);
254	void filter(bool filter);
255
256	const QPixmap& pixmap() const { return m_pixmap; }
257
258protected:
259	virtual void paintEvent(QPaintEvent*) override;
260
261private:
262	QPixmap m_pixmap;
263	QSize m_sizeHint;
264	int m_aspectWidth;
265	int m_aspectHeight;
266	bool m_lockAspectRatio;
267	bool m_lockIntegerScaling;
268	bool m_filter;
269};
270
271}