all repos — mgba @ ba566f334d4b7d34d7572a9fde8d7510d07ff162

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 changeRenderer();
135
136	void tryMakePortable();
137	void mustRestart();
138
139	void recordFrame();
140	void showFPS();
141	void focusCheck();
142
143	void updateFrame();
144
145private:
146	static const int FPS_TIMER_INTERVAL = 2000;
147	static const int MUST_RESTART_TIMEOUT = 10000;
148
149	void setupMenu(QMenuBar*);
150	void openStateWindow(LoadSave);
151
152	void attachWidget(QWidget* widget);
153	void detachWidget(QWidget* widget);
154
155	void appendMRU(const QString& fname);
156	void clearMRU();
157	void updateMRU();
158
159	void openView(QWidget* widget);
160	void attachDisplay();
161
162	template <typename T, typename... A> std::function<void()> openTView(A... arg);
163	template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
164
165	Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
166	template<typename T, typename V> Action* addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
167	template<typename V> Action* addGameAction(const QString& visibleName, const QString& name, V (CoreController::*action)(), const QString& menu = {}, const QKeySequence& = {});
168	Action* addGameAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
169
170	void updateTitle(float fps = -1);
171
172	QString getFilters() const;
173	QString getFiltersArchive() const;
174
175	CoreManager* m_manager;
176	std::shared_ptr<CoreController> m_controller;
177	std::unique_ptr<AudioProcessor> m_audioProcessor;
178
179	std::unique_ptr<Display> m_display;
180	int m_savedScale;
181
182	// TODO: Move these to a new class
183	ActionMapper m_actions;
184	QList<Action*> m_gameActions;
185	QList<Action*> m_nonMpActions;
186#ifdef M_CORE_GBA
187	QMultiMap<mPlatform, Action*> m_platformActions;
188#endif
189	Action* m_multiWindow;
190	QMap<int, Action*> m_frameSizes;
191
192	LogController m_log{0};
193	LogView* m_logView;
194#ifdef USE_DEBUGGERS
195	DebuggerConsoleController* m_console = nullptr;
196#endif
197	LoadSaveState* m_stateWindow = nullptr;
198	WindowBackground* m_screenWidget;
199	QPixmap m_logo{":/res/mgba-1024.png"};
200	ConfigController* m_config;
201	InputController m_inputController;
202	QList<qint64> m_frameList;
203	QElapsedTimer m_frameTimer;
204	QTimer m_fpsTimer;
205	QTimer m_mustRestart;
206	QList<QString> m_mruFiles;
207	ShortcutController* m_shortcutController;
208#if defined(BUILD_GL) || defined(BUILD_GLES2)
209	std::unique_ptr<ShaderSelector> m_shaderView;
210#endif
211	bool m_fullscreenOnStart = false;
212	QTimer m_focusCheck;
213	bool m_autoresume = false;
214	bool m_wasOpened = false;
215	QString m_pendingPatch;
216	QString m_pendingState;
217	bool m_pendingPause = false;
218	bool m_pendingClose = false;
219
220	bool m_hitUnimplementedBiosCall;
221
222	std::unique_ptr<OverrideView> m_overrideView;
223	std::unique_ptr<SensorView> m_sensorView;
224	FrameView* m_frameView = nullptr;
225
226#ifdef USE_FFMPEG
227	VideoView* m_videoView = nullptr;
228	GIFView* m_gifView = nullptr;
229#endif
230
231#ifdef USE_GDB_STUB
232	GDBController* m_gdbController = nullptr;
233#endif
234
235#ifdef USE_SQLITE3
236	LibraryController* m_libraryView;
237#endif
238};
239
240class WindowBackground : public QWidget {
241Q_OBJECT
242
243public:
244	WindowBackground(QWidget* parent = 0);
245
246	void setPixmap(const QPixmap& pixmap);
247	void setSizeHint(const QSize& size);
248	virtual QSize sizeHint() const override;
249	void setDimensions(int width, int height);
250	void setLockIntegerScaling(bool lock);
251	void setLockAspectRatio(bool lock);
252	void filter(bool filter);
253
254	const QPixmap& pixmap() const { return m_pixmap; }
255
256protected:
257	virtual void paintEvent(QPaintEvent*) override;
258
259private:
260	QPixmap m_pixmap;
261	QSize m_sizeHint;
262	int m_aspectWidth;
263	int m_aspectHeight;
264	bool m_lockAspectRatio;
265	bool m_lockIntegerScaling;
266	bool m_filter;
267};
268
269}