all repos — mgba @ 7f41dd354176b720c8e3310553c6b772278b9dca

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