all repos — mgba @ b6db8581dfc625e527b2c7041193e996497a5ff7

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