all repos — mgba @ cea5864f817fe92ab2d1df85e5dd318aef788196

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 ShortcutController;
 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 keyPressEvent(QKeyEvent* event) override;
110	virtual void keyReleaseEvent(QKeyEvent* event) override;
111	virtual void resizeEvent(QResizeEvent*) override;
112	virtual void showEvent(QShowEvent*) override;
113	virtual void closeEvent(QCloseEvent*) override;
114	virtual void focusInEvent(QFocusEvent*) override;
115	virtual void focusOutEvent(QFocusEvent*) override;
116	virtual void dragEnterEvent(QDragEnterEvent*) override;
117	virtual void dropEvent(QDropEvent*) override;
118	virtual void mouseDoubleClickEvent(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 showFPS();
135	void focusCheck();
136
137private:
138	static const int FPS_TIMER_INTERVAL = 2000;
139	static const int FRAME_LIST_SIZE = 120;
140
141	void setupMenu(QMenuBar*);
142	void openStateWindow(LoadSave);
143
144	void attachWidget(QWidget* widget);
145	void detachWidget(QWidget* widget);
146
147	void appendMRU(const QString& fname);
148	void updateMRU();
149
150	void openView(QWidget* widget);
151
152	template <typename T, typename... A> std::function<void()> openTView(A... arg);
153	template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
154
155	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
156	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
157
158	void updateTitle(float fps = -1);
159
160	QString getFilters() const;
161	QString getFiltersArchive() const;
162
163	CoreManager* m_manager;
164	std::shared_ptr<CoreController> m_controller;
165	std::unique_ptr<AudioProcessor> m_audioProcessor;
166
167	std::unique_ptr<Display> m_display;
168	int m_savedScale;
169	// TODO: Move these to a new class
170	QList<QAction*> m_gameActions;
171	QList<QAction*> m_nonMpActions;
172#ifdef M_CORE_GBA
173	QList<QAction*> m_gbaActions;
174#endif
175	QAction* m_multiWindow;
176	QMap<int, QAction*> m_frameSizes;
177	LogController m_log{0};
178	LogView* m_logView;
179#ifdef USE_DEBUGGERS
180	DebuggerConsoleController* m_console = nullptr;
181#endif
182	LoadSaveState* m_stateWindow = nullptr;
183	WindowBackground* m_screenWidget;
184	QPixmap m_logo{":/res/mgba-1024.png"};
185	ConfigController* m_config;
186	InputController m_inputController;
187	QList<QDateTime> m_frameList;
188	QTimer m_fpsTimer;
189	QList<QString> m_mruFiles;
190	QMenu* m_mruMenu = nullptr;
191	QMenu* m_videoLayers;
192	QMenu* m_audioChannels;
193	ShortcutController* m_shortcutController;
194	std::unique_ptr<ShaderSelector> m_shaderView;
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 QLabel {
224Q_OBJECT
225
226public:
227	WindowBackground(QWidget* parent = 0);
228
229	void setSizeHint(const QSize& size);
230	virtual QSize sizeHint() const override;
231	void setDimensions(int width, int height);
232	void setLockIntegerScaling(bool lock);
233	void setLockAspectRatio(bool lock);
234
235protected:
236	virtual void paintEvent(QPaintEvent*) override;
237
238private:
239	QSize m_sizeHint;
240	int m_aspectWidth;
241	int m_aspectHeight;
242	bool m_lockAspectRatio;
243	bool m_lockIntegerScaling;
244};
245
246}