all repos — mgba @ d33f1d13926f4aa2afebad31775222cdd278411c

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