all repos — mgba @ 8e46e0ea79d601ed57eab0ee365bc8a9525ed7fb

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
137	void updateFrame();
138
139private:
140	static const int FPS_TIMER_INTERVAL = 2000;
141	static const int FRAME_LIST_SIZE = 120;
142
143	void setupMenu(QMenuBar*);
144	void openStateWindow(LoadSave);
145
146	void attachWidget(QWidget* widget);
147	void detachWidget(QWidget* widget);
148
149	void appendMRU(const QString& fname);
150	void updateMRU();
151
152	void openView(QWidget* widget);
153
154	template <typename T, typename... A> std::function<void()> openTView(A... arg);
155	template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
156
157	QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
158	QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
159
160	void updateTitle(float fps = -1);
161
162	QString getFilters() const;
163	QString getFiltersArchive() const;
164
165	CoreManager* m_manager;
166	std::shared_ptr<CoreController> m_controller;
167	std::unique_ptr<AudioProcessor> m_audioProcessor;
168
169	std::unique_ptr<Display> m_display;
170	int m_savedScale;
171	// TODO: Move these to a new class
172	QList<QAction*> m_gameActions;
173	QList<QAction*> m_nonMpActions;
174#ifdef M_CORE_GBA
175	QList<QAction*> m_gbaActions;
176#endif
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/mgba-1024.png"};
187	ConfigController* m_config;
188	InputController m_inputController;
189	QList<QDateTime> m_frameList;
190	QTimer m_fpsTimer;
191	QList<QString> m_mruFiles;
192	QMenu* m_mruMenu = nullptr;
193	QMenu* m_videoLayers;
194	QMenu* m_audioChannels;
195	ShortcutController* m_shortcutController;
196#if defined(BUILD_GL) || defined(BUILD_GLES2)
197	std::unique_ptr<ShaderSelector> m_shaderView;
198#endif
199	bool m_fullscreenOnStart = false;
200	QTimer m_focusCheck;
201	bool m_autoresume = false;
202	bool m_wasOpened = false;
203	QString m_pendingPatch;
204
205	bool m_hitUnimplementedBiosCall;
206
207	std::unique_ptr<OverrideView> m_overrideView;
208	std::unique_ptr<SensorView> m_sensorView;
209
210#ifdef USE_FFMPEG
211	VideoView* m_videoView = nullptr;
212#endif
213
214#ifdef USE_MAGICK
215	GIFView* m_gifView = nullptr;
216#endif
217
218#ifdef USE_GDB_STUB
219	GDBController* m_gdbController = nullptr;
220#endif
221
222#ifdef USE_SQLITE3
223	LibraryController* m_libraryView;
224#endif
225};
226
227class WindowBackground : public QWidget {
228Q_OBJECT
229
230public:
231	WindowBackground(QWidget* parent = 0);
232
233	void setPixmap(const QPixmap& pixmap);
234	void setSizeHint(const QSize& size);
235	virtual QSize sizeHint() const override;
236	void setDimensions(int width, int height);
237	void setLockIntegerScaling(bool lock);
238	void setLockAspectRatio(bool lock);
239
240	const QPixmap& pixmap() const { return m_pixmap; }
241
242protected:
243	virtual void paintEvent(QPaintEvent*) override;
244
245private:
246	QPixmap m_pixmap;
247	QSize m_sizeHint;
248	int m_aspectWidth;
249	int m_aspectHeight;
250	bool m_lockAspectRatio;
251	bool m_lockIntegerScaling;
252};
253
254}