all repos — mgba @ 5e82d97b5b41609b29c67aa1aa0da5b3849fdb4a

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